commit dfc47cde3a41c2f3776f720a367cf8d042335ddd parent ad55171a802b227cbb894bd2c094ab99911b330e Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Thu, 24 Jul 2025 11:31:52 +0200 Add container-run.sh script Diffstat:
A | container-run.sh | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/container-run.sh b/container-run.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# A simple script to run commands (e.g. build commands) in a Docker container. +# It can be used for testing on platforms different from the host. For example, +# the command +# +# ./container-run.sh arm ./build test +# +# builds nissy and runs the unit tests in an ARM container. +# The container images are based on Alpine Linux, see Dockerfile for details. +# The images are built with a tag starting with 'localhost/nissy/'. +# See below for a list of options. + +usage() { + echo "$1" + echo "" + echo "usage: $0 PLATFORM [COMMAND]" + echo "" + echo "If COMMAND is unspecified, an interactive shell will be opened." + echo "" + echo "Available platforms:" + echo "x86 (equivalent to: x86_64, amd64)" + echo "arm (equivalent to: arm64)" + echo "" + echo "Examples:" + echo "$0 ram ./build test # Run unit tests in arm container" + exit 1 +} + +if [ -z "$1" ]; then + usage "No platform given." +fi + +case "$1" in +x86|x86_64|amd64) + p=amd64 + shift + ;; +arm|arm64) + p=arm64 + shift + ;; +*) + usage "Platform '$1' not available." + ;; +esac + +platform="--platform=linux/$p" +image="localhost/nissy/alpine-$p" + +docker build "$platform" -t "$image" . + +if [ -z "$2" ]; then + docker run "$platform" -it "$image" /bin/sh +else + docker run "$platform" -t "$image" $@ +fi