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