|
1 | 1 | #!/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. |
3 | 3 | # |
4 | 4 | # This script is called in the update-mirror-digests Github workflow. |
5 | 5 | # It must be run from the root of DataDog/images and requires crane to be installed. |
6 | 6 |
|
7 | 7 | set -euo pipefail |
8 | 8 |
|
9 | 9 | 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" |
10 | 12 |
|
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-" |
13 | 54 | # shellcheck source=scripts/get-image-digests.sh |
14 | 55 | source "${SCRIPT_DIR}/get-image-digests.sh" |
15 | 56 |
|
16 | 57 | 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}" |
21 | 69 | fi |
22 | 70 | done |
23 | 71 |
|
24 | | -# Update existing digest entries in mirror.lock.yaml in-place |
25 | 72 | for variant in "${CI_VARIANTS[@]}"; do |
26 | 73 | tag="ci-${variant}" |
27 | 74 | update_digest "${tag}" "${DIGESTS[$variant]}" mirror.lock.yaml |
|
0 commit comments