aboutsummaryrefslogtreecommitdiff
path: root/container-run.sh
diff options
context:
space:
mode:
Diffstat (limited to 'container-run.sh')
-rwxr-xr-xcontainer-run.sh57
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
14usage() {
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
30if [ -z "$1" ]; then
31 usage "No platform given."
32fi
33
34case "$1" in
35x86|x86_64|amd64)
36 p=amd64
37 shift
38 ;;
39arm|arm64)
40 p=arm64
41 shift
42 ;;
43*)
44 usage "Platform '$1' not available."
45 ;;
46esac
47
48platform="--platform=linux/$p"
49image="localhost/nissy/alpine-$p"
50
51docker build "$platform" -t "$image" .
52
53if [ -z "$2" ]; then
54 docker run "$platform" -it "$image" /bin/sh
55else
56 docker run "$platform" -t "$image" $@
57fi

Generated with cgit - Back to sebastiano.tronto.net