Workflow file for this run
This file contains 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 | |
on: | |
push: | |
branches: | |
- main | |
- db/multi-platform-docker | |
tags: | |
- "*" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
set-tags: | |
name: Set Docker Tags | |
runs-on: ubuntu-latest | |
outputs: | |
base_tag: ${{ steps.set_tag.outputs.base_tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Git SHA | |
id: git_sha | |
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Determine Base Tag | |
id: set_tag | |
run: | | |
ts=$(date +%s%N | cut -b1-13) | |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "base_tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref }}" == "refs/heads/db/multi-platform-docker" ]]; then | |
echo "base_tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
echo "base_tag=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
echo "base_tag=none" >> $GITHUB_OUTPUT | |
else | |
echo "Unsupported event ${GITHUB_EVENT_NAME} or ref ${GITHUB_REF}. Only refs/heads/main, refs/tags/*, and pull_request are supported." | |
echo "base_tag=none" >> $GITHUB_OUTPUT | |
build-push-image: | |
name: Build and Push Docker Image for ${{ matrix.arch }} | |
runs-on: [matterlabs-ci-runner-high-performance] | |
needs: set-tags | |
strategy: | |
matrix: | |
include: | |
- platform: linux/amd64 | |
arch: amd64 | |
- platform: linux/arm64 | |
arch: arm64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Base Docker Tag | |
run: echo "BASE_TAG=${{ needs.set-tags.outputs.base_tag }}" >> $GITHUB_ENV | |
- name: Set Repository Owner | |
run: echo "REPO_OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV | |
- name: Set Full Docker Tags | |
id: full_tags | |
run: | | |
base_tag="${{ env.BASE_TAG }}" | |
arch="${{ matrix.arch }}" | |
repo_owner="${{ env.REPO_OWNER }}" | |
if [[ "$base_tag" == "none" ]]; then | |
echo "tags=none" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
echo "ghcr.io/${repo_owner}/anvil-zksync:${base_tag}-${arch}" >> tags.txt | |
echo "us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${base_tag}-${arch}" >> tags.txt | |
echo "tags=$(cat tags.txt | tr '\n' ',')" >> $GITHUB_OUTPUT | |
- name: Login to GAR | |
run: | | |
gcloud auth configure-docker us-docker.pkg.dev -q | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set Up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image | |
id: docker_build | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/db/multi-platform-docker' || startsWith(github.ref, 'refs/tags/')) }} | |
platforms: ${{ matrix.platform }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ env.BASE_TAG }}-${{ matrix.arch }} | |
us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${{ env.BASE_TAG }}-${{ matrix.arch }} | |
- name: Print image digest to summary | |
run: | | |
echo "Image tags: ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ env.BASE_TAG }}-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY | |
echo "Image tags: us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${{ env.BASE_TAG }}-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY |