Compare commits

...

5 Commits

Author SHA1 Message Date
编码猿
3c3309af28 frontend
All checks were successful
build and push / build-and-push (push) Successful in 2m25s
2025-10-07 21:05:59 +08:00
编码猿
a2dad87e52 重新部署
Some checks failed
build and push / build-and-push (push) Failing after 2m23s
2025-10-07 20:57:45 +08:00
编码猿
cf6f58a46f 删除老旧镜像,保留最新版和上一版本![skip actions] 2025-10-07 05:21:52 +08:00
编码猿
22b11cf45c 测试删除老旧镜像
All checks were successful
build and push / build-and-push (push) Successful in 1m47s
2025-10-07 05:12:01 +08:00
编码猿
aa72af578a 测试提交
All checks were successful
build and push / build-and-push (push) Successful in 1m32s
2025-10-07 05:05:55 +08:00
2 changed files with 15 additions and 4 deletions

View File

@@ -1,6 +1,5 @@
name: build and push
# 当代码推送到 main 分支时触发
on:
push:
branches: [ main ]
@@ -59,6 +58,14 @@ jobs:
password: ${{ secrets.PASSWORD }}
port: ${{ vars.PORT }}
script: |
# 因为正在运行的镜像被占用了,所以下面命令无法删除,只能删除从前没在使用的老镜像
# 然后拉取最新镜像,所有 服务器内部会有两个镜像:最新的,和上一个版本的镜像
# 挺好的保留上一版前端出bug了镜像可以退回去。如果不想保留上一版本
# 那么需要在这里 先 docker stack rm 停止等待5秒后再删除镜像即可.
# docker stack rm ${{ vars.DOCKER_IMAGE_NAME }}
# sleep 5
# 同样的如果用了这个代码那么下面8384行则之间注释即可
# 删除该仓库的所有镜像
docker images --format "{{.ID}}" ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE_NAME }} | xargs -r docker rmi -f
# 拉取刚打包的最新镜像
@@ -73,5 +80,8 @@ jobs:
password: ${{ secrets.PASSWORD }}
port: ${{ vars.PORT }}
script: |
# 先停止之前的 swarm 并等待5秒后再重新运行要不然用的还是之前老镜像
docker stack rm ${{ vars.DOCKER_IMAGE_NAME }}
sleep 5
# 切换到管理员,要不然没权限在服务器执行 docker 命令,部署到 Swarm 集群
sudo docker stack deploy -c ${{ vars.SSH_MANAGE_PATH }}${{ vars.DOCKER_SWARM_YML }} ${{ vars.DOCKER_IMAGE_NAME }}

View File

@@ -1,5 +1,9 @@
version: "3.8" # Docker Compose 文件版本3.8 支持 Swarm 模式的所有功能
networks:
frontend: # 定义 frontend 网络
driver: overlay # 使用 overlay 网络驱动,支持跨主机通信
services:
app-product:
image: registry.bmycode.help/app-product:{{IMAGE_TAG}}
@@ -34,6 +38,3 @@ services:
networks:
- frontend # 连接到 frontend 网络
networks:
frontend: # 定义 frontend 网络
driver: overlay # 使用 overlay 网络驱动,支持跨主机通信