aboutsummaryrefslogtreecommitdiff
path: root/utils/container-run.sh
diff options
context:
space:
mode:
Diffstat (limited to 'utils/container-run.sh')
-rwxr-xr-xutils/container-run.sh76
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
19usage() {
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
35if [ -z "$1" ]; then
36 usage "No platform given."
37fi
38
39case "$1" in
40x86|x86_64|amd64)
41 p=amd64
42 shift
43 ;;
44arm|arm64)
45 p=arm64
46 shift
47 ;;
48*)
49 usage "Platform '$1' not available."
50 ;;
51esac
52
53image="localhost/nissy/alpine-$p"
54platform="--platform=linux/$p"
55mount="--mount type=bind,src=./,dst=/nissy-core"
56flags="--rm --privileged"
57
58dockerfile="$(mktemp)"
59cat > "$dockerfile" << EOF
60FROM alpine:3.22.1
61RUN apk update
62RUN apk add gcc g++ clang python3 python3-dev
63#COPY . ./nissy-core
64RUN mkdir /nissy-core
65WORKDIR /nissy-core
66USER 1000:1000
67EOF
68
69docker build "$platform" -f "$dockerfile" -t "$image" .
70rm "$dockerfile"
71
72if [ -z "$1" ]; then
73 docker run $flags $mount "$platform" -it "$image" /bin/sh
74else
75 docker run $flags $mount "$platform" -t "$image" $@
76fi

Generated with cgit - Back to sebastiano.tronto.net