Skip to content

Commit 3d116fc

Browse files
committed
feat: implement tars symlinks (#559)
1 parent 40884f6 commit 3d116fc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

oci/private/image.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def _oci_image_impl(ctx):
166166
# reuse given base image
167167
args.add(ctx.file.base.path, format = "--from=%s")
168168
inputs.append(ctx.file.base)
169+
if use_symlinks:
170+
transitive_inputs.append(ctx.file.base)
169171
else:
170172
# create a scratch base image with given os/arch[/variant]
171173
args.add(_platform_str(ctx.attr.os, ctx.attr.architecture, ctx.attr.variant), format = "--scratch=%s")

oci/private/image.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ function base_from() {
3333
local path="$1"
3434
# shellcheck disable=SC2045
3535
for blob in $(ls -1 -d "$path/blobs/"*/*); do
36-
local relative=${blob#"$path/"}
37-
mkdir -p "$OUTPUT/$(dirname "$relative")"
38-
cat "$blob" >"$OUTPUT/$relative"
36+
local relative_to_blobs=${blob#"$path/blobs"}
37+
mkdir -p "$OUTPUT/blobs/$(dirname "$relative_to_blobs")"
38+
if [[ "$USE_TREEARTIFACT_SYMLINKS" == "1" ]]; then
39+
# Relative path from `output/blobs/sha256/` to `$blob`
40+
relative=$(coreutils realpath --relative-to="$OUTPUT/blobs/sha256" "$blob" --no-symlinks)
41+
coreutils ln -s "$relative" "$OUTPUT/blobs/$relative_to_blobs"
42+
else
43+
coreutils cat "$blob" > "$OUTPUT/blobs/$relative_to_blobs"
44+
fi
3945
done
40-
cat "$path/oci-layout" >"$OUTPUT/oci-layout"
46+
coreutils cat "$path/oci-layout" >"$OUTPUT/oci-layout"
4147
jq '.manifests[0].annotations["org.opencontainers.image.ref.name"] = "intermediate"' "$path/index.json" >"$OUTPUT/index.json"
4248
}
4349

0 commit comments

Comments
 (0)