2 Star 0 Fork 0

keep/pk_h5

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
.gitlab-ci.yml 3.94 KB
一键复制 编辑 原始数据 按行查看 历史
jason 提交于 2024-12-02 13:19 . 修改自动打包文件名
# runner 会挂载主机的以下目录:
# /root/deploy: 部署主目录
# /var/run/docker.sock: dind共享
# /var/lib/docker: 镜像共享
# /usr/local/bin/docker-compose: compose共享
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
services:
- docker:dind
# 定义不同分支的端口,部署路径
build:
stage: test
tags:
- web
before_script:
- |
case "$CI_COMMIT_BRANCH" in
"old_main")
DEPLOY_NAME="oldh5"
;;
"new_version_main")
DEPLOY_NAME="h5"
;;
*)
echo "Branch '$CI_COMMIT_BRANCH' does not match any predefined configurations."
exit 1
;;
esac
escape_markdown() {
echo "$1" | sed 's/\\/\\\\/g;s/_/\\_/g;s/`/\\`/g;s/\./\\./g;s/-/\\-/g;s/+/\\+/g;s/!/\\!/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/{/\\{/g;s/}/\\}/g;s/~/\\~/g;s/\^/\\^/g;s/|/\\|/g;s/:/\\:/g;s/ /\\ /g;'
}
COMMIT_BRANCH=$(escape_markdown "$CI_COMMIT_BRANCH")
COMMIT_MESSAGE_STR=$(escape_markdown "$(git log -1 --pretty=format:%s)")
COMMIT_AUTHOR=$(escape_markdown "$(git log -1 --pretty=format:%an)")
COMMIT_TIMESTAMP=$(git log -1 --pretty=format:%ct)
COMMIT_TIME_STRING0=$(TZ="Asia/Shanghai" date -d @$COMMIT_TIMESTAMP +"%Y-%m-%d %H:%M:%S")
COMMIT_TIME_STRING=$(escape_markdown "$COMMIT_TIME_STRING0")
echo "COMMIT_MESSAGE_STR=$COMMIT_MESSAGE_STR" > /tmp/commit_info.txt
echo "COMMIT_AUTHOR=$COMMIT_AUTHOR" >> /tmp/commit_info.txt
echo "COMMIT_TIME_STRING=\"$COMMIT_TIME_STRING\"" >> /tmp/commit_info.txt
script:
- |
DEPLOY_DST="/root/deploy/$DEPLOY_NAME"
mkdir -p $DEPLOY_DST
# 清理异常构建容器,并启动构建容器
if docker ps -q -f name=temp0 > /dev/null; then docker stop temp0 && docker rm temp0; fi
docker run -d --name temp0 node:22.1.0 bash -c "tail -f /dev/null"
# # 替换静态资源# 在 src 目录下执行替换操作
# find src -type f -exec sed -i "s|\"/imgs/|\"/$DEPLOY_NAME/imgs/|g" {} +
# find src -type f -exec sed -i "s|\"/pwa/|\"/$DEPLOY_NAME/pwa/|g" {} +
# find src -type f -exec sed -i "s|\"/svga/|\"/$DEPLOY_NAME/svga/|g" {} +
# find src -type f -exec sed -i "s|'\/imgs/|'\/$DEPLOY_NAME/imgs/|g" {} +
# find src -type f -exec sed -i "s|'\/pwa/|'\/$DEPLOY_NAME/pwa/|g" {} +
# find src -type f -exec sed -i "s|'\/svga/|'\/$DEPLOY_NAME/svga/|g" {} +
# # 在 public 目录下执行替换操作
# find public -type f -exec sed -i "s|\"/imgs/|\"/$DEPLOY_NAME/imgs/|g" {} +
# find public -type f -exec sed -i "s|\"/pwa/|\"/$DEPLOY_NAME/pwa/|g" {} +
# find public -type f -exec sed -i "s|\"/svga/|\"/$DEPLOY_NAME/svga/|g" {} +
# find public -type f -exec sed -i "s|'\/imgs/|'\/$DEPLOY_NAME/imgs/|g" {} +
# find public -type f -exec sed -i "s|'\/pwa/|'\/$DEPLOY_NAME/pwa/|g" {} +
# find public -type f -exec sed -i "s|'\/svga/|'\/$DEPLOY_NAME/svga/|g" {} +
# 拷贝代码到容器并开始构建
docker cp ./ temp0:/data
docker exec temp0 bash -c "cd /data && yarn && VITE_PUBLIC_PATH=$DEPLOY_NAME npm run build"
docker cp temp0:/data/dist dist
cp -rf dist/* $DEPLOY_DST
# 删除临时构建容器
docker stop temp0 && docker rm temp0
docker run --rm botw python bot.py "$(echo -e "Status:\ Deploy Success🎉🎉🎉\nBranch:\ ${COMMIT_BRANCH}\nMessage:\ ${COMMIT_MESSAGE_STR}\nAuthor:\ ${COMMIT_AUTHOR}\nTime:\ ${COMMIT_TIME_STRING}")"
rules:
# 新版本使用rules控制条件
- if: '$CI_COMMIT_BRANCH == "old_main"'
when: always
- if: '$CI_COMMIT_BRANCH == "new_version_main"'
when: always
after_script:
- |
if [ "$CI_JOB_STATUS" == "failed" ]; then
source /tmp/commit_info.txt
docker run --rm botw python bot.py "$(echo -e "Status:\ Deploy Failed❌\nBranch:\ ${COMMIT_BRANCH}\nMessage:\ ${COMMIT_MESSAGE_STR}\nAuthor:\ ${COMMIT_AUTHOR}\nTime:\ ${COMMIT_TIME_STRING}")"
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/keep1996/pk_h5.git
git@gitee.com:keep1996/pk_h5.git
keep1996
pk_h5
pk_h5
new_version_owen

搜索帮助

0d507c66 1850385 C8b1a773 1850385