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

Update linuxkit container image naming: #224

Merged
merged 1 commit into from
May 17, 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
23 changes: 13 additions & 10 deletions bash/hook-lk-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ function build_all_hook_linuxkit_containers() {

# when adding new container builds here you'll also want to add them to the
# `linuxkit_build` function in the linuxkit.sh file.
build_hook_linuxkit_container images/hook-bootkit HOOK_CONTAINER_BOOTKIT_IMAGE
build_hook_linuxkit_container images/hook-docker HOOK_CONTAINER_DOCKER_IMAGE
build_hook_linuxkit_container images/hook-mdev HOOK_CONTAINER_MDEV_IMAGE
build_hook_linuxkit_container images/containerd HOOK_CONTAINER_CONTAINERD_IMAGE
build_hook_linuxkit_container images/runc HOOK_CONTAINER_RUNC_IMAGE
# # NOTE: linuxkit containers must be in the images/ directory
build_hook_linuxkit_container hook-bootkit HOOK_CONTAINER_BOOTKIT_IMAGE
build_hook_linuxkit_container hook-docker HOOK_CONTAINER_DOCKER_IMAGE
build_hook_linuxkit_container hook-mdev HOOK_CONTAINER_MDEV_IMAGE
build_hook_linuxkit_container hook-containerd HOOK_CONTAINER_CONTAINERD_IMAGE
build_hook_linuxkit_container hook-runc HOOK_CONTAINER_RUNC_IMAGE
}

function build_hook_linuxkit_container() {
declare container_dir="${1}"
declare -n output_var="${2}" # bash name reference, kind of an output var but weird
declare container_base_dir="images"

# Lets hash the contents of the directory and use that as a tag
declare container_files_hash
container_files_hash="$(find "${container_dir}" -type f -print | LC_ALL=C sort | xargs sha256sum | sha256sum | cut -d' ' -f1)"
# NOTE: linuxkit containers must be in the images/ directory
container_files_hash="$(find "${container_base_dir}/${container_dir}" -type f -print | LC_ALL=C sort | xargs sha256sum | sha256sum | cut -d' ' -f1)"
declare container_files_hash_short="${container_files_hash:0:8}"

declare container_oci_ref="${HOOK_LK_CONTAINERS_OCI_BASE}${container_dir}:${container_files_hash_short}-${DOCKER_ARCH}"
log info "Consider building LK container ${container_oci_ref} from ${container_dir} for platform ${DOCKER_ARCH}"
log info "Consider building LK container ${container_oci_ref} from ${container_base_dir}/${container_dir} for platform ${DOCKER_ARCH}"
output_var="${container_oci_ref}" # the the name reference
echo "${output_var}" > /dev/null # no-op; just to avoid shellcheck SC2034 (unused var; but it is actually a bash nameref)

Expand All @@ -50,13 +53,13 @@ function build_hook_linuxkit_container() {
exit 9
fi

log info "Building ${container_oci_ref} from ${container_dir} for platform ${DOCKER_ARCH}"
log info "Building ${container_oci_ref} from ${container_base_dir}/${container_dir} for platform ${DOCKER_ARCH}"
(
cd "${container_dir}" || exit 1
cd "${container_base_dir}/${container_dir}" || exit 1
docker buildx build --load "--progress=${DOCKER_BUILDX_PROGRESS_TYPE}" -t "${container_oci_ref}" --platform "linux/${DOCKER_ARCH}" .
)

log info "Built ${container_oci_ref} from ${container_dir} for platform ${DOCKER_ARCH}"
log info "Built ${container_oci_ref} from ${container_base_dir}/${container_dir} for platform ${DOCKER_ARCH}"

push_hook_linuxkit_container "${container_oci_ref}"

Expand Down
File renamed without changes.
File renamed without changes.