Docker Build and Publish #17
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: Docker Build and Publish | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| paths: | |
| - 'cmd/**' | |
| - 'internal/**' | |
| - 'pkg/**' | |
| - 'deploy/docker/**' | |
| - 'go.mod' | |
| - 'go.sum' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag for the image' | |
| required: true | |
| default: 'dev' | |
| env: | |
| DOCKER_HUB_USERNAME: ifuryst | |
| ALIYUN_REGISTRY: registry.ap-southeast-1.aliyuncs.com/mcp-ecosystem | |
| BUILDX_NO_DEFAULT_ATTESTATIONS: 1 | |
| PUSH_LATEST: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Login to Docker Hub | |
| if: env.PUSH_LATEST == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ env.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| if: env.PUSH_LATEST == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Aliyun Container Registry | |
| if: env.PUSH_LATEST == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.ALIYUN_REGISTRY }} | |
| username: ${{ secrets.ALIYUN_USERNAME }} | |
| password: ${{ secrets.ALIYUN_PASSWORD }} | |
| - name: Build and push allinone image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: deploy/docker/allinone/Dockerfile | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| tags: | | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-allinone:latest', env.DOCKER_HUB_USERNAME) || '' }} | |
| ${{ format('{0}/mcp-gateway-allinone:{1}', env.DOCKER_HUB_USERNAME, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('ghcr.io/{0}/allinone:latest', github.repository) || '' }} | |
| ${{ format('ghcr.io/{0}/allinone:{1}', github.repository, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-allinone:latest', env.ALIYUN_REGISTRY) || '' }} | |
| ${{ format('{0}/mcp-gateway-allinone:{1}', env.ALIYUN_REGISTRY, github.ref_name) }} | |
| - name: Build and push apiserver image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: deploy/docker/multi/apiserver/Dockerfile | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| tags: | | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-apiserver:latest', env.DOCKER_HUB_USERNAME) || '' }} | |
| ${{ format('{0}/mcp-gateway-apiserver:{1}', env.DOCKER_HUB_USERNAME, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('ghcr.io/{0}/apiserver:latest', github.repository) || '' }} | |
| ${{ format('ghcr.io/{0}/apiserver:{1}', github.repository, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-apiserver:latest', env.ALIYUN_REGISTRY) || '' }} | |
| ${{ format('{0}/mcp-gateway-apiserver:{1}', env.ALIYUN_REGISTRY, github.ref_name) }} | |
| - name: Build and push mcp-gateway image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: deploy/docker/multi/mcp-gateway/Dockerfile | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| tags: | | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-mcp-gateway:latest', env.DOCKER_HUB_USERNAME) || '' }} | |
| ${{ format('{0}/mcp-gateway-mcp-gateway:{1}', env.DOCKER_HUB_USERNAME, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('ghcr.io/{0}/mcp-gateway:latest', github.repository) || '' }} | |
| ${{ format('ghcr.io/{0}/mcp-gateway:{1}', github.repository, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-mcp-gateway:latest', env.ALIYUN_REGISTRY) || '' }} | |
| ${{ format('{0}/mcp-gateway-mcp-gateway:{1}', env.ALIYUN_REGISTRY, github.ref_name) }} | |
| - name: Build and push mock-user-svc image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: deploy/docker/multi/mock-user-svc/Dockerfile | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| tags: | | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-mock-user-svc:latest', env.DOCKER_HUB_USERNAME) || '' }} | |
| ${{ format('{0}/mcp-gateway-mock-user-svc:{1}', env.DOCKER_HUB_USERNAME, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('ghcr.io/{0}/mock-user-svc:latest', github.repository) || '' }} | |
| ${{ format('ghcr.io/{0}/mock-user-svc:{1}', github.repository, github.ref_name) }} | |
| ${{ env.PUSH_LATEST == 'true' && format('{0}/mcp-gateway-mock-user-svc:latest', env.ALIYUN_REGISTRY) || '' }} | |
| ${{ format('{0}/mcp-gateway-mock-user-svc:{1}', env.ALIYUN_REGISTRY, github.ref_name) }} |