Skip to content

Commit b84a309

Browse files
committed
Validate Docker tags before build
1 parent c87d106 commit b84a309

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/docker.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,33 @@ jobs:
1919
with:
2020
username: ${{ secrets.DOCKER_HUB_USERNAME }}
2121
password: ${{ secrets.DOCKER_HUB_SECRET }}
22+
- name: Prepare image metadata
23+
id: prep
24+
run: |
25+
if [ -z "$DOCKER_USER" ]; then
26+
echo "::error::Secret DOCKER_HUB_USERNAME is not set." >&2
27+
exit 1
28+
fi
29+
if [ -z "$IMAGE_REPO" ]; then
30+
echo "::error::Variable REPO is not set." >&2
31+
exit 1
32+
fi
33+
if [ -z "$IMAGE_VERSION" ]; then
34+
echo "::error::Variable VERSION is not set." >&2
35+
exit 1
36+
fi
37+
38+
IMAGE_NAME="$DOCKER_USER/$IMAGE_REPO"
39+
echo "image=$IMAGE_NAME" >> "$GITHUB_OUTPUT"
40+
echo "version=$IMAGE_VERSION" >> "$GITHUB_OUTPUT"
41+
env:
42+
DOCKER_USER: ${{ secrets.DOCKER_HUB_USERNAME }}
43+
IMAGE_REPO: ${{ vars.REPO }}
44+
IMAGE_VERSION: ${{ vars.VERSION }}
2245
- name: Build and push
2346
uses: docker/build-push-action@v5
2447
with:
2548
context: .
2649
platforms: linux/amd64,linux/arm64
2750
push: true
28-
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.REPO }}:latest, ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.REPO }}:${{ vars.VERSION }}-BUILD${{ github.run_number }}
51+
tags: ${{ steps.prep.outputs.image }}:latest, ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.version }}-BUILD${{ github.run_number }}

0 commit comments

Comments
 (0)