🚀🐳 Publish images to Docker Hub #18
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: 🚀🐳 Publish images to Docker Hub | |
| on: | |
| workflow_dispatch: | |
| inputs: &inputs | |
| base: | |
| description: Branch/tag/commit to publish from | |
| type: string | |
| default: master | |
| tag: | |
| type: string | |
| description: The tag to use for the docker image (Note that you should probably add a '-python' suffix if publishing the python version) | |
| required: true | |
| dry_run: | |
| description: If selected will not publish to Docker Hub | |
| type: boolean | |
| default: false | |
| python: | |
| type: string | |
| description: If set, will build the python image using this as the tag for the base python image, e.g. '3.14.2-slim-trixie' | |
| workflow_call: | |
| inputs: *inputs | |
| permissions: | |
| contents: read | |
| env: | |
| REGISTRY_IMAGE: pometry/raphtory | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| platform: | |
| - linux/amd64 | |
| - linux/arm64 | |
| steps: | |
| - name: Print input | |
| run: echo '${{ toJSON(inputs) }}' | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.base }} | |
| - name: Read rust version | |
| run: echo "RUST_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].rust_version')" >> $GITHUB_ENV | |
| # maybe this can be merged into the one below | |
| - name: Prepare | |
| run: | | |
| platform=${{ matrix.platform }} | |
| echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
| - name: Set dockerfile path and cache image | |
| run: | | |
| if [ -n "${{ inputs.python }}" ]; then | |
| echo "Building Python image" | |
| echo "DOCKERFILE_PATH=python.Dockerfile" >> $GITHUB_ENV | |
| echo "CACHE_IMAGE=${{ env.REGISTRY_IMAGE }}:buildcache-python-${{ env.PLATFORM_PAIR }}" >> $GITHUB_ENV | |
| else | |
| echo "Building Rust image" | |
| echo "DOCKERFILE_PATH=Dockerfile" >> $GITHUB_ENV | |
| echo "CACHE_IMAGE=${{ env.REGISTRY_IMAGE }}:buildcache-rust-${{ env.PLATFORM_PAIR }}" >> $GITHUB_ENV | |
| fi | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY_IMAGE }} | |
| tags: ${{ inputs.tag }} | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| build-args: | | |
| RUST_VERSION=${{ env.RUST_VERSION }} | |
| BASE_PYTHON_IMAGE_TAG=${{ inputs.python }} | |
| file: ${{ env.DOCKERFILE_PATH }} | |
| platforms: ${{ matrix.platform }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true | |
| cache-from: type=registry,ref=${{ env.CACHE_IMAGE }} | |
| cache-to: type=registry,ref=${{ env.CACHE_IMAGE }},mode=max | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ inputs.python }}-${{ env.PLATFORM_PAIR }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: /tmp/digests | |
| pattern: digests-${{ inputs.python }}-* | |
| merge-multiple: true | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY_IMAGE }} | |
| tags: ${{ inputs.tag }} | |
| - name: Create manifest list and push | |
| if: ${{ !inputs.dry_run }} | |
| working-directory: /tmp/digests | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) | |
| - name: Inspect image | |
| if: ${{ !inputs.dry_run }} | |
| run: | | |
| docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |