Skip to content

Commit

Permalink
feat: support symlinking blobs from base (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored May 8, 2024
1 parent 40884f6 commit cbff154
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/big_image/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ oci_tarball(
name = "evil",
image = ":base",
repo_tags = ["hello:test"],
tags = ["manual"],
)

# 2- Create an image that extends the base without adding additional layers
Expand Down
2 changes: 2 additions & 0 deletions oci/private/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def _oci_image_impl(ctx):
# reuse given base image
args.add(ctx.file.base.path, format = "--from=%s")
inputs.append(ctx.file.base)
if use_symlinks:
transitive_inputs.append(ctx.file.base)
else:
# create a scratch base image with given os/arch[/variant]
args.add(_platform_str(ctx.attr.os, ctx.attr.architecture, ctx.attr.variant), format = "--scratch=%s")
Expand Down
14 changes: 10 additions & 4 deletions oci/private/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ function base_from() {
local path="$1"
# shellcheck disable=SC2045
for blob in $(ls -1 -d "$path/blobs/"*/*); do
local relative=${blob#"$path/"}
mkdir -p "$OUTPUT/$(dirname "$relative")"
cat "$blob" >"$OUTPUT/$relative"
local relative_to_blobs="${blob#"$path/blobs"}"
mkdir -p "$OUTPUT/blobs/$(dirname "$relative_to_blobs")"
if [[ "$USE_TREEARTIFACT_SYMLINKS" == "1" ]]; then
# Relative path from `output/blobs/sha256/` to `$blob`
relative="$(coreutils realpath --relative-to="$OUTPUT/blobs/sha256" "$blob" --no-symlinks)"
coreutils ln -s "$relative" "$OUTPUT/blobs/$relative_to_blobs"
else
coreutils cat "$blob" > "$OUTPUT/blobs/$relative_to_blobs"
fi
done
cat "$path/oci-layout" >"$OUTPUT/oci-layout"
coreutils cat "$path/oci-layout" >"$OUTPUT/oci-layout"
jq '.manifests[0].annotations["org.opencontainers.image.ref.name"] = "intermediate"' "$path/index.json" >"$OUTPUT/index.json"
}

Expand Down

0 comments on commit cbff154

Please sign in to comment.