feat(ci): add concurrency control to cancel in-progress runs #3
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 Publish Docker Images | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'base/**' | |
| - 'intermediate/**' | |
| - 'infra/**' | |
| - '.github/workflows/docker-publish.yml' | |
| workflow_dispatch: | |
| inputs: | |
| layer: | |
| description: 'Layer to build (all builds everything)' | |
| default: 'all' | |
| type: choice | |
| options: | |
| - all | |
| - base | |
| - intermediate | |
| - infra | |
| image: | |
| description: 'Specific image name (optional, leave empty for all in layer)' | |
| required: false | |
| type: string | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/devcontainers | |
| jobs: | |
| build-base: | |
| if: github.event_name == 'push' || inputs.layer == 'all' || inputs.layer == 'base' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| digest: ${{ steps.build.outputs.digest }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push base-system | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: base/base-system.Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_PREFIX }}/base-system:latest | |
| ${{ env.IMAGE_PREFIX }}/base-system:${{ github.sha }} | |
| cache-from: type=gha,scope=base-system | |
| cache-to: type=gha,mode=max,scope=base-system | |
| - name: Make package public | |
| run: | | |
| gh api --method PUT /orgs/${{ github.repository_owner }}/packages/container/devcontainers%2Fbase-system/visibility \ | |
| -f visibility=public || true | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-intermediate: | |
| if: github.event_name == 'push' || inputs.layer == 'all' || inputs.layer == 'intermediate' | |
| needs: build-base | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: [rust, go] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push ${{ matrix.image }} | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: intermediate/${{ matrix.image }}.Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:latest | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:${{ github.sha }} | |
| cache-from: type=gha,scope=${{ matrix.image }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.image }} | |
| build-contexts: | | |
| base-system:latest=docker-image://${{ env.IMAGE_PREFIX }}/base-system:latest | |
| - name: Make package public | |
| run: | | |
| gh api --method PUT /orgs/${{ github.repository_owner }}/packages/container/devcontainers%2F${{ matrix.image }}/visibility \ | |
| -f visibility=public || true | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-infra-base: | |
| if: github.event_name == 'push' || inputs.layer == 'all' || inputs.layer == 'infra' | |
| needs: build-base | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - coinbase | |
| - coinbase_ethereum | |
| - coinbase_ethereum_solana | |
| - coinbase_polygon | |
| - convex | |
| - ethereum | |
| - hardhat | |
| - injective | |
| - mongodb | |
| - polygon | |
| - postgresql | |
| - universal | |
| - zksync | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push ${{ matrix.image }} | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: infra/${{ matrix.image }}.Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:latest | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:${{ github.sha }} | |
| cache-from: type=gha,scope=${{ matrix.image }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.image }} | |
| build-contexts: | | |
| base-system:latest=docker-image://${{ env.IMAGE_PREFIX }}/base-system:latest | |
| - name: Make package public | |
| run: | | |
| gh api --method PUT /orgs/${{ github.repository_owner }}/packages/container/devcontainers%2F${{ matrix.image }}/visibility \ | |
| -f visibility=public || true | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-infra-rust: | |
| if: github.event_name == 'push' || inputs.layer == 'all' || inputs.layer == 'infra' | |
| needs: build-intermediate | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - aptos | |
| - brevis | |
| - foundry | |
| - reth | |
| - rindexer | |
| - risc0 | |
| - solana | |
| - stylus | |
| - succinct | |
| - sui | |
| - tangle | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push ${{ matrix.image }} | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: infra/${{ matrix.image }}.Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:latest | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:${{ github.sha }} | |
| cache-from: type=gha,scope=${{ matrix.image }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.image }} | |
| build-contexts: | | |
| rust:latest=docker-image://${{ env.IMAGE_PREFIX }}/rust:latest | |
| - name: Make package public | |
| run: | | |
| gh api --method PUT /orgs/${{ github.repository_owner }}/packages/container/devcontainers%2F${{ matrix.image }}/visibility \ | |
| -f visibility=public || true | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-infra-go: | |
| if: github.event_name == 'push' || inputs.layer == 'all' || inputs.layer == 'infra' | |
| needs: build-intermediate | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - cosmos | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push ${{ matrix.image }} | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: infra/${{ matrix.image }}.Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:latest | |
| ${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:${{ github.sha }} | |
| cache-from: type=gha,scope=${{ matrix.image }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.image }} | |
| build-contexts: | | |
| go:latest=docker-image://${{ env.IMAGE_PREFIX }}/go:latest | |
| - name: Make package public | |
| run: | | |
| gh api --method PUT /orgs/${{ github.repository_owner }}/packages/container/devcontainers%2F${{ matrix.image }}/visibility \ | |
| -f visibility=public || true | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |