Skip to content

Commit

Permalink
Add support for running containers with foreign architectures (#87)
Browse files Browse the repository at this point in the history
This adds a -arch option for building and running the container image.

This was tested with qemu, building an armv7 image for intel. The goal
however is to use it for armv7 on arm64.

It would be nice to provide pre-built armv7 (and perhaps riscv) images.
  • Loading branch information
justinmichaud authored Jan 20, 2025
1 parent 11d89fa commit c6dafd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/host-only/wkdev-create
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ argsparse_use_option attach "Attach to container as it starts up."
argsparse_use_option no-pull "Do not login or pull images."
argsparse_use_option list-tags "List available image tags."
argsparse_use_option =tag: "Create the container using a specific tag, see-also --list-tags." default:$(get_default_container_tag)
argsparse_use_option =arch: "Container architecture."

argsparse_usage_description="$(cat <<EOF
<< Purpose >>
Expand Down Expand Up @@ -436,6 +437,12 @@ build_podman_create_arguments() {
arguments+=("--pull=newer")
fi

if argsparse_is_option_set "arch"; then
container_arch="${program_options["arch"]}"
echo "Overriding container architecture: ${container_arch}"
arguments+=("--arch=${container_arch}")
fi

set +o nounset
try_process_user ${1}
try_process_groups ${1}
Expand Down
7 changes: 7 additions & 0 deletions scripts/host-only/wkdev-sdk-bakery
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ argsparse_use_option =env: "Environment variable as string array, e.g. -e
argsparse_use_option =mode: "Operation mode: 'build', 'deploy', or 'export'" mandatory
argsparse_use_option idle-cores: "Number of CPU cores to leave idle, when building the image" type:uint default:2
argsparse_use_option =tag: "Tag to use for created image." default:$(get_default_container_tag)
argsparse_use_option =arch: "Container architecture."

argsparse_usage_description="$(cat <<EOF
<< Purpose >>
Expand Down Expand Up @@ -63,6 +64,12 @@ build_image() {
local podman_argument=("--jobs" "$(get_number_of_cores_for_build)")
podman_argument+=("--tag" "$(get_tag_for_build)")

if argsparse_is_option_set "arch"; then
container_arch="${program_options["arch"]}"
echo "Overriding container architecture: ${container_arch}"
podman_argument+=("--arch=${container_arch}")
fi

for environment_variable in "${cumulated_values_env[@]}"
do
podman_argument+=("--env" "${environment_variable}")
Expand Down

0 comments on commit c6dafd9

Please sign in to comment.