Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support symlinking blobs from base #560

Merged
merged 1 commit into from
May 8, 2024
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
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)
gregmagolan marked this conversation as resolved.
Show resolved Hide resolved
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"
gregmagolan marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading