mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-04-05 11:38:27 +08:00
chrome: 删除无用脚本和注释,优化ci自动化
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 登录阿里云hub
|
||||
docker login --username=mmdapl registry.cn-hangzhou.aliyuncs.com
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/bin/bash
|
||||
## 功能:本地前后端项目构建、打包镜像,上传docker仓库
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 使用示例:bash xxx.sh 版本号 faster[可选]
|
||||
## - bash build_image.sh 0.0.1 faster
|
||||
## 作者:储凡
|
||||
##
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
## 项目名称
|
||||
readonly projectName="408CSFamily"
|
||||
## 仓库地址
|
||||
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
|
||||
## 版本号
|
||||
version=${1}
|
||||
## 是否先本地构建,执行npm run build操作
|
||||
isFaster=${2}
|
||||
## 镜像名称
|
||||
imageTagName=${repoAddress}:${projectName}-${version}
|
||||
|
||||
|
||||
## 参数预检查
|
||||
prepare_check(){
|
||||
if test -z "${version}";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空。参考版本: 0.0.x"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 运行命令
|
||||
run(){
|
||||
echo -e "${successLogger}---------------- shell ${projectName} start ---------------- "
|
||||
|
||||
if [ "${isFaster}" == "faster" ];then
|
||||
## 本地构建、快速制作镜像
|
||||
pnpm build && docker build \
|
||||
--build-arg APP_VERSION="${version}" \
|
||||
--build-arg CONTAINER_BUILD=false \
|
||||
-t "${imageTagName}" .
|
||||
else
|
||||
## ci流程,容器构建打包
|
||||
docker build \
|
||||
--build-arg APP_VERSION="${version}" \
|
||||
--build-arg CONTAINER_BUILD=true \
|
||||
-t "${imageTagName}" .
|
||||
fi
|
||||
|
||||
echo -e "${successLogger}---------------- shell ${projectName} end ---------------- "
|
||||
push_docker_image
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
## 推送镜像
|
||||
push_docker_image(){
|
||||
if [[ "$(docker images -q "${imageTagName}" 2> /dev/null)" != "" ]];
|
||||
then
|
||||
## 推送
|
||||
docker push "${imageTagName}"
|
||||
echo -e "${successLogger}---------------- 上传镜像成功,删除本地镜像 ---------------- "
|
||||
docker rmi "${imageTagName}"
|
||||
else
|
||||
echo -e "${errorLogger}${currentTime}:[镜像] ${imageTagName}不存在"
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
prepare_check
|
||||
run
|
||||
|
||||
|
||||
@@ -23,19 +23,21 @@ const imageName=`${repoAddress}:${projectName}-${packageVersion}`
|
||||
|
||||
/**
|
||||
* 获取构建镜像的脚本
|
||||
* - faster: "faster"
|
||||
* @param containerBuild
|
||||
* @param needProxy
|
||||
*/
|
||||
function getBuildImageScript(faster){
|
||||
// 是否容器构建
|
||||
const isContainerBuild=faster==="faster"
|
||||
|
||||
function getBuildImageScript({containerBuild,needProxy=false}){
|
||||
// 基础构建脚本
|
||||
const baseBuildScript=containerBuild?"":(
|
||||
needProxy?"./scripts/bundle build_proxy":"./scripts/bundle build"
|
||||
)
|
||||
return [
|
||||
// 构建镜像
|
||||
`
|
||||
${isContainerBuild? `./scripts/bundle build && `:""}
|
||||
${baseBuildScript}
|
||||
docker build \
|
||||
--build-arg APP_VERSION=${packageVersion} \
|
||||
--build-arg CONTAINER_BUILD=${!isContainerBuild} \
|
||||
--build-arg CONTAINER_BUILD=${containerBuild} \
|
||||
-t ${imageName} .
|
||||
`,
|
||||
// 推送镜像
|
||||
@@ -61,8 +63,19 @@ function getBuildImageScript(faster){
|
||||
const SupportScripts={
|
||||
build:'vuepress build docs',
|
||||
build_proxy:'PROXY_DOMAIN=true vuepress build docs',
|
||||
image:getBuildImageScript(),
|
||||
image_faster:getBuildImageScript("faster")
|
||||
image:getBuildImageScript({
|
||||
containerBuild:true,
|
||||
needProxy:false
|
||||
}),
|
||||
image_proxy:getBuildImageScript({
|
||||
containerBuild:true,
|
||||
needProxy:true
|
||||
}),
|
||||
// 直接从本地拿dist文件,生成镜像
|
||||
image_faster:getBuildImageScript({
|
||||
containerBuild:false,
|
||||
needProxy:false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +105,11 @@ async function getScriptCommand(){
|
||||
name: SupportScripts.image,
|
||||
value: '#0000ff'
|
||||
},
|
||||
{
|
||||
message: 'build to docker image with proxy',
|
||||
name: SupportScripts.image_proxy,
|
||||
value: '#0000ff'
|
||||
},
|
||||
{
|
||||
message: 'build to docker image faster',
|
||||
name: SupportScripts.image_faster,
|
||||
@@ -111,9 +129,6 @@ async function getScriptCommand(){
|
||||
|
||||
;(async ()=>{
|
||||
const scriptCommand= await getScriptCommand()
|
||||
console.log(`>>>> ${scriptCommand} `)
|
||||
|
||||
// 执行
|
||||
// await execShell(scriptCommand)
|
||||
await execShell(scriptCommand)
|
||||
})()
|
||||
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
#!/bin/bash
|
||||
## 功能:清除容器,删除旧镜像,创建新的容器
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:储凡
|
||||
## 使用示例:bash deploy.sh 部署平台 版本号
|
||||
## - bash deploy.sh ali 0.0.1
|
||||
##
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
|
||||
readonly containerName="408CSFamily"
|
||||
readonly networkName="service_env_net"
|
||||
## 定义参数
|
||||
operationName=${1}
|
||||
version=${2}
|
||||
## 镜像名称
|
||||
imageName="${repoAddress}:${containerName}-${version}"
|
||||
|
||||
|
||||
## 参数预检查
|
||||
prepare_check(){
|
||||
if test -z "${operationName}"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 部署平台不能为空."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -z "${version}"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
## 判断容器存在即删除
|
||||
## - 一个参数,容器名称
|
||||
delete_container(){
|
||||
docker inspect "${1}" -f '{{.Name}}' > /dev/null
|
||||
if [ $? -eq 0 ] ;then
|
||||
echo -e "${warnLogger}${currentTime}容器:${1} 存在,现进行删除"
|
||||
docker rm -f "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
## 判断镜像存在,即删除
|
||||
## - 一个参数,镜像地址
|
||||
delete_image(){
|
||||
## 判断版本号
|
||||
if test -z "${version}";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 镜像版本号不能为空."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$(docker images -q "${1}" 2> /dev/null)" != "" ]];
|
||||
then
|
||||
echo -e "${warnLogger}${currentTime}镜像:${1}存在,现进行删除"
|
||||
docker rmi "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 环境初始成功
|
||||
run(){
|
||||
if [ "${operationName}" == "gitee" ];then
|
||||
## 查看所有
|
||||
deploy_to_gitee
|
||||
exit 0;
|
||||
elif [ "${operationName}" == "github" ]; then
|
||||
deploy_to_github
|
||||
exit 0;
|
||||
elif [ "${operationName}" == "ali" ]; then
|
||||
## 删除容器
|
||||
delete_container "${containerName}"
|
||||
## 删除镜像
|
||||
delete_image "${imageName}"
|
||||
## 部署
|
||||
deploy_to_ali
|
||||
exit 0;
|
||||
else
|
||||
echo -e "${errorLogger}${currentTime}当前操作不支持,目前只支持:ali/gitee/github"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 部署到阿里服务器
|
||||
deploy_to_ali(){
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} ali start ---------------- "
|
||||
|
||||
docker run -d --name "${containerName}" \
|
||||
-p 7000:80 \
|
||||
--network="${networkName}" \
|
||||
--restart=unless-stopped \
|
||||
--ip=172.30.0.100 \
|
||||
"${imageName}"
|
||||
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} ali end ------------------ "
|
||||
docker ps
|
||||
}
|
||||
|
||||
## 部署到github静态资源托管
|
||||
deploy_to_github(){
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} github start ---------------- "
|
||||
|
||||
set -e
|
||||
npm run build-proxy && cd docs/.vuepress/dist
|
||||
git init && git add -A
|
||||
|
||||
## 配置信息
|
||||
git config user.name 'chu fan'
|
||||
git config user.email 'fairy_408@2925.com'
|
||||
git config --list
|
||||
|
||||
git commit -m "release v${version}"
|
||||
|
||||
|
||||
# git push -f https://github.com/mmdapl/408CSFamily.git main
|
||||
## 部署到github pages
|
||||
git push -f https://github.com/mmdapl/408CSFamily.git main:pages/github
|
||||
cd -
|
||||
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} github end ------------------ "
|
||||
}
|
||||
|
||||
|
||||
## 部署到gitee静态资源托管
|
||||
deploy_to_gitee(){
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
prepare_check
|
||||
|
||||
run
|
||||
|
||||
|
||||
10
scripts/dev
Executable file
10
scripts/dev
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
*
|
||||
* 本地启动
|
||||
* 例如:
|
||||
* - ./scripts/dev
|
||||
*/
|
||||
|
||||
const { execShell } = require("./.exec");
|
||||
(async ()=>await execShell('vuepress dev docs'))()
|
||||
125
scripts/docker
125
scripts/docker
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
*
|
||||
* docker cli工具
|
||||
* 例如:
|
||||
* - ./scripts/network create
|
||||
* - ./scripts/network inspect
|
||||
* - ./scripts/network rm
|
||||
* - ./scripts/network ls
|
||||
* - ./scripts/docker container xxx 容器相关
|
||||
* - ./scripts/network image xxx 镜像相关
|
||||
* - ./scripts/docker network xxx 网络相关
|
||||
*/
|
||||
const { execShell, BaseSetting} = require("./.exec");
|
||||
const scriptName=process.argv[2];
|
||||
@@ -24,41 +23,26 @@ const dockerNetworkInfo={
|
||||
gateway:'172.30.0.1',
|
||||
}
|
||||
|
||||
/**
|
||||
* docker containers 容器相关指令
|
||||
*/
|
||||
const SupportScriptsInContainer={
|
||||
run:'',
|
||||
rm:'',
|
||||
ps:'docker ps'
|
||||
}
|
||||
|
||||
function getContainerCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
if(scriptName==='rm')
|
||||
return SupportScriptsInContainer.rm
|
||||
if(scriptName==='run')
|
||||
return SupportScriptsInContainer.run
|
||||
if(scriptName==='ps')
|
||||
return SupportScriptsInContainer.ps
|
||||
return SupportScriptsInContainer.run
|
||||
}
|
||||
|
||||
|
||||
|
||||
const SupportScriptsInImage={
|
||||
rm:'docker rmi **',
|
||||
ps:'docker images'
|
||||
}
|
||||
|
||||
function getContainerCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
if(scriptName==='rm')
|
||||
return SupportScriptsInContainer.rm
|
||||
if(scriptName==='run')
|
||||
return SupportScriptsInContainer.run
|
||||
if(scriptName==='ps')
|
||||
return SupportScriptsInContainer.ps
|
||||
return SupportScriptsInContainer.run
|
||||
/**
|
||||
* docker images 相关脚本指令
|
||||
*/
|
||||
const SupportScriptsInImage = {
|
||||
rm: 'docker rmi **',
|
||||
ps: 'docker images'
|
||||
}
|
||||
|
||||
/**
|
||||
* docker network 相关脚本指令
|
||||
*/
|
||||
const SupportScriptsInNetWork={
|
||||
ls:'docker network ls',
|
||||
create:[
|
||||
@@ -96,28 +80,46 @@ const SupportScriptsInNetWork={
|
||||
`
|
||||
],
|
||||
inspect:
|
||||
`
|
||||
`
|
||||
docker network inspect ${dockerNetworkInfo.defaultName}
|
||||
`
|
||||
}
|
||||
|
||||
function getNetworkCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
|
||||
if(SupportScriptsInNetWork.hasOwnProperty(scriptName)){
|
||||
|
||||
function getContainerCommand(){
|
||||
const name=process.argv[3];
|
||||
|
||||
if(SupportScriptsInContainer.hasOwnProperty(name)){
|
||||
return SupportScriptsInContainer[name]
|
||||
}
|
||||
// 默认查看所有容器
|
||||
return SupportScriptsInContainer.ps
|
||||
}
|
||||
|
||||
function getImageCommand(){
|
||||
const name=process.argv[3];
|
||||
|
||||
if(SupportScriptsInImage.hasOwnProperty(name)){
|
||||
return SupportScriptsInImage[name]
|
||||
}
|
||||
return SupportScriptsInImage.ps
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getNetworkCommand(){
|
||||
const name=process.argv[3];
|
||||
if(SupportScriptsInNetWork.hasOwnProperty(name)){
|
||||
return SupportScriptsInNetWork[scriptName]
|
||||
}
|
||||
if(scriptName==='ls')
|
||||
return SupportScriptsInNetWork.ls
|
||||
if(scriptName==='run')
|
||||
return SupportScriptsInNetWork.create
|
||||
if(scriptName==='ps')
|
||||
return SupportScriptsInNetWork.rm
|
||||
if(scriptName==='inspect')
|
||||
return SupportScriptsInNetWork.inspect
|
||||
return SupportScriptsInNetWork.ls
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 支持的命令
|
||||
const SupportScripts={
|
||||
ls:'docker network ls',
|
||||
@@ -161,38 +163,17 @@ const SupportScripts={
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要执行的shell命令
|
||||
* @param scriptName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getCommand(scriptName){
|
||||
let deployCommand=SupportScripts.ls
|
||||
|
||||
switch (scriptName) {
|
||||
case 'container':
|
||||
return getContainerCommand();
|
||||
function getCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
switch (scriptName){
|
||||
case 'network':
|
||||
break;
|
||||
return getNetworkCommand()
|
||||
case 'container':
|
||||
return getContainerCommand()
|
||||
case 'image':
|
||||
break;
|
||||
return getImageCommand()
|
||||
}
|
||||
|
||||
if(scriptName==='ls'){
|
||||
deployCommand=SupportScripts.ls
|
||||
}
|
||||
|
||||
// 部署到Github
|
||||
if(scriptName==='rm'){
|
||||
deployCommand=SupportScripts.rm
|
||||
}
|
||||
if(scriptName==='create'){
|
||||
deployCommand=SupportScripts.create
|
||||
}
|
||||
if(scriptName==='inspect'){
|
||||
deployCommand=SupportScripts.inspect
|
||||
}
|
||||
return deployCommand
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 功能:设置docker自定义network,并指定网关、IP范围
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:储凡
|
||||
## 使用示例:bash xxx.sh 容器名称 镜像地址
|
||||
##
|
||||
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
operationName=${1}
|
||||
networkName=${2}
|
||||
|
||||
## 网络名称
|
||||
readonly defaultNetworkName="service_env_net"
|
||||
## 子网范围 [/24 子网掩码]
|
||||
readonly subnet="172.30.0.0/24"
|
||||
## 网关
|
||||
readonly gateway="172.30.0.1"
|
||||
|
||||
|
||||
prepare_check(){
|
||||
if test -z "$operationName"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 操作类型不能为空。脚本执行eg: bash xxx.sh [ls/init/rm]"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
run(){
|
||||
if [ "$operationName" == "ls" ];then
|
||||
## 查看所有
|
||||
echo -e "${successLogger}---------------- shell ls start ---------------- "
|
||||
docker network ls
|
||||
echo -e "${successLogger}---------------- shell ls end ------------------ "
|
||||
exit 0;
|
||||
elif [ "$operationName" == "init" ]; then
|
||||
echo -e "${successLogger}---------------- shell init start ---------------- "
|
||||
## 初始化
|
||||
init_network
|
||||
echo -e "${successLogger}---------------- shell init start ---------------- "
|
||||
exit 0;
|
||||
elif [ "$operationName" == "rm" ]; then
|
||||
## 移除
|
||||
echo -e "${successLogger}---------------- shell rm start ---------------- "
|
||||
remove_network
|
||||
echo -e "${successLogger}---------------- shell rm start ---------------- "
|
||||
exit 0;
|
||||
else
|
||||
echo -e "${errorLogger}当前操作不支持,目前只支持:ls/init/rm"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
## 创建网络
|
||||
init_network(){
|
||||
## 查询network -w【全匹配】
|
||||
docker network ls | grep -w "${defaultNetworkName}"
|
||||
if [ $? -eq 0 ] ;then
|
||||
echo -e "${warnLogger}---------------- 容器:${defaultNetworkName} 已存在,无需创建 ---------------- "
|
||||
docker network ls
|
||||
exit ;
|
||||
else
|
||||
echo -e "${successLogger}---------------- 网络${defaultNetworkName},现进行初始化 ---------------- "
|
||||
docker network ls
|
||||
docker network create \
|
||||
--subnet="${subnet}" \
|
||||
--gateway="${gateway}" \
|
||||
"${defaultNetworkName}"
|
||||
echo -e "${successLogger}---------------- 创建后 ---------------------"
|
||||
docker network ls
|
||||
echo -e "${successLogger}---------------- 网络信息 ---------------------"
|
||||
docker netwrok inspect "${defaultNetworkName}"
|
||||
fi
|
||||
}
|
||||
|
||||
## 删除网络
|
||||
remove_network(){
|
||||
if test -z "$networkName";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
|
||||
exit 0
|
||||
fi
|
||||
## 判断是否存在 -w【全匹配】
|
||||
docker network ls | grep -w "${networkName}"
|
||||
if [ $? -eq 1 ] ;then
|
||||
echo -e "${errorLogger}${currentTime}:容器网络:${networkName} 不存在,删除无效 "
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo -e "${successLogger}----------------删除前---------------------"
|
||||
docker network ls
|
||||
docker network rm "${networkName}"
|
||||
echo -e "${successLogger}----------------删除后---------------------"
|
||||
docker network ls
|
||||
}
|
||||
|
||||
|
||||
prepare_check
|
||||
|
||||
run
|
||||
Reference in New Issue
Block a user