Skip to content

Commit fc7f4b7

Browse files
committed
fix WPB-27900: add create-build-entry to nix path
1 parent 8e02f36 commit fc7f4b7

4 files changed

Lines changed: 113 additions & 31 deletions

File tree

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ rec {
6969
list-helm-containers
7070
mirror-apt-jammy
7171
generate-gpg1-key
72-
#create-build-entry
72+
create-build-entry
7373
# Linting
7474
shellcheck
7575

nix/overlay.nix

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ super: {
7373
wrapProgram $out/bin/list-helm-containers --prefix PATH : '${super.lib.makeBinPath [ self.kubernetes-helm ]}'
7474
'';
7575

76-
# create-build-entry = super.runCommandNoCC "create-build-entry"
77-
# {
78-
# nativeBuildInputs = [ super.makeWrapper ];
79-
# }
80-
# ''
81-
# install -Dm755 ${./scripts/create-build-entry.sh} $out/bin/create-build-entry
82-
# wrapProgram $out/bin/create-build-entry --prefix PATH : '${super.lib.makeBinPath (with self; [ bash jq ])}'
83-
# '';
76+
create-build-entry = super.runCommandNoCC "create-build-entry"
77+
{
78+
nativeBuildInputs = [ super.makeWrapper ];
79+
}
80+
''
81+
install -Dm755 ${./scripts/create-build-entry.sh} $out/bin/create-build-entry
82+
wrapProgram $out/bin/create-build-entry --prefix PATH : '${super.lib.makeBinPath (with self; [ bash jq ])}'
83+
'';
8484

8585
}

nix/scripts/create-build-entry.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -eou pipefail
3+
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <docker-image-with-tag> <directory>"
6+
exit 1
7+
fi
8+
9+
IMAGE_WITH_TAG=$1
10+
DIRECTORY=$2
11+
12+
IMAGE=$(echo "$IMAGE_WITH_TAG" | cut -d':' -f1)
13+
TAG=$(echo "$IMAGE_WITH_TAG" | cut -d':' -f2)
14+
15+
JSON_FILE="$DIRECTORY/images.json"
16+
17+
if [ ! -d "$DIRECTORY" ]; then
18+
mkdir -p "$DIRECTORY"
19+
fi
20+
21+
append_image_entry() {
22+
local image=$1
23+
local tag=$2
24+
local json_file=$3
25+
26+
if [ -f "$json_file" ]; then
27+
existing_content=$(jq '.' "$json_file")
28+
29+
new_entry=$(jq -n --arg image "$image" --arg tag "$tag" '{$image: $tag}')
30+
updated_content=$(echo "$existing_content" | jq --argjson new_entry "$new_entry" '. += [$new_entry]')
31+
else
32+
updated_content=$(jq -n --arg image "$image" --arg tag "$tag" '[{$image: $tag}]')
33+
fi
34+
35+
echo "$updated_content" | jq '.' > "$json_file"
36+
}
37+
38+
append_image_entry "$IMAGE" "$TAG" "$JSON_FILE"

nix/scripts/create-container-dump.sh

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,77 @@ if [[ ! $# -eq 1 ]]; then
88
exit 1
99
fi
1010

11+
export HTTP_TIMEOUT=600 # Timeout in seconds (default is typically 90)
12+
export REGISTRY_TIMEOUT=600 # Registry specific timeout
13+
14+
output_dir=$1
1115
mkdir -p $1
16+
1217
# Download all the docker images into $1, and append its name to an index.txt
1318
# If this errors out for you, copy default-policy.json from the skopeo repo to
1419
# /etc/containers/policy.json
1520
while IFS= read -r image; do
16-
# sanitize the image file name, replace slashes with underscores, suffix with .tar
17-
image_filename=$(sed -r "s/[:\/]/_/g" <<< $image)
18-
image_path=$(realpath $1)/${image_filename}.tar
19-
if [[ -e $image_path ]];then
20-
echo "Skipping $image_filename"
21+
22+
# sanitize the image file name, replace slashes with underscores, suffix with .tar
23+
image_filename=$(sed -r "s/[:\/]/_/g" <<< "$image")
24+
image_path="$(realpath "$1")/${image_filename}.tar"
25+
26+
if [[ -s "$image_path" ]]; then
27+
echo "Skipping $image_filename"
28+
continue
29+
fi
30+
31+
echo "Fetching $image_filename"
32+
33+
# All of these images should be publicly fetchable, especially given we
34+
# ship public tarballs containing these images.
35+
# ci.sh already honors DOCKER_LOGIN, so do the same here, otherwise
36+
# fallback to unauthorized fetching.
37+
38+
# If an image has both a tag and digest, remove the tag. Return the original if there is no match.
39+
image_trimmed=$(echo "$image" | sed -E 's/(.+)(:.+(@.+))/\1\3/')
40+
41+
tmp_path="${image_path}.tmp"
42+
rm -f "$tmp_path"
43+
44+
success=false
45+
46+
for attempt in {1..5}; do
47+
echo "Attempt $attempt/5 for $image_trimmed"
48+
49+
if [[ -n "${DOCKER_LOGIN:-}" && "$image" =~ quay.io/wire ]]; then
50+
skopeo copy --insecure-policy \
51+
--src-creds "$DOCKER_LOGIN" \
52+
--retry-times 10 \
53+
"docker://$image_trimmed" \
54+
"docker-archive:${tmp_path}" \
55+
--additional-tag "$image" || rc=$?
2156
else
22-
echo "Fetching $image_filename"
23-
24-
# All of these images should be publicly fetchable, especially given we
25-
# ship public tarballs containing these images.
26-
# ci.sh already honors DOCKER_LOGIN, so do the same here, otherwise
27-
# fallback to unauthorized fetching.
28-
29-
# If an image has both a tag and digest, remove the tag. Return the original if there is no match.
30-
image_trimmed=$(echo "$image" | sed -E 's/(.+)(:.+(@.+))/\1\3/')
31-
if [[ -n "${DOCKER_LOGIN:-}" && "$image" =~ quay.io/wire ]];then
32-
skopeo copy --insecure-policy --src-creds "$DOCKER_LOGIN" \
33-
docker://$image_trimmed docker-archive:${image_path} --additional-tag $image
34-
else
35-
skopeo copy --insecure-policy \
36-
docker://$image_trimmed docker-archive:${image_path} --additional-tag $image
37-
fi
38-
echo "${image_filename}.tar" >> $(realpath "$1")/index.txt
57+
skopeo copy --insecure-policy \
58+
--retry-times 10 \
59+
"docker://$image_trimmed" \
60+
"docker-archive:${tmp_path}" \
61+
--additional-tag "$image" || rc=$?
62+
fi
63+
64+
rc=$?
65+
66+
if [[ $rc -eq 0 && -s "$tmp_path" ]]; then
67+
mv "$tmp_path" "$image_path"
68+
success=true
69+
break
3970
fi
71+
72+
echo "Fetch failed for $image_trimmed with rc=$rc; retrying…"
73+
rm -f "$tmp_path"
74+
sleep $((attempt * 20))
75+
done
76+
77+
if [[ "$success" != true ]]; then
78+
echo "ERROR: failed to fetch $image after retries" >&2
79+
exit 1
80+
fi
81+
82+
echo "${image_filename}.tar" >> "$(realpath "$1")/index.txt"
83+
create-build-entry "$image" "$output_dir"
4084
done

0 commit comments

Comments
 (0)