From 8e68f11b0e2b895940042cfa2fc315ef48b294ad Mon Sep 17 00:00:00 2001 From: Eike Ahmels Date: Sat, 30 Oct 2021 13:21:41 +0200 Subject: [PATCH] NEW: multi arch docker build --- .github/workflows/docker-publish-api.yml | 86 +++++++++++++++++------- .github/workflows/docker-publish.yml | 2 +- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/.github/workflows/docker-publish-api.yml b/.github/workflows/docker-publish-api.yml index f0462ad..785db8f 100644 --- a/.github/workflows/docker-publish-api.yml +++ b/.github/workflows/docker-publish-api.yml @@ -8,7 +8,7 @@ name: Build api image on: push: # Publish semver tags as releases. - tags: [ 'v*.*.*' ] + tags: [ 'api-v*.*.*-' ] env: # Use docker.io for Docker Hub if empty @@ -26,6 +26,33 @@ jobs: packages: write steps: + - name: Prepare + id: prepare + run: | + DOCKER_IMAGE=mainsail/mainsail-docker-api + DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x + VERSION=edge + + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/v} + fi + if [ "${{ github.event_name }}" = "schedule" ]; then + VERSION=nightly + fi + + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" + fi + + echo ::set-output name=docker_image::${DOCKER_IMAGE} + echo ::set-output name=version::${VERSION} + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ + --build-arg VERSION=${VERSION} \ + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ + --build-arg VCS_REF=${GITHUB_SHA::8} \ + ${TAGS} --file ./api/Dockerfile ./api + - name: Checkout repository uses: actions/checkout@v2 @@ -37,30 +64,41 @@ jobs: # Login against a Docker registry except on PR # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + #- name: Log into registry ${{ env.REGISTRY }} + # if: github.event_name != 'pull_request' + # uses: docker/login-action@v1 + # with: + # registry: ${{ env.REGISTRY }} + # username: ${{ github.actor }} + # password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 # Extract metadata (tags, labels) for Docker # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 - with: - images: | - mainsail/mainsail-docker-api - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-api + #- name: Extract Docker metadata + # id: meta + # uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + # with: + # images: | + # mainsail/mainsail-docker-api + # ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-api - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: api/ - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + - + name: Docker Buildx (build) + run: | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} + + - name: Docker Buildx (push) + if: success() && github.event_name != 'pull_request' + run: | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} + + - name: Inspect image + if: always() && github.event_name != 'pull_request' + run: | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d50fc91..591fc43 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -8,7 +8,7 @@ name: Build web image on: push: # Publish semver tags as releases. - tags: [ 'v*.*.*' ] + tags: [ 'web-v*.*.*' ] env: # Use docker.io for Docker Hub if empty