Build and Push Docker Image to GHCR and ALI_DOCKER_REGISTRY #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image to GHCR and ALI_DOCKER_REGISTRY | |
| on: | |
| workflow_dispatch: # 手动触发 | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-frontend: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Get short SHA | |
| id: vars | |
| run: echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT | |
| - name: Log in to GHCR with GITHUB_TOKEN | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to Aliyun Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ secrets.ALI_DOCKER_REGISTRY }} | |
| username: ${{ secrets.ALI_DOCKER_USERNAME }} | |
| password: ${{ secrets.ALI_DOCKER_PASSWORD }} | |
| - name: Build and push frontend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./frontend | |
| file: ./frontend/Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/pancrepal-xiaoyibao/kb-frontend:latest | |
| ghcr.io/pancrepal-xiaoyibao/kb-frontend:${{ github.sha }} | |
| ghcr.io/pancrepal-xiaoyibao/kb-frontend:${{ steps.vars.outputs.short_sha }} | |
| ${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-frontend:latest | |
| ${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-frontend:${{ steps.vars.outputs.short_sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64 | |
| - name: Frontend build summary | |
| run: | | |
| echo "✅ 前端容器构建完成!" | |
| echo "" | |
| echo "前端镜像标签:" | |
| echo " - ghcr.io/pancrepal-xiaoyibao/kb-frontend:latest" | |
| echo " - ghcr.io/pancrepal-xiaoyibao/kb-frontend:${{ steps.vars.outputs.short_sha }}" | |
| build-backend: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Get short SHA | |
| id: vars | |
| run: echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT | |
| - name: Log in to GHCR with GITHUB_TOKEN | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to Aliyun Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ secrets.ALI_DOCKER_REGISTRY }} | |
| username: ${{ secrets.ALI_DOCKER_USERNAME }} | |
| password: ${{ secrets.ALI_DOCKER_PASSWORD }} | |
| - name: Build and push backend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./backend | |
| file: ./backend/Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/pancrepal-xiaoyibao/kb-backend:latest | |
| ghcr.io/pancrepal-xiaoyibao/kb-backend:${{ github.sha }} | |
| ghcr.io/pancrepal-xiaoyibao/kb-backend:${{ steps.vars.outputs.short_sha }} | |
| ${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-backend:latest | |
| ${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-backend:${{ steps.vars.outputs.short_sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64 | |
| - name: Backend build summary | |
| run: | | |
| echo "✅ 后端容器构建完成!" | |
| echo "" | |
| echo "后端镜像标签:" | |
| echo " - ghcr.io/pancrepal-xiaoyibao/kb-backend:latest" | |
| echo " - ghcr.io/pancrepal-xiaoyibao/kb-backend:${{ steps.vars.outputs.short_sha }}" |