From 9555ae63fb3893f22ac6d465875c692575b07864 Mon Sep 17 00:00:00 2001 From: Sebastian Urchs Date: Tue, 13 Aug 2024 15:42:26 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'.github/workfl?= =?UTF-8?q?ows/build=5Fdocker=5Fon=5Frelease.yml'=20with=20remote=20'templ?= =?UTF-8?q?ate=5Fworkflows/auto=5Frelease/build=5Fdocker=5Fon=5Frelease.ym?= =?UTF-8?q?l'=20(#252)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: surchs --- .github/workflows/build_docker_on_release.yml | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docker_on_release.yml b/.github/workflows/build_docker_on_release.yml index 52863e1..cc3144f 100644 --- a/.github/workflows/build_docker_on_release.yml +++ b/.github/workflows/build_docker_on_release.yml @@ -11,6 +11,27 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - + # The release event is a superset of the push tag event, + # so we expect two tags to be generated by docker/metadata-action + # based on the behaviour for the type=semver,pattern=... tag type: + # 1. a semver tag vX.Y.Z (from the release Git tag; this is what will be used as the image version in the generated label) + # 2. latest (as type=semver,pattern=... is part of the latest tag handling) + # References: + # - https://github.com/docker/metadata-action?tab=readme-ov-file#typesemver + # - https://github.com/docker/metadata-action?tab=readme-ov-file#latest-tag + # - https://github.com/docker/metadata-action/issues/103 + # - https://github.com/docker/metadata-action/issues/168 + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # TODO: Repos with this wf must have DOCKERHUB_REPO set in the repository variables + images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_REPO }} + # NOTE: This input is probably not necessary as the action should generate the appropriate tags + # based on the default type=ref,event=tag, but we define an explicit pattern here for clarity + tags: | + type=semver,pattern={{raw}} - name: Login to Docker Hub uses: docker/login-action@v3 @@ -27,4 +48,10 @@ jobs: context: . file: ./Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/query_tool:latest, ${{ secrets.DOCKERHUB_USERNAME }}/query_tool:${{ github.event.release.tag_name }} + tags: ${{ steps.meta.outputs.tags }} + # Select a subset of labels to apply from https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys, + # following https://github.com/docker/metadata-action/issues/303 + labels: | + org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.source'] }} + org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} + org.opencontainers.image.version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}