Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/update-mirror-digests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
echo "::error::Timeout after 30 minutes: ci-base digest did not change from existing mirror"
exit 1

- name: Resolve digests and update mirror.lock.yaml files
- name: Resolve digests and update mirror files
run: bash "${GITHUB_WORKSPACE}/dd-trace-java-docker-build/scripts/update-ci-image-digests.sh"
working-directory: images

Expand All @@ -82,7 +82,7 @@ jobs:
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add mirror.lock.yaml
git add mirror.yaml mirror.lock.yaml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious if adding of mirror.yaml should be conditional?
Or if file not changed, that will be a no-op effectively?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if the file has no changes, git add-ing it is effectively a no-op!

if git diff --cached --quiet; then
echo "No changes detected in mirror files; skipping commit."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
Expand Down
63 changes: 55 additions & 8 deletions scripts/update-ci-image-digests.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
#!/usr/bin/env bash
# update-ci-image-digests.sh update pinned ci-* image digests in mirror.lock.yaml in the DataDog/images repo.
# update-ci-image-digests.sh - add/update ci-* image mirror entries in the DataDog/images repo.
#
# This script is called in the update-mirror-digests Github workflow.
# It must be run from the root of DataDog/images and requires crane to be installed.

set -euo pipefail

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

# Verify all ci-* entries exist before updating
PREFIX="ci-"
insert_mirror_yaml_entry() {
local variant="$1" tag="ci-${variant}" amd64_only="false"

if [[ "${variant}" == "7" || "${variant}" == "ibm8" ]]; then
amd64_only="true"
fi

awk -v source_prefix="${SOURCE_PREFIX}" -v dest_repo="${DEST_REPO}" -v tag="${tag}" -v amd64_only="${amd64_only}" '
/^image_groups:$/ && !inserted {
print " - source: \"" source_prefix ":" tag "\""
print " dest:"
print " repo: \"" dest_repo "\""
print " tag: \"" tag "\""
print " replication_target: \"\""
print " platforms:"
print " - \"linux/amd64\""
if (amd64_only != "true") {
print " - \"linux/arm64\""
}
print " renovate:"
print " enabled: true"
inserted = 1
}
{ print }
END {
if (!inserted) {
print "missing top-level image_groups section in mirror.yaml" > "/dev/stderr"
exit 1
}
}
' mirror.yaml > mirror.yaml.tmp && mv mirror.yaml.tmp mirror.yaml
}

append_mirror_lock_entry() {
local tag="$1" digest="$2"

printf ' # renovate\n - source: %s:%s\n digest: %s\n' \
"${SOURCE_PREFIX}" "${tag}" "${digest}" >> mirror.lock.yaml
}

readonly PREFIX="ci-"
# shellcheck source=scripts/get-image-digests.sh
source "${SCRIPT_DIR}/get-image-digests.sh"

for variant in "${CI_VARIANTS[@]}"; do
if ! grep -qF "ghcr.io/datadog/dd-trace-java-docker-build:ci-${variant}" mirror.lock.yaml; then
echo "::error::Missing from mirror.lock.yaml: ci-${variant}" >&2
echo "Bootstrap ci-* entries manually before running this workflow." >&2
exit 1
tag="ci-${variant}"
source="${SOURCE_PREFIX}:${tag}"

if ! grep -qF "${source}" mirror.yaml; then
Comment thread
sarahchen6 marked this conversation as resolved.
insert_mirror_yaml_entry "${variant}"
echo "Added mirror.yaml entry: ${tag}"
fi

if ! grep -qF "${source}" mirror.lock.yaml; then
append_mirror_lock_entry "${tag}" "${DIGESTS[$variant]}"
echo "Added mirror.lock.yaml entry: ${tag}"
fi
done

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