1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-04-13 18:00:58 +08:00

feat: 脚本优化更新

This commit is contained in:
chu fan
2023-09-06 09:57:37 +08:00
parent 0842ce3276
commit c072b3d3a4
6 changed files with 79 additions and 71 deletions

View File

@@ -20,7 +20,7 @@
"image": "bash scripts/build_image.sh $npm_package_version",
"image:faster": "bash scripts/build_image.sh $npm_package_version faster",
"deploy:ali": "bash scripts/deploy.sh ali $npm_package_version",
"deploy:github": "bash scripts/page_deploy.sh",
"deploy:github": "bash scripts/deploy.sh github $npm_package_version",
"deploy:vercel": "vercel --prod",
"release": "bumpp --preid alpha --execute=\"pnpm commit-and-tag-version && git add CHANGELOG.md\" --commit \"chore(release): publish v%s\" --all --tag --push",
"lint": "eslint --ext .js,.vue,.ts --ignore-path .gitignore .",

9
scripts/build_image.sh Normal file → Executable file
View File

@@ -24,7 +24,7 @@ isFaster=${2}
imageTagName=${repoAddress}:${projectName}-${version}
## 预检查
## 参数预检查
prepare_check(){
if test -z "${version}";then
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空。参考版本: 0.0.x"
@@ -49,12 +49,6 @@ run(){
--build-arg APP_VERSION="${version}" \
--build-arg CONTAINER_BUILD=true \
-t "${imageTagName}" .
echo 12312
echo docker build \
--build-arg APP_VERSION="${version}" \
--build-arg CONTAINER_BUILD=true \
-t "${imageTagName}" .
fi
echo -e "${successLogger}---------------- shell ${projectName} end ---------------- "
@@ -79,7 +73,6 @@ push_docker_image(){
}
prepare_check
run

47
scripts/deploy Executable file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env node
/**
*
* 例如:
* - ./scripts/deploy ali
* - ./scripts/deploy github
*/
const { execShell } = require("./.exec");
const packageVersion=require('../package.json').version
// 支持的命令
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}`
}
const deployName=process.argv[2];
let deployCommand=SupportScripts.Ali
// 部署到阿里云服务器
if(deployName==='ali'){
deployCommand=SupportScripts.Ali
}
// 部署到Github
if(deployName==='github'){
deployCommand=SupportScripts.Github_Test
}
// 执行
;(async ()=>{
await execShell(deployCommand)
})()

View File

@@ -1,9 +1,9 @@
#!/bin/bash
## 功能:清除容器,删除旧镜像,创建新的容器
## 参考https://blog.csdn.net/Dontla/article/details/125210694
## 作者:储凡
## 使用示例bash xxx.sh 容器名称 镜像地址
## 使用示例bash deploy.sh 部署平台 版本号
## - bash deploy.sh ali 0.0.1
##
## 日志颜色定义
@@ -18,18 +18,24 @@ readonly networkName="service_env_net"
## 定义参数
operationName=${1}
version=${2}
## 镜像名称
imageName="${repoAddress}:${containerName}-${version}"
## 参数检查
## 参数预检查
prepare_check(){
if test -z "${containerName}"
if test -z "${operationName}"
then
echo -e "${errorLogger}${currentTime}:参数错误 部署平台不能为空."
exit 0
fi
if test -z "${version}"
then
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空."
exit 0
fi
}
## 判断容器存在即删除
@@ -72,7 +78,7 @@ run(){
## 删除容器
delete_container "${containerName}"
## 删除镜像
delete_image "${repoAddress}:${containerName}-${version}"
delete_image "${imageName}"
## 部署
deploy_to_ali
exit 0;
@@ -92,7 +98,7 @@ deploy_to_ali(){
--network="${networkName}" \
--restart=unless-stopped \
--ip=172.30.0.100 \
"${repoAddress}:${containerName}-${version}"
"${imageName}"
echo -e "${successLogger}---------------- deploy ${containerName} ali end ------------------ "
docker ps
@@ -102,29 +108,23 @@ deploy_to_ali(){
deploy_to_github(){
echo -e "${successLogger}---------------- deploy ${containerName} github start ---------------- "
# 当命令以非零状态退出时则退出shell
set -e
npm run build-proxy && cd docs/.vuepress/dist
git init && git add -A
# 进入上级目录,并编译
npm run build && cd docs/.vuepress/dist
git init && git add --all
## 如果没有输入commit信息则采用默认
if [ "${commitInfo}" -eq "" ]; then
commitInfo="408CSFamily Init"
fi
git commit -m "refactor:${commitInfo}"
## 配置个人信息
git config user.name "晚上吃芝士+葡萄的妹妹"
git config user.email "fairy0115@2925.com"
## 配置信息
git config user.name 'chu fan'
git config user.email 'fairy_408@2925.com'
git config --list
# if you are deploying to https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f https://github.com/mmdapl/408CSFamily.git master:pages/github
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 ------------------ "
}

View File

@@ -1,27 +0,0 @@
#!/usr/bin/env sh
commitInfo=${1}
set -e
npm run build-proxy && cd docs/.vuepress/dist
git init && git add -A
## 如果没有输入commit信息则采用默认
if [ "${commitInfo}" -eq "" ]; then
commitInfo="408CSFamily page init"
fi
## 配置个人信息
git config user.name 'chu fan' && git config user.email 'fairy_408@2925.com' && git config --list
git commit -m "refactor:${commitInfo}"
# 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 -

View File

@@ -1,5 +1,9 @@
#!/usr/bin/env node
/**
* 脚本测试
* 链接https://github.com/enquirer/enquirer
*/
// const {execShell} = require("./.exec");
(async ()=>{
@@ -22,15 +26,6 @@
'Coconut',
'Cranberry',
'Grape',
'Nougat',
'Orange',
'Pear',
'Pineapple',
'Raspberry',
'Strawberry',
'Vanilla',
'Watermelon',
'Wintergreen'
]
});