Skip to content

Commit b191676

Browse files
authored
Update workflow to account for new entry (#171)
* Update workflow to account for new entry
1 parent 0e4a2a5 commit b191676

2 files changed

Lines changed: 57 additions & 10 deletions

File tree

.github/workflows/update-mirror-digests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
echo "::error::Timeout after 30 minutes: ci-base digest did not change from existing mirror"
7070
exit 1
7171
72-
- name: Resolve digests and update mirror.lock.yaml files
72+
- name: Resolve digests and update mirror files
7373
run: bash "${GITHUB_WORKSPACE}/dd-trace-java-docker-build/scripts/update-ci-image-digests.sh"
7474
working-directory: images
7575

@@ -82,7 +82,7 @@ jobs:
8282
run: |
8383
git config user.name "github-actions[bot]"
8484
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
85-
git add mirror.lock.yaml
85+
git add mirror.yaml mirror.lock.yaml
8686
if git diff --cached --quiet; then
8787
echo "No changes detected in mirror files; skipping commit."
8888
echo "has_changes=false" >> "$GITHUB_OUTPUT"

scripts/update-ci-image-digests.sh

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,74 @@
11
#!/usr/bin/env bash
2-
# update-ci-image-digests.sh update pinned ci-* image digests in mirror.lock.yaml in the DataDog/images repo.
2+
# update-ci-image-digests.sh - add/update ci-* image mirror entries in the DataDog/images repo.
33
#
44
# This script is called in the update-mirror-digests Github workflow.
55
# It must be run from the root of DataDog/images and requires crane to be installed.
66

77
set -euo pipefail
88

99
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
readonly SOURCE_PREFIX="ghcr.io/datadog/dd-trace-java-docker-build"
11+
readonly DEST_REPO="dd-trace-java-docker-build"
1012

11-
# Verify all ci-* entries exist before updating
12-
PREFIX="ci-"
13+
insert_mirror_yaml_entry() {
14+
local variant="$1" tag="ci-${variant}" amd64_only="false"
15+
16+
if [[ "${variant}" == "7" || "${variant}" == "ibm8" ]]; then
17+
amd64_only="true"
18+
fi
19+
20+
awk -v source_prefix="${SOURCE_PREFIX}" -v dest_repo="${DEST_REPO}" -v tag="${tag}" -v amd64_only="${amd64_only}" '
21+
/^image_groups:$/ && !inserted {
22+
print " - source: \"" source_prefix ":" tag "\""
23+
print " dest:"
24+
print " repo: \"" dest_repo "\""
25+
print " tag: \"" tag "\""
26+
print " replication_target: \"\""
27+
print " platforms:"
28+
print " - \"linux/amd64\""
29+
if (amd64_only != "true") {
30+
print " - \"linux/arm64\""
31+
}
32+
print " renovate:"
33+
print " enabled: true"
34+
inserted = 1
35+
}
36+
{ print }
37+
END {
38+
if (!inserted) {
39+
print "missing top-level image_groups section in mirror.yaml" > "/dev/stderr"
40+
exit 1
41+
}
42+
}
43+
' mirror.yaml > mirror.yaml.tmp && mv mirror.yaml.tmp mirror.yaml
44+
}
45+
46+
append_mirror_lock_entry() {
47+
local tag="$1" digest="$2"
48+
49+
printf ' # renovate\n - source: %s:%s\n digest: %s\n' \
50+
"${SOURCE_PREFIX}" "${tag}" "${digest}" >> mirror.lock.yaml
51+
}
52+
53+
readonly PREFIX="ci-"
1354
# shellcheck source=scripts/get-image-digests.sh
1455
source "${SCRIPT_DIR}/get-image-digests.sh"
1556

1657
for variant in "${CI_VARIANTS[@]}"; do
17-
if ! grep -qF "ghcr.io/datadog/dd-trace-java-docker-build:ci-${variant}" mirror.lock.yaml; then
18-
echo "::error::Missing from mirror.lock.yaml: ci-${variant}" >&2
19-
echo "Bootstrap ci-* entries manually before running this workflow." >&2
20-
exit 1
58+
tag="ci-${variant}"
59+
source="${SOURCE_PREFIX}:${tag}"
60+
61+
if ! grep -qF "${source}" mirror.yaml; then
62+
insert_mirror_yaml_entry "${variant}"
63+
echo "Added mirror.yaml entry: ${tag}"
64+
fi
65+
66+
if ! grep -qF "${source}" mirror.lock.yaml; then
67+
append_mirror_lock_entry "${tag}" "${DIGESTS[$variant]}"
68+
echo "Added mirror.lock.yaml entry: ${tag}"
2169
fi
2270
done
2371

24-
# Update existing digest entries in mirror.lock.yaml in-place
2572
for variant in "${CI_VARIANTS[@]}"; do
2673
tag="ci-${variant}"
2774
update_digest "${tag}" "${DIGESTS[$variant]}" mirror.lock.yaml

0 commit comments

Comments
 (0)