diff --git a/.github/workflows/build_docker_on_release.yml b/.github/workflows/build_docker_on_release.yml index 879a702..f8adf32 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 }}/${{ secrets.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 }}/api:latest, ${{ secrets.DOCKERHUB_USERNAME }}/api:${{ 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'] }}