|
| 1 | +name: Build fastgpt-mcp-server images |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'projects/sandbox/**' |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | +jobs: |
| 10 | + build-fastgpt-mcp_server-images: |
| 11 | + permissions: |
| 12 | + packages: write |
| 13 | + contents: read |
| 14 | + attestations: write |
| 15 | + id-token: write |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - arch: amd64 |
| 20 | + - arch: arm64 |
| 21 | + runs-on: ubuntu-24.04-arm |
| 22 | + runs-on: ${{ matrix.runs-on || 'ubuntu-24.04' }} |
| 23 | + steps: |
| 24 | + # install env |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v3 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + with: |
| 32 | + driver-opts: network=host |
| 33 | + - name: Cache Docker layers |
| 34 | + uses: actions/cache@v4 |
| 35 | + with: |
| 36 | + path: /tmp/.buildx-cache |
| 37 | + key: ${{ runner.os }}-mcp-server-buildx-${{ github.sha }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-mcp_server-buildx- |
| 40 | +
|
| 41 | + # login docker |
| 42 | + - name: Login to GitHub Container Registry |
| 43 | + uses: docker/login-action@v3 |
| 44 | + with: |
| 45 | + registry: ghcr.io |
| 46 | + username: ${{ github.repository_owner }} |
| 47 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + - name: Login to Ali Hub |
| 49 | + uses: docker/login-action@v3 |
| 50 | + with: |
| 51 | + registry: registry.cn-hangzhou.aliyuncs.com |
| 52 | + username: ${{ secrets.ALI_HUB_USERNAME }} |
| 53 | + password: ${{ secrets.ALI_HUB_PASSWORD }} |
| 54 | + - name: Login to Docker Hub |
| 55 | + uses: docker/login-action@v3 |
| 56 | + with: |
| 57 | + username: ${{ secrets.DOCKER_HUB_NAME }} |
| 58 | + password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
| 59 | + |
| 60 | + - name: Build for ${{ matrix.arch }} |
| 61 | + id: build |
| 62 | + uses: docker/build-push-action@v6 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + file: projects/mcp_server/Dockerfile |
| 66 | + platforms: linux/${{ matrix.arch }} |
| 67 | + labels: | |
| 68 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 69 | + org.opencontainers.image.description=fastgpt-mcp_server image |
| 70 | + outputs: type=image,"name=ghcr.io/${{ github.repository_owner }}/fastgpt-mcp_server,${{ secrets.ALI_IMAGE_NAME }}/fastgpt-mcp_server,${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-mcp_server",push-by-digest=true,push=true |
| 71 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 72 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 73 | + |
| 74 | + - name: Export digest |
| 75 | + run: | |
| 76 | + mkdir -p ${{ runner.temp }}/digests |
| 77 | + digest="${{ steps.build.outputs.digest }}" |
| 78 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 79 | +
|
| 80 | + - name: Upload digest |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: digests-fastgpt-mcp_server-${{ github.sha }}-${{ matrix.arch }} |
| 84 | + path: ${{ runner.temp }}/digests/* |
| 85 | + if-no-files-found: error |
| 86 | + retention-days: 1 |
| 87 | + |
| 88 | + release-fastgpt-mcp_server-images: |
| 89 | + permissions: |
| 90 | + packages: write |
| 91 | + contents: read |
| 92 | + attestations: write |
| 93 | + id-token: write |
| 94 | + needs: build-fastgpt-mcp_server-images |
| 95 | + runs-on: ubuntu-24.04 |
| 96 | + steps: |
| 97 | + - name: Login to GitHub Container Registry |
| 98 | + uses: docker/login-action@v3 |
| 99 | + with: |
| 100 | + registry: ghcr.io |
| 101 | + username: ${{ github.repository_owner }} |
| 102 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + - name: Login to Ali Hub |
| 104 | + uses: docker/login-action@v3 |
| 105 | + with: |
| 106 | + registry: registry.cn-hangzhou.aliyuncs.com |
| 107 | + username: ${{ secrets.ALI_HUB_USERNAME }} |
| 108 | + password: ${{ secrets.ALI_HUB_PASSWORD }} |
| 109 | + - name: Login to Docker Hub |
| 110 | + uses: docker/login-action@v3 |
| 111 | + with: |
| 112 | + username: ${{ secrets.DOCKER_HUB_NAME }} |
| 113 | + password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
| 114 | + |
| 115 | + - name: Download digests |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + path: ${{ runner.temp }}/digests |
| 119 | + pattern: digests-fastgpt-mcp_server-${{ github.sha }}-* |
| 120 | + merge-multiple: true |
| 121 | + |
| 122 | + - name: Set up Docker Buildx |
| 123 | + uses: docker/setup-buildx-action@v3 |
| 124 | + |
| 125 | + - name: Set image name and tag |
| 126 | + run: | |
| 127 | + if [[ "${{ github.ref_name }}" == "main" ]]; then |
| 128 | + echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 129 | + echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 130 | + echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 131 | + echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 132 | + echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 133 | + echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 134 | + else |
| 135 | + echo "Git_Tag=ghcr.io/${{ github.repository_owner }}/fastgpt-mcp_server:${{ github.ref_name }}" >> $GITHUB_ENV |
| 136 | + echo "Git_Latest=ghcr.io/${{ github.repository_owner }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 137 | + echo "Ali_Tag=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-mcp_server:${{ github.ref_name }}" >> $GITHUB_ENV |
| 138 | + echo "Ali_Latest=${{ secrets.ALI_IMAGE_NAME }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 139 | + echo "Docker_Hub_Tag=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-mcp_server:${{ github.ref_name }}" >> $GITHUB_ENV |
| 140 | + echo "Docker_Hub_Latest=${{ secrets.DOCKER_IMAGE_NAME }}/fastgpt-mcp_server:latest" >> $GITHUB_ENV |
| 141 | + fi |
| 142 | +
|
| 143 | + - name: Create manifest list and push |
| 144 | + working-directory: ${{ runner.temp }}/digests |
| 145 | + run: | |
| 146 | + TAGS="$(echo -e "${Git_Tag}\n${Git_Latest}\n${Ali_Tag}\n${Ali_Latest}\n${Docker_Hub_Tag}\n${Docker_Hub_Latest}")" |
| 147 | + for TAG in $TAGS; do |
| 148 | + docker buildx imagetools create -t $TAG \ |
| 149 | + $(printf 'ghcr.io/${{ github.repository_owner }}/fastgpt-mcp_server@sha256:%s ' *) |
| 150 | + sleep 5 |
| 151 | + done |
0 commit comments