Files
gitea_actions/.gitea/workflows/build.yml
编码猿 aefbb552e6
Some checks failed
build and push / build-and-push (push) Failing after 2m43s
sudo
2025-10-06 23:17:19 +08:00

71 lines
2.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# 验证替换结果(可选,用于调试)
echo "替换后的 app-product.yml 内容:"
cat app-product.yml
echo ""
- 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 }}
# 切换到管理员,要不然没权限在服务器执行 docker 命令,部署到 Swarm 集群
sudo docker stack deploy -c /home/bmy/app-product.yml app-product