Skip to content

Commit a7a57d5

Browse files
authored
feat(IDX): Add prefix to artifact bundles (#5098)
This adds a `prefix` option when creating artifact bundles. This will allow us to use the bundles directly when uploading artifacts to the CDN, instead of duplicating the logic of listing artifacts & computing checksums. This also makes the necessary changes in `build-ic.sh` to support nested build artifacts as well as fixes a typo in the guestos directory name. The implementation of `artifact_bundle` is also simplified to avoid creating symlinks from Bazel; moreover the output of `artifact_bundle` is now a _directory_ instead of a list of artifacts. Prefixes are also added to all artifact bundles to reflect the file structure on the CDN.
1 parent 26c0950 commit a7a57d5

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

ci/container/build-ic.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ for artifact in $(bazel cquery "${BAZEL_COMMON_ARGS[@]}" --output=files "$query"
172172
esac
173173

174174
mkdir -p "$target_dir"
175-
cp "$artifact" "$target_dir"
175+
176+
# We use -L so that find dereferences symlinks (artifacts are not
177+
# necessarily duplicated in the build)
178+
find -L "$artifact" -type f -exec cp {} "$target_dir" \;
176179
done
177180

178181
if "$BUILD_BIN"; then

ic-os/guestos/envs/prod/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ file_size_check(
3939
artifact_bundle(
4040
name = "bundle",
4141
inputs = [":prod"],
42+
prefix = "guest-os/update-img",
4243
)
4344

4445
# This image is used for GuestOS upgrades
4546
upload_artifacts(
4647
name = "upload_update-img",
4748
inputs = [icos_images.update_image],
48-
remote_subdir = "guestos-os/update-img",
49+
remote_subdir = "guest-os/update-img",
4950
visibility = ["//visibility:public"], # testnet deploy tools use this
5051
)

ic-os/hostos/envs/prod/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ file_size_check(
3737
artifact_bundle(
3838
name = "bundle",
3939
inputs = [":prod"],
40+
prefix = "host-os/update-img",
4041
)
4142

4243
# This image is used for HostOS upgrades

ic-os/setupos/envs/prod/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ launch_bare_metal(
3131
artifact_bundle(
3232
name = "bundle",
3333
inputs = [":prod"],
34+
prefix = "setup-os/disk-img",
3435
)
3536

3637
# This image is used as the IC-OS installation image downloaded by Node Providers

publish/binaries/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ filegroup(
122122
artifact_bundle(
123123
name = "bundle",
124124
inputs = [":binaries"],
125+
prefix = "binaries/" + os_info,
126+
)
127+
128+
artifact_bundle(
129+
name = "bundle-legacy",
130+
inputs = [":binaries"],
131+
prefix = "release",
125132
)
126133

127134
upload_artifacts(

publish/canisters/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ filegroup(
135135
artifact_bundle(
136136
name = "bundle",
137137
inputs = [":canisters"],
138+
prefix = "canisters",
138139
)
139140

140141
# the further targets are all testonly for simplicity because if a target was

publish/defs.bzl

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,12 @@ def _artifact_bundle_impl(ctx):
125125
# List of input files
126126
input_files = ctx.files.inputs
127127

128-
bundle_dir = "{}_bundle".format(ctx.attr.name)
128+
bundle_root = ctx.actions.declare_directory("bundle-{}".format(ctx.attr.name))
129129

130-
# Declare output files (NOTE: not windows friendly)
131-
out_checksums = ctx.actions.declare_file(bundle_dir + "/SHA256SUMS")
130+
bundle_prefix = ctx.attr.prefix
132131

133-
def make_symlink(target):
134-
symlink = ctx.actions.declare_file(bundle_dir + "/" + target.basename)
135-
ctx.actions.symlink(output = symlink, target_file = target)
136-
return symlink
137-
138-
symlinks = [make_symlink(file) for file in input_files]
132+
if bundle_prefix == "":
133+
fail("artifact bundle prefix must be set")
139134

140135
# Compute checksums and print it to stdout & out file.
141136
# The filenames are stripped from anything but the basename.
@@ -144,32 +139,35 @@ def _artifact_bundle_impl(ctx):
144139
ctx.actions.run_shell(
145140
inputs = input_files,
146141
arguments = [file.path for file in input_files],
147-
outputs = [out_checksums],
142+
env = {
143+
"BUNDLE_ROOT": bundle_root.path,
144+
"BUNDLE_PREFIX": bundle_prefix,
145+
},
146+
outputs = [bundle_root],
148147
tools = [ctx.executable._sha256],
149148
command = """
150149
set -euo pipefail
151150
152-
out_checksums="{out}"
153-
output=$(mktemp) # temporary file bc sha256 doesn't support writing to stdout (or /dev/stdout) directly
151+
outdir="$BUNDLE_ROOT/$BUNDLE_PREFIX"
152+
153+
mkdir -p "$outdir"
154+
155+
out_checksums="$outdir/SHA256SUMS"
154156
157+
output=$(mktemp) # temporary file bc sha256 doesn't support writing to stdout (or /dev/stdout) directly
155158
for input in "$@"; do
156-
if ! [[ $input =~ (\\.tar|\\.gz) ]]; then
157-
echo "skipping non-archive file $input"
158-
continue
159-
fi
160159
{sha256} "$input" "$output"
161160
cat "$output" >> "$out_checksums"
162161
echo " $(basename $input)" >> "$out_checksums"
162+
ln -s "$( realpath "$input" )" "$outdir/$(basename $input)"
163163
done
164164
165-
cat "$out_checksums"
166-
167165
sort -o "$out_checksums" -k 2 "$out_checksums"
168-
""".format(out = out_checksums.path, sha256 = ctx.executable._sha256.path),
166+
""".format(sha256 = ctx.executable._sha256.path),
169167
)
170168

171169
# Return the output file
172-
return [DefaultInfo(files = depset([out_checksums] + symlinks))]
170+
return [DefaultInfo(files = depset([bundle_root]))]
173171

174172
# A rule that re-exports symlinks to all the inputs as well
175173
# as an extra file 'SHA256SUMS' containing the checksums of inputs.
@@ -180,6 +178,9 @@ artifact_bundle = rule(
180178
allow_files = True,
181179
mandatory = True,
182180
),
181+
"prefix": attr.string(
182+
mandatory = True,
183+
),
183184
# The bazel-provided sha256 tool to avoid relying on tools from the container/env
184185
"_sha256": attr.label(
185186
default = "@bazel_tools//tools/build_defs/hash:sha256",

0 commit comments

Comments
 (0)