diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-07-24 11:31:52 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-07-24 11:31:52 +0200 |
| commit | dfc47cde3a41c2f3776f720a367cf8d042335ddd (patch) | |
| tree | 14384957c93846463e3ba955cfcfe6e0c28cd681 | |
| parent | ad55171a802b227cbb894bd2c094ab99911b330e (diff) | |
| download | nissy-core-dfc47cde3a41c2f3776f720a367cf8d042335ddd.tar.gz nissy-core-dfc47cde3a41c2f3776f720a367cf8d042335ddd.zip | |
Add container-run.sh script
Diffstat (limited to '')
| -rwxr-xr-x | container-run.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/container-run.sh b/container-run.sh new file mode 100755 index 0000000..9799f65 --- /dev/null +++ b/container-run.sh | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # A simple script to run commands (e.g. build commands) in a Docker container. | ||
| 4 | # It can be used for testing on platforms different from the host. For example, | ||
| 5 | # the command | ||
| 6 | # | ||
| 7 | # ./container-run.sh arm ./build test | ||
| 8 | # | ||
| 9 | # builds nissy and runs the unit tests in an ARM container. | ||
| 10 | # The container images are based on Alpine Linux, see Dockerfile for details. | ||
| 11 | # The images are built with a tag starting with 'localhost/nissy/'. | ||
| 12 | # See below for a list of options. | ||
| 13 | |||
| 14 | usage() { | ||
| 15 | echo "$1" | ||
| 16 | echo "" | ||
| 17 | echo "usage: $0 PLATFORM [COMMAND]" | ||
| 18 | echo "" | ||
| 19 | echo "If COMMAND is unspecified, an interactive shell will be opened." | ||
| 20 | echo "" | ||
| 21 | echo "Available platforms:" | ||
| 22 | echo "x86 (equivalent to: x86_64, amd64)" | ||
| 23 | echo "arm (equivalent to: arm64)" | ||
| 24 | echo "" | ||
| 25 | echo "Examples:" | ||
| 26 | echo "$0 ram ./build test # Run unit tests in arm container" | ||
| 27 | exit 1 | ||
| 28 | } | ||
| 29 | |||
| 30 | if [ -z "$1" ]; then | ||
| 31 | usage "No platform given." | ||
| 32 | fi | ||
| 33 | |||
| 34 | case "$1" in | ||
| 35 | x86|x86_64|amd64) | ||
| 36 | p=amd64 | ||
| 37 | shift | ||
| 38 | ;; | ||
| 39 | arm|arm64) | ||
| 40 | p=arm64 | ||
| 41 | shift | ||
| 42 | ;; | ||
| 43 | *) | ||
| 44 | usage "Platform '$1' not available." | ||
| 45 | ;; | ||
| 46 | esac | ||
| 47 | |||
| 48 | platform="--platform=linux/$p" | ||
| 49 | image="localhost/nissy/alpine-$p" | ||
| 50 | |||
| 51 | docker build "$platform" -t "$image" . | ||
| 52 | |||
| 53 | if [ -z "$2" ]; then | ||
| 54 | docker run "$platform" -it "$image" /bin/sh | ||
| 55 | else | ||
| 56 | docker run "$platform" -t "$image" $@ | ||
| 57 | fi | ||
