mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-04-13 17:09:45 +08:00
release v0.0.1-alpha.0
This commit is contained in:
@@ -19,7 +19,6 @@ RUN if [ "$CONTAINER_BUILD" = "true" ]; then \
|
||||
npm i pnpm@7 -g && pnpm i -D && pnpm build; \
|
||||
fi;
|
||||
|
||||
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:1.23.0-alpine
|
||||
|
||||
ARG APP_VERSION
|
||||
|
||||
@@ -5,16 +5,6 @@ process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}`
|
||||
const {exec,exit} = require('shelljs');
|
||||
|
||||
|
||||
async function printWithInterval() {
|
||||
for (let count = 1; ; count++) {
|
||||
if(count<5){
|
||||
console.log('执行中'+'.'.repeat(count));
|
||||
}else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -63,9 +53,26 @@ exports.execShell = async commands => {
|
||||
}
|
||||
|
||||
for (const command of runCommands) {
|
||||
console.log(`=== command: >>> ${command} <<< start === `)
|
||||
console.log(`>>>command:\n ${command} \n<<<start === \n`)
|
||||
// await syncExec(command)
|
||||
const {code}=await exec(command)
|
||||
// 指令异常,不执行后续指令
|
||||
if(code!==0){
|
||||
break;
|
||||
}
|
||||
|
||||
await syncExec(command)
|
||||
console.log(`=== command: >>> ${command} <<< ending === `)
|
||||
console.log(`<<<ending === `)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 脚本基础设置
|
||||
* @type {{currentTime: string, errorLogger: string, successLogger: string, warnLogger: string}}
|
||||
*/
|
||||
exports.BaseSetting={
|
||||
successLogger:"\033[36m",
|
||||
errorLogger:"\033[1;31m",
|
||||
warnLogger:"\033[1;33m",
|
||||
// 定义时间
|
||||
currentTime:'$(date "+%Y-%m-%d %H:%M:%S")'
|
||||
}
|
||||
|
||||
@@ -14,6 +14,44 @@
|
||||
const { execShell } = require("./.exec");
|
||||
const { Select } = require('enquirer');
|
||||
|
||||
const packageVersion=require('../package.json').version
|
||||
const projectName="408CSFamily"
|
||||
// 仓库地址
|
||||
const repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
|
||||
// 镜像地址
|
||||
const imageName=`${repoAddress}:${projectName}-${packageVersion}`
|
||||
|
||||
/**
|
||||
* 获取构建镜像的脚本
|
||||
* - faster: "faster"
|
||||
*/
|
||||
function getBuildImageScript(faster){
|
||||
// 是否容器构建
|
||||
const isContainerBuild=faster==="faster"
|
||||
|
||||
return [
|
||||
// 构建镜像
|
||||
`
|
||||
${isContainerBuild? `./scripts/bundle build && `:""}
|
||||
docker build \
|
||||
--build-arg APP_VERSION=${packageVersion} \
|
||||
--build-arg CONTAINER_BUILD=${!isContainerBuild} \
|
||||
-t ${imageName} .
|
||||
`,
|
||||
// 推送镜像
|
||||
`
|
||||
if [[ "$(docker images -q ${imageName} 2> /dev/null)" != "" ]];then
|
||||
## 推送
|
||||
docker push ${imageName}
|
||||
echo "---------------- 上传镜像成功,删除本地镜像 ---------------- "
|
||||
docker rmi ${imageName}
|
||||
else
|
||||
echo "镜像: ${imageName} , 不存在"
|
||||
fi
|
||||
`
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支持的脚本命令
|
||||
@@ -21,8 +59,8 @@ const { Select } = require('enquirer');
|
||||
const SupportScripts={
|
||||
build:'vuepress build docs',
|
||||
build_proxy:'PROXY_DOMAIN=true vuepress build docs',
|
||||
image:'bash scripts/build_image.sh $npm_package_version',
|
||||
image_faster:'bash scripts/build_image.sh $npm_package_version faster'
|
||||
image:getBuildImageScript(),
|
||||
image_faster:getBuildImageScript("faster")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,40 +8,73 @@
|
||||
const { execShell } = require("./.exec");
|
||||
const packageVersion=require('../package.json').version
|
||||
|
||||
const dockerDeployInfo={
|
||||
repoAddress:"registry.cn-hangzhou.aliyuncs.com/142vip/doc_book",
|
||||
containerName:'408CSFamily',
|
||||
networkName:'service_env_net',
|
||||
imageName:`${this.repoAddress}:${this.containerName}-${packageVersion}`
|
||||
}
|
||||
|
||||
// 支持的命令
|
||||
const SupportScripts={
|
||||
Github:`bash scripts/deploy.sh github ${packageVersion}`,
|
||||
Github_Test:[
|
||||
"set -e",
|
||||
"./scripts/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}\"",
|
||||
// 部署到github pages
|
||||
"git push -f https://github.com/mmdapl/408CSFamily.git main:pages/github",
|
||||
"cd -"
|
||||
].join(' && '),
|
||||
Ali:`bash scripts/deploy.sh ali ${packageVersion}`
|
||||
Github:`
|
||||
set -e
|
||||
./scripts/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${packageVersion}"
|
||||
## 部署到github pages
|
||||
git push -f https://github.com/mmdapl/408CSFamily.git main:pages/github
|
||||
cd -
|
||||
`,
|
||||
Ali:[
|
||||
// 容器存在即删除
|
||||
`
|
||||
docker inspect ${dockerDeployInfo.containerName} -f '{{.Name}}' > /dev/null
|
||||
if [ $? -eq 0 ] ;then
|
||||
docker rm -f ${dockerDeployInfo.containerName}
|
||||
fi
|
||||
`,
|
||||
// 镜像存在即删除
|
||||
`
|
||||
if [[ "$(docker images -q ${dockerDeployInfo.imageName} 2> /dev/null)" != "" ]];then
|
||||
docker rmi ${dockerDeployInfo.imageName}
|
||||
fi
|
||||
`,
|
||||
// 运行容器
|
||||
`
|
||||
docker run -d --name ${dockerDeployInfo.containerName}
|
||||
-p 7000:80
|
||||
--network=${dockerDeployInfo.networkName}
|
||||
--restart=unless-stopped
|
||||
--ip=172.30.0.100
|
||||
${dockerDeployInfo.imageName}`,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
const deployName=process.argv[2];
|
||||
|
||||
let deployCommand=SupportScripts.Ali
|
||||
|
||||
// 部署到阿里云服务器
|
||||
if(deployName==='ali'){
|
||||
function getDeployCommand(){
|
||||
let deployCommand=SupportScripts.Ali
|
||||
// 部署到阿里云服务器
|
||||
if(deployName==='ali'){
|
||||
deployCommand=SupportScripts.Ali
|
||||
}
|
||||
// 部署到Github
|
||||
if(deployName==='github'){
|
||||
deployCommand=SupportScripts.Github
|
||||
}
|
||||
return deployCommand
|
||||
}
|
||||
|
||||
// 部署到Github
|
||||
if(deployName==='github'){
|
||||
deployCommand=SupportScripts.Github_Test
|
||||
}
|
||||
|
||||
// 执行
|
||||
;(async ()=>{
|
||||
const deployCommand=getDeployCommand()
|
||||
await execShell(deployCommand)
|
||||
})()
|
||||
99
scripts/network
Executable file
99
scripts/network
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
*
|
||||
* 例如:
|
||||
* - ./scripts/network create
|
||||
* - ./scripts/network inspect
|
||||
* - ./scripts/network rm
|
||||
*/
|
||||
const { execShell, BaseSetting} = require("./.exec");
|
||||
const scriptName=process.argv[2];
|
||||
|
||||
|
||||
/**
|
||||
* 网络基础信息
|
||||
* - 网络名称
|
||||
* - 子网掩码
|
||||
* - 网关地址
|
||||
*/
|
||||
const dockerNetworkInfo={
|
||||
defaultName:'service_env_net',
|
||||
subnet:'172.30.0.0/24',
|
||||
gateway:'172.30.0.1',
|
||||
}
|
||||
|
||||
// 支持的命令
|
||||
const SupportScripts={
|
||||
ls:'docker network ls',
|
||||
create:[
|
||||
// 创建网关
|
||||
`
|
||||
docker network create
|
||||
--subnet=${dockerNetworkInfo.subnet}
|
||||
--gateway=${dockerNetworkInfo.gateway}
|
||||
${dockerNetworkInfo.defaultName}
|
||||
`,
|
||||
// 查看创建后基本信息
|
||||
`
|
||||
docker network inspect ${dockerNetworkInfo.defaultName}
|
||||
`
|
||||
].join(' && '),
|
||||
rm:[
|
||||
// 参数校验
|
||||
`
|
||||
if test -z "${dockerNetworkInfo.defaultName}";then
|
||||
echo "参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
|
||||
fi
|
||||
`,
|
||||
// 判断网络是否存在
|
||||
`
|
||||
docker network ls | grep -w "${dockerNetworkInfo.defaultName}"
|
||||
if [ $? -eq 1 ] ;then
|
||||
echo "容器网络:${dockerNetworkInfo.defaultName} 不存在,删除无效"
|
||||
exit 0;
|
||||
fi
|
||||
`,
|
||||
// 删除网络
|
||||
`
|
||||
docker network rm "${dockerNetworkInfo.defaultName}"
|
||||
`
|
||||
].join(''),
|
||||
inspect:
|
||||
`
|
||||
docker network inspect ${dockerNetworkInfo.defaultName}
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要执行的shell命令
|
||||
* @param scriptName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getCommand(scriptName){
|
||||
let deployCommand=SupportScripts.ls
|
||||
|
||||
// 部署到阿里云服务器
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
// 执行
|
||||
;(async ()=>{
|
||||
const command=getCommand(scriptName)
|
||||
await execShell(command)
|
||||
})()
|
||||
Reference in New Issue
Block a user