Skip to content

Commit b6a1ffe

Browse files
committed
ci: more refactoring
1 parent b319c05 commit b6a1ffe

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

.github/workflows/wc-build-push-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
packages: write
3131
pull-requests: write
3232
with:
33-
devcontainer-metadata: .devcontainer/${{ matrix.flavor }}/devcontainer-metadata.json
33+
devcontainer-metadata-file: .devcontainer/${{ matrix.flavor }}/devcontainer-metadata.json
3434
dockerfile: .devcontainer/${{ matrix.flavor }}/Dockerfile
3535
image-name: ${{ github.repository }}-${{ matrix.flavor }}
3636

.github/workflows/wc-build-push.yml

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
description: "Name of the Docker image to build, without registry or tag. E.g. 'my-image' or 'my-org/my-image'"
1313
required: true
1414
type: string
15-
devcontainer-metadata:
15+
devcontainer-metadata-file:
1616
description: "Path to a JSON file containing devcontainer metadata to add as a label to the built image"
1717
required: false
1818
type: string
@@ -75,6 +75,8 @@ jobs:
7575
with:
7676
persist-credentials: false
7777
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
78+
with:
79+
cache-binary: false
7880
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
7981
env:
8082
USERNAME: ${{ secrets.DOCKER_REGISTRY_USERNAME || github.actor }}
@@ -93,16 +95,16 @@ jobs:
9395
run: |
9496
set -Eeuo pipefail
9597
96-
if [ -z "${DEVCONTAINER_METADATA:-}" ] || [ ! -f "${DEVCONTAINER_METADATA}" ]; then
97-
echo "devcontainer-metadata input not set or file does not exist, skipping devcontainer.metadata label"
98-
echo "metadata=" >> "$GITHUB_OUTPUT"
98+
if [ -z "${DEVCONTAINER_METADATA_FILE:-}" ] || [ ! -f "${DEVCONTAINER_METADATA_FILE}" ]; then
99+
echo "devcontainer-metadata-file input not set or file does not exist, skipping devcontainer.metadata label"
100+
echo "label=" >> "$GITHUB_OUTPUT"
99101
exit 0
100102
fi
101103
102104
# the sed expression is a workaround for quotes being eaten in arrays (e.g. ["x", "y", "z"] -> ["x",y,"z"])
103-
echo "metadata=devcontainer.metadata=$(jq -cj '[.]' "${DEVCONTAINER_METADATA}" | sed 's/,"/, "/g')" >> "$GITHUB_OUTPUT"
105+
echo "label=devcontainer.metadata=$(jq -cj '[.]' "${DEVCONTAINER_METADATA_FILE}" | sed 's/,"/, "/g')" >> "$GITHUB_OUTPUT"
104106
env:
105-
DEVCONTAINER_METADATA: ${{ inputs.devcontainer-metadata }}
107+
DEVCONTAINER_METADATA_FILE: ${{ inputs.devcontainer-metadata-file }}
106108
id: devcontainer-metadata
107109
- run: echo "git-commit-epoch=$(git log -1 --pretty=%ct)" >> "$GITHUB_OUTPUT"
108110
id: devcontainer-epoch
@@ -129,7 +131,6 @@ jobs:
129131
touch "${RUNNER_TEMP}/digests/${DIGEST#sha256:}"
130132
env:
131133
DIGEST: ${{ steps.build-and-push.outputs.digest }}
132-
RUNNER_TEMP: ${{ runner.temp }}
133134
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
134135
with:
135136
name: digests-${{ needs.sanitize-image-name.outputs.image-basename }}-${{ steps.devcontainer-arch.outputs.arch }}
@@ -167,6 +168,8 @@ jobs:
167168
pattern: digests-${{ needs.sanitize-image-name.outputs.image-basename }}-*
168169
merge-multiple: true
169170
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
171+
with:
172+
cache-binary: false
170173
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
171174
env:
172175
USERNAME: ${{ secrets.DOCKER_REGISTRY_USERNAME || github.actor }}
@@ -179,7 +182,6 @@ jobs:
179182
id: metadata
180183
env:
181184
DOCKER_METADATA_ANNOTATIONS_LEVELS: index
182-
DOCKER_METADATA_SET_OUTPUT_ENV: false
183185
with:
184186
images: ${{ needs.sanitize-image-name.outputs.fully-qualified-image-name }}
185187
# Generate Docker tags based on the following events/attributes.
@@ -197,38 +199,16 @@ jobs:
197199
run: |
198200
set -Eeuo pipefail
199201
200-
CMD=(docker buildx imagetools create)
201-
202-
# Build tag and annotation lists from metadata action output
203-
mapfile -t TAGS < <(jq -r '.tags[]? // empty' <<<"${METADATA_JSON}") || true
204-
mapfile -t ANNOTATIONS < <(jq -r '.annotations[]? // empty' <<<"${METADATA_JSON}") || true
205-
206-
for ann in "${ANNOTATIONS[@]:-}"; do
207-
[ -n "${ann}" ] && CMD+=( --annotation "${ann}" )
202+
readarray -t lines <<< "$DOCKER_METADATA_OUTPUT_ANNOTATIONS"
203+
annotations=()
204+
for line in "${lines[@]}"; do
205+
annotations+=(--annotation "$line")
208206
done
209-
for tag in "${TAGS[@]:-}"; do
210-
[ -n "${tag}" ] && CMD+=( --tag "${tag}" )
211-
done
212-
213-
# Each file in the working directory represents a digest (either named sha256:<hash> or the 64-char digest itself)
214-
for f in *; do
215-
[ -f "$f" ] || continue
216-
digest=""
217-
if [[ "$f" == sha256:* ]]; then
218-
digest="${f#sha256:}"
219-
elif [[ ${#f} -eq 64 && "$f" =~ ^[a-f0-9]{64}$ ]]; then
220-
digest="$f"
221-
else
222-
continue
223-
fi
224-
CMD+=( "${CONTAINER}@sha256:${digest}" )
225-
done
226-
227-
echo "Creating manifest list with command:" >&2
228-
printf ' %q' "${CMD[@]}" >&2; echo >&2
229207
230-
# Execute the command
231-
"${CMD[@]}"
208+
docker buildx imagetools create \
209+
"${annotations[@]}" \
210+
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${METADATA_JSON}") \
211+
$(printf "${CONTAINER}@sha256:%s " *)
232212
env:
233213
CONTAINER: ${{ needs.sanitize-image-name.outputs.fully-qualified-image-name }}
234214
METADATA_JSON: ${{ steps.metadata.outputs.json }}

0 commit comments

Comments
 (0)