@@ -49,45 +49,57 @@ jobs:
49
49
with :
50
50
authToken : ' ${{ secrets.CACHIX_CARDANO_SCALING_AUTH_TOKEN }}'
51
51
52
- - name : 🔨 Build image using nix
52
+ - name : 🔨 🏷️ Build and tag images
53
53
run : |
54
+
54
55
IMAGE_NAME=ghcr.io/${{github.repository_owner}}/${{matrix.target}}
55
56
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
56
57
nix build .#docker-${{ matrix.target }}
57
58
docker load < result
58
59
59
- - name : 🏷️ Tag images
60
- run : |
60
+ # Compute tags. We want the following behaviour:
61
+ #
62
+ # 1. Building on tag: image tagged `tag`
63
+ # 2. Building on release: image tagged `release`
64
+ # 3. Building on master: image tagged `unstable`.
65
+
66
+ # Let's default to 'unstable'.
67
+ IMAGE_LABEL=unstable
68
+ # And the version as the git commit.
69
+ VERSION=${{github.sha}}
61
70
62
- # Determine whether we are building a tag and if yes, set a
63
- # VERSION_NAME, if not, use `unstable` as the version name .
71
+ # Determine whether we are building a tag and if yes, set the label
72
+ # name to be the tag name, and the version to be the tag .
64
73
BUILDING_TAG=${{github.ref_type == 'tag'}}
65
- VERSION_NAME=unstable
66
74
[[ ${BUILDING_TAG} = true ]] && \
67
- VERSION_NAME=${{github.ref_name}}
75
+ IMAGE_LABEL=${{github.ref_name}} && \
76
+ VERSION=${{github.ref_name}}
77
+
78
+ # If we're running on the release branch, tag it as `latest`,
79
+ # and leave the version as the git commit.
80
+ [[ ${GITHUB_REF_NAME} = "release" ]] && \
81
+ IMAGE_LABEL=latest
68
82
69
- # Use 'FROM' instruction to use docker build with --label
83
+ # If we're running on master, tag it as "unstable" and
84
+ # and again leave the version as the git commit.
85
+ [[ ${GITHUB_REF_NAME} = "master" ]] && \
86
+ IMAGE_LABEL=unstable
87
+
88
+ # Use 'FROM' instruction to use docker build with --label, as
89
+ # well as setting the tag directly.
70
90
echo "FROM ${{matrix.target}}" | docker build \
71
91
--label org.opencontainers.image.source=https://github.com/cardano-scaling/hydra \
72
92
--label org.opencontainers.image.licenses=Apache-2.0 \
73
93
--label org.opencontainers.image.created=$(date -Is) \
74
94
--label org.opencontainers.image.revision=${{github.sha}} \
75
- --label org.opencontainers.image.version=${VERSION_NAME} \
76
- --tag ${IMAGE_NAME}:${VERSION_NAME} -
77
-
78
- # If we're running on the release branch, tag it as `latest`
79
- [[ ${GITHUB_REF_NAME} = "release" ]] && \
80
- docker tag ${IMAGE_NAME} ${IMAGE_NAME}:latest
81
-
82
- # Also tag with version if we are building a tag
83
- [[ ${BUILDING_TAG} = true && ${{matrix.target}} != "hydraw" ]] && \
84
- docker tag ${IMAGE_NAME} ${IMAGE_NAME}:${VERSION_NAME}
95
+ --label org.opencontainers.image.version=${VERSION} \
96
+ --tag ${IMAGE_NAME}:${IMAGE_LABEL} -
85
97
86
98
# Also tag with ref name when manually dispatched
87
99
[[ ${{github.event_name == 'workflow_dispatch'}} = true ]] && \
88
- docker tag ${IMAGE_NAME} ${IMAGE_NAME}:workflow_dispatch-${{github.event.inputs.ref_name}}
100
+ docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:workflow_dispatch-${{github.event.inputs.ref_name}}
89
101
90
- docker inspect ${IMAGE_NAME}
102
+ docker inspect ${IMAGE_NAME}:${VERSION_NAME}
91
103
docker images
92
104
93
105
- name : 📤 Push to registry
0 commit comments