登录前端集群,拉镜像
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
name: Build and Push Docker Image
|
name: 提交代码自动打包前端并构建和推送镜像
|
||||||
|
|
||||||
# 当代码推送到 main 分支时触发
|
# 当代码推送到 main 分支时触发
|
||||||
on:
|
on:
|
||||||
@@ -10,36 +10,42 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# 步骤 1: 检出你的代码仓库
|
- name: 拉取最新代码
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 步骤 2: 设置 Docker Buildx (推荐,支持多平台构建等高级功能)
|
- name: 设置 Docker Buildx
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
# 步骤 3: 登录到你的 Docker 仓库
|
- name: 登录到自己的 Docker 仓库
|
||||||
# 你需要在 Gitea/GitHub 的 Secrets 中配置好 DOCKERHUB_USERNAME 和 DOCKERHUB_TOKEN
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: registry.bmycode.help
|
registry: registry.bmycode.help
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
# 步骤 4: 构建并推送 Docker 镜像 (核心步骤)
|
|
||||||
- name: Build and push
|
- name: 构建并推送镜像
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
# context: . 表示 Docker 构建上下文为当前仓库的根目录
|
# 使用项目中的 Dockerfile
|
||||||
# 这意味着 Dockerfile 中 COPY . . 会复制整个项目代码
|
|
||||||
context: .
|
context: .
|
||||||
|
|
||||||
# push: true 表示构建成功后将镜像推送到仓库
|
# 构建成功后自动将镜像推送到仓库
|
||||||
push: true
|
push: true
|
||||||
|
|
||||||
# tags: 定义镜像的名称和标签
|
# tags: 定义镜像的名称和标签
|
||||||
# 推荐使用 commit sha 作为标签,便于版本追溯
|
|
||||||
tags: |
|
tags: |
|
||||||
registry.bmycode.help/app-product:latest
|
registry.bmycode.help/app-product:latest
|
||||||
registry.bmycode.help/app-product:${{ github.sha }}
|
registry.bmycode.help/app-product:${{ github.sha }}
|
||||||
|
|
||||||
|
- name: 登录前端集群,拉镜像
|
||||||
|
uses: appleboy/ssh-action@v1
|
||||||
|
with:
|
||||||
|
# 192.168.139.19,192.168.139.120,192.168.139.242
|
||||||
|
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 }}
|
||||||
Reference in New Issue
Block a user