Skip to content

Commit 3cd85ea

Browse files
committed
Tidy up logic yet again
1 parent 1881538 commit 3cd85ea

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

.github/workflows/docker.yaml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,57 @@ jobs:
4949
with:
5050
authToken: '${{ secrets.CACHIX_CARDANO_SCALING_AUTH_TOKEN }}'
5151

52-
- name: 🔨 Build image using nix
52+
- name: 🔨 🏷️ Build and tag images
5353
run: |
54+
5455
IMAGE_NAME=ghcr.io/${{github.repository_owner}}/${{matrix.target}}
5556
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
5657
nix build .#docker-${{ matrix.target }}
5758
docker load < result
5859
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}}
6170
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.
6473
BUILDING_TAG=${{github.ref_type == 'tag'}}
65-
VERSION_NAME=unstable
6674
[[ ${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
6882
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.
7090
echo "FROM ${{matrix.target}}" | docker build \
7191
--label org.opencontainers.image.source=https://github.com/cardano-scaling/hydra \
7292
--label org.opencontainers.image.licenses=Apache-2.0 \
7393
--label org.opencontainers.image.created=$(date -Is) \
7494
--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} -
8597
8698
# Also tag with ref name when manually dispatched
8799
[[ ${{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}}
89101
90-
docker inspect ${IMAGE_NAME}
102+
docker inspect ${IMAGE_NAME}:${VERSION_NAME}
91103
docker images
92104
93105
- name: 📤 Push to registry

0 commit comments

Comments
 (0)