mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-02-12 06:46:39 +08:00
80 lines
2.0 KiB
JavaScript
Executable File
80 lines
2.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
*
|
|
* 例如:
|
|
* - ./scripts/deploy ali
|
|
* - ./scripts/deploy github
|
|
*/
|
|
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:`
|
|
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];
|
|
|
|
|
|
function getDeployCommand(){
|
|
let deployCommand=SupportScripts.Ali
|
|
// 部署到阿里云服务器
|
|
if(deployName==='ali'){
|
|
deployCommand=SupportScripts.Ali
|
|
}
|
|
// 部署到Github
|
|
if(deployName==='github'){
|
|
deployCommand=SupportScripts.Github
|
|
}
|
|
return deployCommand
|
|
}
|
|
|
|
|
|
// 执行
|
|
;(async ()=>{
|
|
const deployCommand=getDeployCommand()
|
|
await execShell(deployCommand)
|
|
})() |