Skip to content

Commit

Permalink
feat: implement tars symlinks (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed May 8, 2024
1 parent 40884f6 commit 5c033ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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 5c033ff

Please sign in to comment.