forked from mathinstitut/goemaxima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildimage.sh
executable file
·49 lines (45 loc) · 1.68 KB
/
buildimage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# This script builds the Docker container for a particular version of STACK.
#
# It should be run with one, two or three arguments:
# arg1: the vesrion of the stackmaxima code. This is looked up in the 'versions' file
# to find the corresponding SBCL and Maxima versions to use.
# arg2: (optional) REGISTRY or dockerhub id to use. If given, teh built container is pushed there with tag -dev.
# arg3: (optional) if given, the built image is also pushed with this tag, and also -latest.
stackver="$1"
if [ -z "$stackver" ]; then
echo "Stack version is missing"
echo "Usage: $0 stackmaximaversion [registry] [containerversion]"
exit 1
fi
verstring=$(awk '$1 == "'"$1"'"{ print $0 }' versions)
maximaver="$(echo "$verstring" | cut -f2)"
sbclver="$(echo "$verstring" | cut -f3)"
goemaxver="$(cat goemaxima_version)"
libpath="stack/$stackver/maxima"
echo "starting to build image for:"
echo "Maxima: $maximaver"
echo "SBCL: $sbclver"
echo "stackmaxima: $stackver"
echo "goemaxima: $goemaxver"
REG="$2"
IMAGENAME="goemaxima:$1"
CACHE_ARG=""
if [ -n "$REG" ]; then
docker pull "$2/$IMAGENAME-dev"
CACHE_ARG="--cache-from=$2/$IMAGENAME-dev"
fi
# build it
DOCKER_BUILDKIT=1 docker build -t "${IMAGENAME}-dev" $CACHE_ARG --build-arg MAXIMA_VERSION="$maximaver" --build-arg SBCL_VERSION="$sbclver" --build-arg LIB_PATH="$libpath" . || exit 1
echo "${IMAGENAME} was built successfully."
# push the image
if [ -n "$REG" ]; then
docker tag "$IMAGENAME-dev" "$2/$IMAGENAME-dev"
docker push "$2/$IMAGENAME-dev"
if [ -n "$3" ]; then
docker tag "$IMAGENAME-dev" "$2/$IMAGENAME-$3"
docker push "$2/$IMAGENAME-$3"
docker tag "$IMAGENAME-dev" "$2/$IMAGENAME-latest"
docker push "$2/$IMAGENAME-latest"
fi
fi