From 09ed2090db0bae415a38681f3dde021bc754198a Mon Sep 17 00:00:00 2001 From: Alejandro Villar Date: Mon, 26 Aug 2024 18:10:25 +0200 Subject: [PATCH] Multiarch Docker image --- .github/workflows/builld-docker.yml | 80 +++++++++++++++++++++++++++-- README.md | 4 +- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/.github/workflows/builld-docker.yml b/.github/workflows/builld-docker.yml index c75b246..7143af5 100644 --- a/.github/workflows/builld-docker.yml +++ b/.github/workflows/builld-docker.yml @@ -9,18 +9,31 @@ concurrency: group: docker cancel-in-progress: true +env: + REGISTRY_IMAGE: ghcr.io/ogcincubator/chek-data-completeness + jobs: - docker: + build: runs-on: ubuntu-latest permissions: contents: read packages: write + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Docker Buildx + - name: Set up Docker ºBuildx uses: docker/setup-buildx-action@v3 - name: Log in to the Container registry @@ -35,18 +48,75 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/ogcincubator/chek-data-completeness + images: ${{ env.REGISTRY_IMAGE }} tags: | type=raw,value=latest,enable={{is_default_branch}} type=ref,event=branch type=ref,event=tag + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push Docker image uses: docker/build-push-action@v6 with: + platforms: ${{ matrix.platform }} context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + + - 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-${{ 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-* + merge-multiple: true + + - 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 }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + if: ${{ github.event_name != 'pull_request' }} + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} diff --git a/README.md b/README.md index 7fe7134..4ddcec9 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ You may also create a `.env` file with the [configuration](#configuration) inste val3dity and CityGML tools come prepackaged in the Docker image, so no dependencies are required. ``` -docker run -p 8080:8080 ghcr.io/ogcincubator/chek-data-completeness +docker run --pull=always -p 8080:8080 ghcr.io/ogcincubator/chek-data-completeness ``` The service will be available at https://localhost:8080. @@ -52,7 +52,7 @@ If you need to serve the application from a path other than `/`, you can pass it variable: ``` -docker run -p 8080:8080 -e ROOT_PATH=/my-subpath/ ghcr.io/ogcincubator/chek-data-completeness +docker run --pull=always -p 8080:8080 -e ROOT_PATH=/my-subpath/ ghcr.io/ogcincubator/chek-data-completeness ``` ## Configuration