Skip to content

Commit f1c83d6

Browse files
authored
[Devcontainer]: Sanitize dynamic Docker image tag in workflow (#59)
1 parent f1fa329 commit f1c83d6

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/devcontainer.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ concurrency:
1616
permissions:
1717
contents: read
1818

19-
env:
20-
image_tag: devcontainer:${{ github.head_ref || github.run_id }}
21-
2219
jobs:
2320
build:
2421
name: Build
@@ -43,11 +40,23 @@ jobs:
4340
dockerfile: .devcontainer/ubuntu-24.04/Dockerfile
4441

4542
- name: Set up Docker Buildx
46-
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
43+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
44+
45+
- name: Prepare image tag
46+
shell: bash
47+
run: |
48+
RAW_TAG="${GITHUB_HEAD_REF:-$GITHUB_RUN_ID}"
49+
SAFE_TAG=$(echo "$RAW_TAG" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_.-]/-/g')
50+
if ! [[ "$SAFE_TAG" =~ ^[a-z0-9_] ]]; then SAFE_TAG="x-$SAFE_TAG"; fi
51+
SAFE_TAG="${SAFE_TAG:0:128}"
52+
echo "image_tag=devcontainer:${SAFE_TAG}" >> "$GITHUB_ENV"
4753
4854
- name: Build Docker image
4955
run: |
50-
docker buildx build .devcontainer/ubuntu-24.04/ --tag "${{ env.image_tag }}" --label "runnumber=${{ github.run_id }}" --load
56+
docker buildx build .devcontainer/ubuntu-24.04/ \
57+
--tag "${{ env.image_tag }}" \
58+
--label "runnumber=${{ github.run_id }}" \
59+
--load
5160
5261
- uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 # v3
5362
env:

0 commit comments

Comments
 (0)