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

perf: make registry output to bazel-out #324

Merged
merged 8 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions e2e/custom_registry/registry/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ function start_registry() {
fi
echo "127.0.0.1:${port}"
return 0
}

function stop_registry() {
:
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 4 additions & 2 deletions oci/private/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def _oci_image_impl(ctx):

launcher = ctx.actions.declare_file("image_%s.sh" % ctx.label.name)

output = ctx.actions.declare_directory(ctx.label.name)

ctx.actions.expand_template(
template = ctx.file._image_sh_tpl,
output = launcher,
Expand All @@ -116,7 +118,7 @@ def _oci_image_impl(ctx):
"{{registry_launcher_path}}": registry.registry_info.launcher.path,
"{{crane_path}}": crane.crane_info.binary.path,
"{{jq_path}}": jq.jqinfo.bin.path,
"{{storage_dir}}": "/".join([ctx.bin_dir.path, ctx.label.package, "storage_%s" % ctx.label.name]),
"{{storage_dir}}": output.path,
"{{empty_tar}}": ctx.file._empty_tar.path,
},
)
Expand Down Expand Up @@ -174,7 +176,7 @@ def _oci_image_impl(ctx):
args.add(ctx.file.annotations.path, format = "--annotations-file=%s")
inputs_depsets.append(depset([ctx.file.annotations]))

output = ctx.actions.declare_directory(ctx.label.name)

args.add(output.path, format = "--output=%s")

action_env = {}
Expand Down
11 changes: 7 additions & 4 deletions oci/private/image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ function base_from_layout() {
local oci_layout_path=$1
local registry=$2

"${CRANE}" push "${oci_layout_path}" "${registry}/oci/layout:latest" --image-refs "${refs}" > "${output}" 2>&1

echo "${output}" >&2
"${CRANE}" push "${oci_layout_path}" "${registry}/image:latest" --image-refs "${refs}" > "${output}" 2>&1
thesayyn marked this conversation as resolved.
Show resolved Hide resolved

if grep -q "MANIFEST_INVALID" "${output}"; then
cat >&2 << EOF
Expand Down Expand Up @@ -160,7 +158,12 @@ if [ ${#ENV_EXPANSIONS[@]} -ne 0 ]; then
fi

if [ -n "$OUTPUT" ]; then
"${CRANE}" pull "${REF}" "./${OUTPUT}" --format=oci
"${CRANE}" pull "${REF}" "./${OUTPUT}" --format=oci --annotate-ref
mv "${OUTPUT}/index.json" "${OUTPUT}/temp.json"
"${JQ}" --arg ref "${REF}" '.manifests |= map(select(.annotations["org.opencontainers.image.ref.name"] == $ref)) | del(.manifests[0].annotations)' "${OUTPUT}/temp.json" > "${OUTPUT}/index.json"
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
rm "${OUTPUT}/temp.json"
"${CRANE}" layout gc "./${OUTPUT}"
stop_registry "${OUTPUT}"
fi

} 2>> "${STDERR}"
10 changes: 5 additions & 5 deletions oci/private/registry/crane_launcher.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ function start_registry() {
local output="$2"
local deadline="${3:-5}"

mkdir -p "${storage_dir}"
# --blobs-to-disk uses go's os.TempDir() function which is equal to TMPDIR under *nix.
# https://pkg.go.dev/os#TempDir
TMPDIR="${storage_dir}" TMP="${storage_dir}" \
"${CRANE_REGISTRY_BIN}" registry serve --blobs-to-disk >> $output 2>&1 &
"${CRANE_REGISTRY_BIN}" registry serve --disk="${storage_dir}" >> $output 2>&1 &

local timeout=$((SECONDS+${deadline}))

Expand All @@ -26,4 +22,8 @@ function start_registry() {
fi
echo "127.0.0.1:${port}"
return 0
}

function stop_registry() {
:
}
15 changes: 10 additions & 5 deletions oci/private/registry/zot_launcher.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ function start_registry() {
local storage_dir="$1"
local output="$2"
local deadline="${3:-5}"
local config_path="$1/config.json"
local config_path="$storage_dir/config.json"

mkdir -p "${storage_dir}"
cat > "${config_path}" <<EOF
{
"storage": {"rootDirectory": "$1" },
"http": { "port": "0", "address": "127.0.0.1" },
"log": { "level": "info" }
"storage": { "rootDirectory": "$storage_dir/..", "dedupe": false, "commit": true },
"http":{ "port": "0", "address": "127.0.0.1" },
"log":{ "level": "info" }
}
EOF
HOME="${TMPDIR}" "${ZOT}" serve "${config_path}" >> $output 2>&1 &
Expand All @@ -31,4 +30,10 @@ EOF
fi
echo "127.0.0.1:${port}"
return 0
}

function stop_registry() {
local storage_dir="$1"
rm -rf "${storage_dir}/.uploads"
rm -r "${storage_dir}/config.json"
}
Loading