Docker #19
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
| # Builds and uploads docker images whenever a version tag is pushed. When a release is created, | |
| # the associated image is then tagged with the version number and latest. | |
| name: Docker | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - 'v*' | |
| release: | |
| types: [published] | |
| env: | |
| # Workaround for https://github.com/rust-lang/cargo/issues/8719#issuecomment-1516492970 | |
| CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse | |
| jobs: | |
| manual-build-image: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: blacksmith-8vcpu-ubuntu-2204 | |
| env: | |
| BLACKSMITH_DOCKER_CACHE_KEY: ${{ github.repository }}-docker-pathfinder | |
| steps: | |
| - name: Checkout sources | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate version | |
| id: generate_version | |
| run: | | |
| git fetch --force --tags https://github.com/eqlabs/pathfinder.git 'refs/tags/v*:refs/tags/v*' | |
| echo -n "pathfinder_version=" >> "$GITHUB_OUTPUT" | |
| git describe --tags --dirty --always >> "$GITHUB_OUTPUT" | |
| - name: Tags | |
| id: tag | |
| run: | | |
| IMAGE="ghcr.io/${{ github.repository_owner }}/pathfinder" | |
| SHA=$(git rev-parse --short=7 "$GITHUB_SHA") | |
| MANUAL_SHA="$IMAGE:manual-$SHA" | |
| TAGS="$MANUAL_SHA" | |
| echo "manual-sha=$MANUAL_SHA" >> "$GITHUB_OUTPUT" | |
| if [[ "${{ github.ref_name }}" == "main" ]]; then | |
| MANUAL_LATEST="$IMAGE:manual-latest" | |
| echo "manual-latest=$MANUAL_LATEST" >> "$GITHUB_OUTPUT" | |
| TAGS="$TAGS"$'\n'"$MANUAL_LATEST" | |
| fi | |
| echo "tags<<EOF" >> "$GITHUB_OUTPUT" | |
| echo "$TAGS" >> "$GITHUB_OUTPUT" | |
| echo "EOF" >> "$GITHUB_OUTPUT" | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: useblacksmith/setup-docker-builder@v1 | |
| env: | |
| GITHUB_REPO_NAME: ${{ env.BLACKSMITH_DOCKER_CACHE_KEY }} | |
| - name: Build Docker Image and Publish | |
| uses: useblacksmith/build-push-action@v2 | |
| env: | |
| GITHUB_REPO_NAME: ${{ env.BLACKSMITH_DOCKER_CACHE_KEY }} | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| build-args: | | |
| PATHFINDER_FORCE_VERSION=${{ steps.generate_version.outputs.pathfinder_version }} | |
| tags: ${{ steps.tag.outputs.tags }} | |
| # Build a docker image unless this was triggered by a release. | |
| build-image: | |
| if: github.event_name == 'push' | |
| runs-on: pathfinder-large-ubuntu | |
| steps: | |
| - name: Determine Docker image metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: eqlabs/pathfinder | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate version | |
| id: generate_version | |
| run: | | |
| echo -n "pathfinder_version=" >> $GITHUB_OUTPUT | |
| git describe --tags --dirty >> $GITHUB_OUTPUT | |
| - name: Set up QEMU | |
| id: qemu | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| image: tonistiigi/binfmt:latest | |
| platforms: all | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| buildkitd-config-inline: | | |
| [worker.oci] | |
| max-parallelism = 4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| # Required for git security reasons. See https://github.com/rustyhorde/vergen/pull/126#issuecomment-1201088162 | |
| - name: Vergen git safe directory | |
| run: git config --global --add safe.directory /workspace | |
| - name: Build | |
| id: docker_build | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: | | |
| linux/amd64 | |
| linux/arm64 | |
| file: ./Dockerfile | |
| build-args: | | |
| PATHFINDER_FORCE_VERSION=${{ steps.generate_version.outputs.pathfinder_version }} | |
| builder: ${{ steps.buildx.outputs.name }} | |
| push: true | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tags: eqlabs/pathfinder:snapshot-${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # Add the release labels to the associated docker image. | |
| tag-release: | |
| if: github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Tag image with release name | |
| run: docker buildx imagetools create -t eqlabs/pathfinder:${{ github.event.release.tag_name }} eqlabs/pathfinder:snapshot-${{ github.sha }} | |
| # Only tag the image as 'latest' if its a release i.e. not a prerelease. | |
| - name: Tag image with 'latest' | |
| if: ${{ !github.event.release.prerelease }} | |
| run: docker buildx imagetools create -t eqlabs/pathfinder:latest eqlabs/pathfinder:snapshot-${{ github.sha }} |