cacheable dockerfile #8
Workflow file for this run
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 Docker Images | |
| on: | |
| workflow_run: | |
| workflows: ["Build and Test"] | |
| branches: [main] | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| push: | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.run_id }} | |
| cancel-in-progress: false | |
| jobs: | |
| docker-build: | |
| name: Multi-architecture Docker Images | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'push' }} | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Load common configuration | |
| id: config | |
| uses: ./.github/actions/load-config | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64,amd64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Get SHA | |
| id: get_sha | |
| run: | | |
| SHORT_SHA=${GITHUB_SHA::7} | |
| echo "sha=$SHORT_SHA" >> $GITHUB_OUTPUT | |
| - name: Prepare tags | |
| id: prep | |
| run: | | |
| SHORT_SHA=${GITHUB_SHA::7} | |
| declare -a TAGS=() | |
| declare -a SEED0_TAGS=() | |
| DOCKER_REGISTRY="${{ steps.config.outputs.docker_registry }}" | |
| DOCKER_NAMESPACE="${{ steps.config.outputs.docker_namespace }}" | |
| IMAGE_NAME="${{ steps.config.outputs.image_name }}" | |
| TAGS+=("$DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME:sha-$SHORT_SHA") | |
| SEED0_TAGS+=("$DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME:sha-$SHORT_SHA-seed0") | |
| git fetch --depth=2 || true | |
| git fetch origin main --depth=2 || true | |
| VERSION=$(grep "^version" crates/starknet-devnet/Cargo.toml | sed -E 's/.*"(.*)"/\1/') | |
| PREVIOUS_VERSION="" | |
| if git rev-parse HEAD~1 &>/dev/null; then | |
| PREVIOUS_VERSION=$(git show HEAD~1:crates/starknet-devnet/Cargo.toml | grep "^version" | sed -E 's/.*"(.*)"/\1/' || echo "") | |
| else | |
| echo "Cannot determine previous version, will not add version tags" | |
| fi | |
| if [[ -n "$PREVIOUS_VERSION" && "$VERSION" != "$PREVIOUS_VERSION" ]] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAGS+=("$DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME:$VERSION") | |
| SEED0_TAGS+=("$DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME:$VERSION-seed0") | |
| if [[ ! "$VERSION" =~ "rc" ]]; then | |
| TAGS+=("$DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME:latest") | |
| SEED0_TAGS+=("$DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME:latest-seed0") | |
| fi | |
| fi | |
| echo "tags=$(IFS=,; echo "${TAGS[*]}")" >> $GITHUB_OUTPUT | |
| echo "seed0_tags=$(IFS=,; echo "${SEED0_TAGS[*]}")" >> $GITHUB_OUTPUT | |
| - name: Build and push multi-platform Docker images | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.prep.outputs.tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build and push seed0 Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/seed0.Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.prep.outputs.seed0_tags }} | |
| build-args: | | |
| BASE_IMAGE=${{ steps.config.outputs.docker_registry }}/${{ steps.config.outputs.docker_namespace }}/${{ steps.config.outputs.image_name }}:sha-${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |