From c296b5821eb02bf721157651cd49783d6f14129b Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Fri, 24 Mar 2023 17:24:00 +0100 Subject: [PATCH] Update tagged build as well --- .github/workflows/docker_tagged.yml | 79 ++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker_tagged.yml b/.github/workflows/docker_tagged.yml index 7cc0f25..fe35da1 100644 --- a/.github/workflows/docker_tagged.yml +++ b/.github/workflows/docker_tagged.yml @@ -9,33 +9,63 @@ jobs: main: runs-on: ubuntu-latest steps: - - - name: Login to DockerHub - uses: docker/login-action@v2 + - name: Checkout + uses: actions/checkout@v3 + + - name: Calculate Docker image tags + id: tags + env: + DOCKER_IMAGES: "ghcr.io/philips-labs/siderite" + run: | + case $GITHUB_REF in + refs/tags/*) VERSION=${GITHUB_REF#refs/tags/};; + refs/heads/*) VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g');; + refs/pull/*) VERSION=pr-${{ github.event.number }};; + *) VERSION=sha-${GITHUB_SHA::8};; + esac + + TAGS=() + for image in $DOCKER_IMAGES; do + TAGS+=("${image}:${VERSION}") + + if [[ "${{ github.event.repository.default_branch }}" == "$VERSION" ]]; then + TAGS+=("${image}:latest") + fi + done + + echo ::set-output name=version::${VERSION} + echo ::set-output name=tags::$(IFS=,; echo "${TAGS[*]}") + echo ::set-output name=commit_hash::${GITHUB_SHA::8} + echo ::set-output name=build_date::$(git show -s --format=%cI) + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Login to HSDP Docker registry - uses: docker/login-action@v2 + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 with: - registry: docker.na1.hsdp.io - username: ${{ secrets.HSDP_DOCKER_USERNAME }} - password: ${{ secrets.HSDP_DOCKER_PASSWORD }} - - - name: Checkout repository - uses: actions/checkout@v3 + install: true + version: latest + # TODO: Remove driver-opts once fix is released docker/buildx#386 + driver-opts: image=moby/buildkit:master + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - name: Set output + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + if: github.event_name == 'push' + + - name: Git information id: vars + shell: bash run: | - echo ::set-output name=tag::${GITHUB_REF#refs/*/} - echo ::set-output name=sha_short::$(git rev-parse --short HEAD) + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - - name: Build and push + name: Build and push alpine id: docker_build uses: docker/build-push-action@v4 with: @@ -45,7 +75,10 @@ jobs: GIT_COMMIT=${{ steps.vars.outputs.sha_short }} platforms: linux/amd64 push: true - tags: philipslabs/siderite:${{ steps.vars.outputs.tag }},docker.na1.hsdp.io/philipslabs/siderite:${{ steps.vars.outputs.tag }} + tags: ${{ steps.tags.outputs.tags }} + - + name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} - name: Build and push debian id: docker_build_debian @@ -57,7 +90,7 @@ jobs: GIT_COMMIT=${{ steps.vars.outputs.sha_short }} platforms: linux/amd64 push: true - tags: philipslabs/siderite:debian-${{ steps.vars.outputs.tag }},docker.na1.hsdp.io/philipslabs/siderite:debian-${{ steps.vars.outputs.tag }} + tags: ${{ steps.tags.outputs.tags }}-debian - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }}