nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

container-run.sh (2204B)


      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.sh 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.sh web or ./build.sh 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 "emscripten"
     30 	echo ""
     31 	echo "Examples:"
     32 	echo "$0 ram ./build.sh test   # Run unit tests in arm container"
     33 	exit 1
     34 }
     35 
     36 if [ -z "$1" ]; then
     37 	usage "No platform given."
     38 fi
     39 
     40 config_standard() {
     41 	image="localhost/nissy/alpine-$1"
     42 	platform="--platform=linux/$1"
     43 	mount="--mount type=bind,src=./,dst=/nissy-core"
     44 	flags="--rm --privileged"
     45 
     46 	dockerfile="$(mktemp)"
     47 	cat > "$dockerfile" << EOF
     48 	FROM alpine:3.22
     49 	RUN apk update
     50 	RUN apk add gcc g++ clang python3 python3-dev
     51 	RUN mkdir /nissy-core
     52 	WORKDIR /nissy-core
     53 	USER 1000:1000
     54 EOF
     55 }
     56 
     57 config_emscripten() {
     58 	image="localhost/nissy/emscripten"
     59 	platform="--platform=linux/amd64"
     60 	mount="--mount type=bind,src=./,dst=/nissy-core"
     61 	flags="--rm --privileged"
     62 
     63 	dockerfile="$(mktemp)"
     64 	cat > "$dockerfile" << EOF
     65 	FROM emscripten/emsdk
     66 	WORKDIR /nissy-core
     67 	USER 1000:1000
     68 EOF
     69 }
     70 
     71 case "$1" in
     72 x86|x86_64|amd64)
     73 	config_standard amd64
     74 	shift
     75 	;;
     76 arm|arm64)
     77 	config_standard arm64
     78 	shift
     79 	;;
     80 emscripten)
     81 	config_emscripten
     82 	shift
     83 	;;
     84 *)
     85 	usage "Platform '$1' not available."
     86 	;;
     87 esac
     88 
     89 docker build "$platform" -f "$dockerfile" -t "$image" .
     90 rm "$dockerfile"
     91 
     92 if [ -z "$1" ]; then 
     93 	docker run $flags $mount "$platform" -it "$image" /bin/sh
     94 else
     95 	docker run $flags $mount "$platform" -t "$image" $@
     96 fi