Skip to content

Commit

Permalink
perf: make registry output to bazel-out (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored Jan 11, 2024
1 parent 6667c5e commit db9273a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
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
10 changes: 6 additions & 4 deletions oci/private/image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,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

if grep -q "MANIFEST_INVALID" "${output}"; then
cat >&2 << EOF
Expand Down Expand Up @@ -161,7 +159,11 @@ 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"
rm "${OUTPUT}/temp.json"
"${CRANE}" layout gc "./${OUTPUT}"
fi

} 2>> "${STDERR}"
13 changes: 7 additions & 6 deletions oci/private/registry/zot_launcher.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ function start_registry() {
local storage_dir="$1"
local output="$2"
local deadline="${3:-5}"
local config_path="$1/config.json"
local registry_pid="$1/proc.pid"
local config_path="$storage_dir/config.json"
local registry_pid="$storage_dir/proc.pid"
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 @@ -37,6 +36,8 @@ EOF

function stop_registry() {
local storage_dir="$1"
rm -rf "${storage_dir}/.uploads"
rm -r "${storage_dir}/config.json"
local registry_pid="$1/proc.pid"
if [[ ! -f "${registry_pid}" ]]; then
return 0
Expand Down

0 comments on commit db9273a

Please sign in to comment.