Skip to content

Commit 4299a60

Browse files
committed
fix(ci): use relay SHA for image labels, drop metadata-action
The docker/metadata-action was generating org.opencontainers.image.revision from github.sha (the docker repo's commit), which overwrote the Dockerfile's LABEL that correctly had the relay SHA. cmlxc reads this label to know which relay commit to check out for testing -- with the wrong SHA, git fetch failed with "not our ref". Drop metadata-action entirely (we were overriding all its outputs anyway) and compute tags + labels in a single shell step: - image.revision now correctly contains the relay checkout's SHA - image.description includes the relay commit message on dispatch builds - Relay ref is passed to test-cmdeploy via --relay-ref, making the label purely informational rather than load-bearing for test orchestration docker-ci.yaml:87-145 unified metadata step replaces 3 separate steps docker-ci.yaml:50-51 build job outputs image_tag + relay_ref docker-ci.yaml:178 test-cmdeploy receives --relay-ref
1 parent b922cfc commit 4299a60

1 file changed

Lines changed: 46 additions & 38 deletions

File tree

.github/workflows/docker-ci.yaml

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ jobs:
4747
name: Build Docker image
4848
runs-on: ubuntu-latest
4949
outputs:
50-
image_tag: ${{ steps.short-tag.outputs.tag }}
50+
image_tag: ${{ steps.meta.outputs.tag }}
51+
relay_ref: ${{ steps.meta.outputs.relay_ref }}
5152
permissions:
5253
contents: read
5354
packages: write
@@ -83,58 +84,65 @@ jobs:
8384
username: ${{ github.actor }}
8485
password: ${{ secrets.GITHUB_TOKEN }}
8586

86-
- name: Extract metadata (tags, labels)
87+
- name: Compute build metadata
8788
id: meta
88-
uses: docker/metadata-action@v6
89-
with:
90-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
91-
tags: |
92-
# Tagged releases: v1.2.3 -> :1.2.3, :1.2, :latest
93-
type=semver,pattern={{version}}
94-
type=semver,pattern={{major}}.{{minor}}
95-
# Branch pushes: main -> :main, feature/foo -> :feature-foo
96-
type=ref,event=branch
97-
# Always include sha
98-
type=sha
99-
100-
- name: Resolve relay SHA and compute tags
101-
id: tags
10289
run: |
90+
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
10391
RELAY_REF="${{ steps.relay.outputs.ref }}"
104-
# Get the actual checked-out SHA (resolves branches/tags to commits)
92+
93+
# Relay SHA comes from the relay checkout at workspace root
10594
RELAY_SHA=$(git rev-parse HEAD)
10695
RELAY_SHA_SHORT="${RELAY_SHA:0:7}"
10796
BUILD_DATE=$(git log -1 --format=%cI)
97+
COMMIT_MSG=$(git log -1 --format=%s)
98+
10899
echo "relay_sha=${RELAY_SHA}" >> "$GITHUB_OUTPUT"
109100
echo "relay_sha_short=${RELAY_SHA_SHORT}" >> "$GITHUB_OUTPUT"
101+
echo "relay_ref=${RELAY_REF}" >> "$GITHUB_OUTPUT"
110102
echo "build_date=${BUILD_DATE}" >> "$GITHUB_OUTPUT"
103+
echo "tag=sha-${RELAY_SHA_SHORT}" >> "$GITHUB_OUTPUT"
111104
112-
TAGS="${{ steps.meta.outputs.tags }}"
113-
# Always add relay sha tag -- metadata-action's type=sha uses the
114-
# docker repo's commit, not the relay's.
115-
TAGS="${TAGS}"$'\n'"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${RELAY_SHA_SHORT}"
116-
if [ "${{ github.event_name }}" != "push" ] && \
117-
[ "${{ github.event_name }}" != "pull_request" ]; then
118-
# branch/tag: main -> :main, j4n/foo -> :j4n-foo
105+
# -- Tags --
106+
# Always: relay SHA tag
107+
TAGS="${IMAGE}:sha-${RELAY_SHA_SHORT}"
108+
if [ "${{ github.event_name }}" = "push" ] || \
109+
[ "${{ github.event_name }}" = "pull_request" ]; then
110+
# Docker-repo push/PR: add docker branch tag
111+
TAGS="${TAGS}"$'\n'"${IMAGE}:${{ github.ref_name }}"
112+
else
113+
# Dispatch: tags based on relay ref
119114
BRANCH_TAG=$(echo "${RELAY_REF}" | sed 's|/|-|g')
120-
TAGS="${TAGS}"$'\n'"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH_TAG}"
121-
# semver tags for release tags
115+
TAGS="${TAGS}"$'\n'"${IMAGE}:${BRANCH_TAG}"
122116
if [[ "${RELAY_REF}" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
123117
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
124118
MINOR="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
125-
TAGS="${TAGS}"$'\n'"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}"
126-
TAGS="${TAGS}"$'\n'"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${MINOR}"
127-
TAGS="${TAGS}"$'\n'"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
119+
TAGS="${TAGS}"$'\n'"${IMAGE}:${VERSION}"
120+
TAGS="${TAGS}"$'\n'"${IMAGE}:${MINOR}"
121+
TAGS="${TAGS}"$'\n'"${IMAGE}:latest"
128122
fi
129123
fi
130124
echo "tags<<EOF" >> "$GITHUB_OUTPUT"
131125
echo "${TAGS}" >> "$GITHUB_OUTPUT"
132126
echo "EOF" >> "$GITHUB_OUTPUT"
133127
134-
- name: Compute short tag for test job
135-
id: short-tag
136-
run: |
137-
echo "tag=sha-${{ steps.tags.outputs.relay_sha_short }}" >> "$GITHUB_OUTPUT"
128+
# -- Labels --
129+
# Use relay commit message as description on dispatch builds
130+
if [ "${{ github.event_name }}" = "repository_dispatch" ] || \
131+
[ "${{ github.event_name }}" = "workflow_dispatch" ]; then
132+
DESC="relay/${RELAY_REF}: ${COMMIT_MSG}"
133+
else
134+
DESC="Chatmail relay server - optimized email for Delta Chat"
135+
fi
136+
{
137+
echo "labels<<EOF"
138+
echo "org.opencontainers.image.title=chatmail-relay"
139+
echo "org.opencontainers.image.description=${DESC}"
140+
echo "org.opencontainers.image.revision=${RELAY_SHA}"
141+
echo "org.opencontainers.image.source=https://github.com/chatmail/relay"
142+
echo "org.opencontainers.image.created=${BUILD_DATE}"
143+
echo "com.chatmail.source.ref=${RELAY_REF}"
144+
echo "EOF"
145+
} >> "$GITHUB_OUTPUT"
138146
139147
- name: Copy .dockerignore to build context
140148
run: cp docker/.dockerignore .dockerignore
@@ -145,14 +153,14 @@ jobs:
145153
context: .
146154
file: docker/chatmail_relay.dockerfile
147155
push: ${{ github.event_name != 'pull_request' }}
148-
tags: ${{ steps.tags.outputs.tags }}
156+
tags: ${{ steps.meta.outputs.tags }}
149157
labels: ${{ steps.meta.outputs.labels }}
150158
cache-from: type=gha
151159
cache-to: type=gha,mode=max
152160
build-args: |
153-
GIT_HASH=${{ steps.tags.outputs.relay_sha }}
154-
SOURCE_REF=${{ steps.relay.outputs.ref }}
155-
BUILD_DATE=${{ steps.tags.outputs.build_date }}
161+
GIT_HASH=${{ steps.meta.outputs.relay_sha }}
162+
SOURCE_REF=${{ steps.meta.outputs.relay_ref }}
163+
BUILD_DATE=${{ steps.meta.outputs.build_date }}
156164
157165
test:
158166
name: Integration test
@@ -167,4 +175,4 @@ jobs:
167175
cmlxc init
168176
cmlxc docker pull --tag ${{ needs.build.outputs.image_tag }}
169177
cmlxc docker deploy dock0 --source ghcr:${{ needs.build.outputs.image_tag }}
170-
cmlxc test-cmdeploy dock0
178+
cmlxc test-cmdeploy dock0 --relay-ref ${{ needs.build.outputs.relay_ref }}

0 commit comments

Comments
 (0)