diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-03 08:52:45 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-03 08:52:45 +0200 |
| commit | f6efc882a279cddb624fe2f2470797561a6997b8 (patch) | |
| tree | 2e792efa7c237962676db894d9e77892432e07e2 /utils/container-run.sh | |
| parent | 7ff76870242b6906b6f3caf22da3c094822ed140 (diff) | |
| download | nissy-core-f6efc882a279cddb624fe2f2470797561a6997b8.tar.gz nissy-core-f6efc882a279cddb624fe2f2470797561a6997b8.zip | |
Move container-run.sh into utils/
Diffstat (limited to 'utils/container-run.sh')
| -rwxr-xr-x | utils/container-run.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/utils/container-run.sh b/utils/container-run.sh new file mode 100755 index 0000000..ba8deae --- /dev/null +++ b/utils/container-run.sh | |||
| @@ -0,0 +1,76 @@ | |||
| 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 | # | ||
| 11 | # The containers are based on Alpine Linux and the contain the necessary tools | ||
| 12 | # to build the main library and the C++ and Python examples. They DO NOT | ||
| 13 | # contain the emscripten compiler, so they cannot be used to build the web | ||
| 14 | # version (e.g. ./build web or ./buidl webtest). | ||
| 15 | # The images are given a tag starting with 'localhost/nissy/'. | ||
| 16 | # | ||
| 17 | # See below for a list of options. | ||
| 18 | |||
| 19 | usage() { | ||
| 20 | echo "$1" | ||
| 21 | echo "" | ||
| 22 | echo "usage: $0 PLATFORM [COMMAND]" | ||
| 23 | echo "" | ||
| 24 | echo "If COMMAND is unspecified, an interactive shell will be opened." | ||
| 25 | echo "" | ||
| 26 | echo "Available platforms:" | ||
| 27 | echo "x86 (equivalent to: x86_64, amd64)" | ||
| 28 | echo "arm (equivalent to: arm64)" | ||
| 29 | echo "" | ||
| 30 | echo "Examples:" | ||
| 31 | echo "$0 ram ./build test # Run unit tests in arm container" | ||
| 32 | exit 1 | ||
| 33 | } | ||
| 34 | |||
| 35 | if [ -z "$1" ]; then | ||
| 36 | usage "No platform given." | ||
| 37 | fi | ||
| 38 | |||
| 39 | case "$1" in | ||
| 40 | x86|x86_64|amd64) | ||
| 41 | p=amd64 | ||
| 42 | shift | ||
| 43 | ;; | ||
| 44 | arm|arm64) | ||
| 45 | p=arm64 | ||
| 46 | shift | ||
| 47 | ;; | ||
| 48 | *) | ||
| 49 | usage "Platform '$1' not available." | ||
| 50 | ;; | ||
| 51 | esac | ||
| 52 | |||
| 53 | image="localhost/nissy/alpine-$p" | ||
| 54 | platform="--platform=linux/$p" | ||
| 55 | mount="--mount type=bind,src=./,dst=/nissy-core" | ||
| 56 | flags="--rm --privileged" | ||
| 57 | |||
| 58 | dockerfile="$(mktemp)" | ||
| 59 | cat > "$dockerfile" << EOF | ||
| 60 | FROM alpine:3.22.1 | ||
| 61 | RUN apk update | ||
| 62 | RUN apk add gcc g++ clang python3 python3-dev | ||
| 63 | #COPY . ./nissy-core | ||
| 64 | RUN mkdir /nissy-core | ||
| 65 | WORKDIR /nissy-core | ||
| 66 | USER 1000:1000 | ||
| 67 | EOF | ||
| 68 | |||
| 69 | docker build "$platform" -f "$dockerfile" -t "$image" . | ||
| 70 | rm "$dockerfile" | ||
| 71 | |||
| 72 | if [ -z "$1" ]; then | ||
| 73 | docker run $flags $mount "$platform" -it "$image" /bin/sh | ||
| 74 | else | ||
| 75 | docker run $flags $mount "$platform" -t "$image" $@ | ||
| 76 | fi | ||
