Skip to content

Commit

Permalink
fix: duplicate tar copying (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored May 21, 2024
1 parent 7cdba81 commit d49f7b6
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 19 deletions.
57 changes: 57 additions & 0 deletions examples/assertion/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//oci:defs.bzl", "oci_image")

# Case 1: image name containing a capital case.
oci_image(
name = "imagE",
architecture = "amd64",
cmd = ["noop"],
os = "linux",
)

# Case 2: existing layer added again.
tar(
name = "empty_tar",
srcs = [],
)

oci_image(
name = "same_tar_multiple_times",
architecture = "amd64",
cmd = ["noop"],
os = "linux",
tars = [
":empty_tar",
],
)

oci_image(
name = "case2",
base = ":same_tar_multiple_times",
tars = [
":empty_tar",
],
)

# Case 3: Adding an identical tar from another directory multiple times
oci_image(
name = "case3",
architecture = "arm64",
os = "linux",
tars = [
# layer_0 and layer_1 is identical
"//examples/just_tar:layer_0",
"//examples/just_tar:layer_1",
],
)

# build them as test.
build_test(
name = "test",
targets = [
":imagE",
":case2",
":case3",
],
)
1 change: 1 addition & 0 deletions examples/assertion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is not useful as an example, merely exists for test coverage.
1 change: 1 addition & 0 deletions examples/big_image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is not useful as an example, merely exists for test coverage.
20 changes: 20 additions & 0 deletions examples/just_tar/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@aspect_bazel_lib//lib:tar.bzl", "tar")

# See `Case 3` in examples/assertion
genrule(
name = "10mb_file",
outs = ["10mb_file.out"],
cmd = "head -c 10485760 < /dev/urandom > $@",
local = True,
tags = ["manual"],
)

[
tar(
name = "layer_%s" % i,
srcs = ["10mb_file"],
tags = ["manual"],
visibility = ["//examples/assertion:__pkg__"],
)
for i in range(2)
]
1 change: 1 addition & 0 deletions examples/just_tar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is not useful as an example, merely exists for test coverage.
1 change: 1 addition & 0 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is not useful as an example, merely exists for test coverage.
16 changes: 0 additions & 16 deletions examples/various/BUILD.bazel

This file was deleted.

6 changes: 4 additions & 2 deletions oci/private/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ function add_layer() {
--arg media_type "${media_type}" | update_manifest

local digest_path=
local output_path=
digest_path="$(jq -r '.digest | sub(":"; "/")' <<< "$desc")"
output_path="$OUTPUT/blobs/$digest_path"

if [[ "$USE_TREEARTIFACT_SYMLINKS" == "1" ]]; then
relative=$(coreutils realpath --no-symlinks --canonicalize-missing --relative-to="$OUTPUT/blobs/sha256" "$path" )
coreutils ln -s "$relative" "$OUTPUT/blobs/$digest_path"
coreutils ln --force --symbolic "$relative" "$output_path"
else
coreutils cat "$path" > "$OUTPUT/blobs/$digest_path"
coreutils cat "$path" > "$output_path"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion oci/private/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ oci_push_lib = struct(
attrs = _attrs,
toolchains = [
"@rules_oci//oci:crane_toolchain_type",
"@aspect_bazel_lib//lib:yq_toolchain_type",
"@aspect_bazel_lib//lib:jq_toolchain_type",
"@bazel_tools//tools/sh:toolchain_type",
],
)
Expand Down

0 comments on commit d49f7b6

Please sign in to comment.