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

modify container_build.sh to add capability to use podman farm for multi-arch images #736

Merged
merged 8 commits into from
Feb 4, 2025
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ help:
@echo
@echo " - make build"
@echo " - make build IMAGE=ramalama"
@echo " - make multi-arch"
@echo " - make multi-arch IMAGE=ramalama"
@echo
@echo "Build docs"
@echo
Expand Down Expand Up @@ -81,6 +83,10 @@ build:
build_rm:
./container_build.sh -r build $(IMAGE)

.PHONY: build_multi_arch
build_multi_arch:
./container_build.sh multi-arch $(IMAGE)

.PHONY: install-docs
install-docs: docs
make -C docs install
Expand Down
Empty file.
Empty file.
26 changes: 21 additions & 5 deletions container_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ add_build_platform() {
fi

conman_build+=("--platform" "$platform")
conman_build+=("-t" "quay.io/ramalama/$image_name")
conman_build+=("-t" "$REGISTRY_PATH/$image_name")
conman_build+=("-f" "$image_name/Containerfile" ".")
}

Expand All @@ -41,7 +41,7 @@ build() {
cd "container-images"
local image_name="${1//container-images\//}"
local conman_build=("${conman[@]}")
local conman_show_size=("${conman[@]}" "images" "--filter" "reference='quay.io/ramalama/$image_name'")
local conman_show_size=("${conman[@]}" "images" "--filter" "reference='$REGISTRY_PATH/$image_name'")
if [ "$3" == "-d" ]; then
add_build_platform
echo "${conman_build[@]}"
Expand All @@ -58,10 +58,13 @@ build() {
rm_container_image
;;
push)
"${conman[@]}" push "quay.io/ramalama/$image_name"
"${conman[@]}" push "$REGISTRY_PATH/$image_name"
;;
multi-arch)
podman farm build -t "$REGISTRY_PATH"/"$image_name" -f "$image_name"/Containerfile .
;;
*)
echo "Invalid command: ${2:-}. Use 'build' or 'push'."
echo "Invalid command: ${2:-}. Use 'build', 'push' or 'multi-arch'."
return 1
;;
esac
Expand Down Expand Up @@ -93,7 +96,7 @@ parse_arguments() {
rm_after_build="true"
shift
;;
build|push)
build|push|multi-arch)
command="$1"
shift
;;
Expand All @@ -112,6 +115,9 @@ process_all_targets() {
if [ "$i" == "container-images/scripts" ]; then
continue
fi
if [ "$command" = "multi-arch" ] && [ ! -f "$i"/.multi-arch ]; then
continue
fi
build "$i" "$command" "$option"
done
}
Expand All @@ -122,6 +128,7 @@ print_usage() {
echo "Commands:"
echo " build Build the container images"
echo " push Push the container images"
echo " multi-arch Build and Push multi-arch images with podman farm"
echo
echo "Options:"
echo " -d Some option description"
Expand All @@ -130,6 +137,9 @@ print_usage() {
echo "Targets:"
echo " Specify the target container image to build or push"
echo " If no target is specified, all container images will be processed"
echo "Destination Registry:"
echo " Override the target registry path by setting the env var REGISTRY_PATH"
echo " default - quay.io/ramalama"
}

main() {
Expand All @@ -149,6 +159,11 @@ main() {
print_usage
exit 1
fi
if [ "$command" = "multi-arch" ] && [ "$conman_bin" != "podman" ]; then
echo "Error: command 'multi-arch' only works with podman farm"
print_usage
exit 1
fi

target="${target:-all}"
if [ "$target" = "all" ]; then
Expand All @@ -158,5 +173,6 @@ main() {
fi
}

REGISTRY_PATH=${REGISTRY_PATH:-quay.io/ramalama}
main "$@"

Loading