Files
gitea_actions/.gitea/workflows/build.yml
编码猿 55ac3cf2df
Some checks failed
build and push / build-and-push (push) Failing after 4m31s
jiq
2025-10-06 22:57:12 +08:00

78 lines
2.4 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:
# 使用项目中的 Dockerfile
context: .
# 构建成功后自动将镜像推送到仓库
push: true
# tags: 定义镜像的名称和标签
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 }}
# 进入部署目录
cd /home/bmy/
# 部署到 Swarm 集群
docker stack deploy -c app-product.yml app-product