Docker Build and Push #195
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 Push | |
| on: | |
| push: | |
| branches: [main, master] | |
| tags: ['v*'] | |
| pull_request: | |
| branches: [main, master, "ci/docker", "ops/dev-env"] | |
| workflow_dispatch: | |
| inputs: | |
| force_chains: | |
| description: 'Force rebuild chain images (comma-separated: mars,venus,gno,a1gno or "all")' | |
| required: false | |
| default: '' | |
| jobs: | |
| # ── Relayer image (multi-arch) ───────────────────────────── | |
| build: | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64] | |
| include: | |
| - arch: amd64 | |
| runner: ubuntu-latest | |
| platform: linux/amd64 | |
| - arch: arm64 | |
| runner: ubuntu-24.04-arm | |
| platform: linux/arm64 | |
| runs-on: ${{ matrix.runner }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}},suffix=-${{ matrix.arch }} | |
| type=raw,value=latest,suffix=-${{ matrix.arch }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=build-${{ matrix.arch }} | |
| cache-to: type=gha,scope=build-${{ matrix.arch }},mode=max | |
| merge: | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=raw,value=latest | |
| - name: Create multi-arch manifests | |
| run: | | |
| IMAGE="ghcr.io/${{ github.repository }}" | |
| for TAG in $(jq -cr '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON"); do | |
| TAG_SUFFIX="${TAG#${IMAGE}:}" | |
| docker buildx imagetools create -t "$TAG" \ | |
| "${IMAGE}:${TAG_SUFFIX}-amd64" \ | |
| "${IMAGE}:${TAG_SUFFIX}-arm64" | |
| done | |
| # ── Chain images (multi-arch) ────────────────────────────── | |
| build-chains: | |
| strategy: | |
| matrix: | |
| chain: [mars, venus, gno, a1gno] | |
| arch: [amd64, arm64] | |
| include: | |
| - arch: amd64 | |
| runner: ubuntu-latest | |
| platform: linux/amd64 | |
| - arch: arm64 | |
| runner: ubuntu-24.04-arm | |
| platform: linux/arm64 | |
| runs-on: ${{ matrix.runner }} | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Check for changes in chain directory | |
| id: changes | |
| uses: dorny/paths-filter@v3 | |
| with: | |
| filters: | | |
| chain: | |
| - 'docker/chains/${{ matrix.chain }}/**' | |
| - 'docker/chains/serve.sh' | |
| - name: Check if build is needed | |
| id: should | |
| run: | | |
| FORCE="${{ inputs.force_chains }}" | |
| if [ "$FORCE" = "all" ] || echo ",$FORCE," | grep -q ",${{ matrix.chain }},"; then | |
| echo "build=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "build=${{ steps.changes.outputs.chain }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Set up Docker Buildx | |
| if: steps.should.outputs.build == 'true' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| if: steps.should.outputs.build == 'true' && github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| if: steps.should.outputs.build == 'true' | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }}/${{ matrix.chain }} | |
| tags: | | |
| type=semver,pattern={{version}},suffix=-${{ matrix.arch }} | |
| type=raw,value=latest,suffix=-${{ matrix.arch }} | |
| - name: Build and push Docker image | |
| if: steps.should.outputs.build == 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: docker/chains | |
| file: docker/chains/${{ matrix.chain }}/Dockerfile | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=${{ matrix.chain }}-${{ matrix.arch }} | |
| cache-to: type=gha,scope=${{ matrix.chain }}-${{ matrix.arch }},mode=max | |
| merge-chains: | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| needs: build-chains | |
| strategy: | |
| matrix: | |
| chain: [mars, venus, gno, a1gno] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }}/${{ matrix.chain }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=raw,value=latest | |
| - name: Create multi-arch manifests | |
| run: | | |
| IMAGE="ghcr.io/${{ github.repository }}/${{ matrix.chain }}" | |
| for TAG in $(jq -cr '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON"); do | |
| TAG_SUFFIX="${TAG#${IMAGE}:}" | |
| if docker buildx imagetools inspect "${IMAGE}:${TAG_SUFFIX}-amd64" > /dev/null 2>&1; then | |
| docker buildx imagetools create -t "$TAG" \ | |
| "${IMAGE}:${TAG_SUFFIX}-amd64" \ | |
| "${IMAGE}:${TAG_SUFFIX}-arm64" | |
| else | |
| echo "Skipping $TAG (source images not found)" | |
| fi | |
| done |