first commit
Some checks failed
build and push / build-and-push (push) Has been cancelled

This commit is contained in:
编码猿
2025-10-07 03:17:55 +08:00
commit b77e36a178
83 changed files with 6356 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
name: build and push
# 当代码推送到 main 分支时触发
on:
push:
branches: [ main ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: 拉取最新代码
uses: actions/checkout@v4
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录到自己的 Docker 仓库
uses: docker/login-action@v3
with:
registry: registry.bmycode.help
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 构建并推送镜像
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
registry.bmycode.help/app-product:latest
registry.bmycode.help/app-product:${{ github.sha }}
- name: 替换镜像标签为 github.sha
run: |
sed -i "s|{{IMAGE_TAG}}|${{ github.sha }}|g" app-product.yml
- name: 上传 app-product.yml 到前端集群管理机
uses: appleboy/scp-action@v1
with:
host: ${{ vars.SSH_MANAGE }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
source: "app-product.yml"
target: "/home/bmy/"
- name: 登录前端集群,拉镜像
uses: appleboy/ssh-action@v1
with:
# 统一登录三台前端集群的linux统一拉取刚推到仓库的最新镜像
# 解决 Swarm 无法控制 工作机拉取镜像的问题!
host: ${{ vars.SSH_HOST_LIST }}
sync: true
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
# 拉取刚打包的最新镜像
docker pull registry.bmycode.help/app-product:${{ github.sha }}
- name: 管理节点部署到 Swarm
uses: appleboy/ssh-action@v1
with:
host: ${{ vars.SSH_MANAGE }}
sync: true
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
# 切换到管理员,要不然没权限在服务器执行 docker 命令,部署到 Swarm 集群
sudo docker stack deploy -c /home/bmy/app-product.yml app-product