forked from PecanProject/pecan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.sh
executable file
·197 lines (173 loc) · 6.61 KB
/
docker.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Use docker.sh -h for instructions on how to use this script.
# exit script if error occurs (-e) in any command of pipeline (pipefail)
set -o pipefail
set -e
cd $(dirname $0)
# Can set the following variables
DEBUG=${DEBUG:-""}
DEPEND=${DEPEND:-""}
R_VERSION=${R_VERSION:-"3.5"}
# --------------------------------------------------------------------------------
# PECAN BUILD SECTION
# --------------------------------------------------------------------------------
# some git variables
PECAN_GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
PECAN_GIT_CHECKSUM="$(git log --pretty=format:%H -1)"
PECAN_GIT_DATE="$(git log --pretty=format:%ad -1)"
# get version number
VERSION=${VERSION:-"$(awk '/Version:/ { print $2 }' base/all/DESCRIPTION)"}
# check for branch and set IMAGE_VERSION
if [ "${PECAN_GIT_BRANCH}" == "master" ]; then
IMAGE_VERSION=${IMAGE_VERSION:-"latest"}
elif [ "${PECAN_GIT_BRANCH}" == "develop" ]; then
IMAGE_VERSION=${IMAGE_VERSION:-"develop"}
else
IMAGE_VERSION=${IMAGE_VERSION:-"testing"}
fi
# read command line options, overriding any environment variables
while getopts dfhi:r: opt; do
case $opt in
d)
DEBUG="echo"
;;
f)
DEPEND="build"
;;
h)
cat << EOF
$0 [-dfh] [-i <IMAGE_VERSION>] [-r <R VERSION]
The following script can be used to create all docker images. Without any
options this will build all images and tag them based on the branch you
are on. The master branch will be tagged with latest, develop branch will
be tagged with develop and any other branch will be tagged with testing.
Most options can be set using either an environment variable or using
command line options. If both are set, the command line options will
override the environmnet variables.
You can change the docker image tag using the environment variable
IMAGE_VERSION or the option -i.
To run the script in debug mode without actually building any images you
can use the environment variable DEBUG or option -d.
By default the docker.sh process will try and use a prebuild dependency
image since this image takes a long time to build. To force this image
to be build use the DEPEND="build" environment flag, or use option -f.
To set the version used of R when building the dependency image use
the environment option R_VERSION (as well as DEPEND). You can also use
the -r option which will make sure the dependency image is build.
You can use the FROM_IMAGE environment variable to also specify what
image should be used when building the base image. You can for example
use the previous base image which will speed up the compile process of
PEcAn.
EOF
exit 1
;;
i)
IMAGE_VERSION="$OPTARG"
;;
n)
DEBUG="echo"
;;
r)
R_VERSION="$OPTARG"
DEPEND="build"
;;
esac
done
# information for user before we build things
echo "# ----------------------------------------------------------------------"
echo "# Building PEcAn"
echo "# PECAN_VERSION : ${VERSION}"
echo "# PECAN_GIT_BRANCH : ${PECAN_GIT_BRANCH}"
echo "# PECAN_GIT_DATE : ${PECAN_GIT_DATE}"
echo "# PECAN_GIT_CHECKSUM : ${PECAN_GIT_CHECKSUM}"
echo "# IMAGE_VERSION : ${IMAGE_VERSION}"
echo "#"
echo "# Created images will be tagged with '${IMAGE_VERSION}'. If you want to"
echo "# test this build you can use:"
echo "# PECAN_VERSION='${IMAGE_VERSION}' docker-compose up"
echo "#"
echo "# The docker image for dependencies takes a long time to build. You"
echo "# can use a prebuild version (default) or force a new versin to be"
echo "# build locally using: DEPEND=build $0"
echo "# ----------------------------------------------------------------------"
# not building dependencies image, following command will build this
if [ "${DEPEND}" == "build" ]; then
${DEBUG} docker build \
--build-arg R_VERSION=${R_VERSION} \
--tag pecan/depends:${IMAGE_VERSION} \
docker/depends
else
if [ "$( docker image ls -q pecan/depends:${IMAGE_VERSION} )" == "" ]; then
if [ "${PECAN_GIT_BRANCH}" != "master" ]; then
if [ "$( docker image ls -q pecan/depends:develop )" == "" ]; then
${DEBUG} docker pull pecan/depends:develop
fi
if [ "${IMAGE_VERSION}" != "develop" ]; then
${DEBUG} docker tag pecan/depends:develop pecan/depends:${IMAGE_VERSION}
fi
else
if [ "$( docker image ls -q pecan/depends:latest )" == "" ]; then
${DEBUG} docker pull pecan/depends:latest
fi
if [ "${IMAGE_VERSION}" != "latest" ]; then
${DEBUG} docker tag pecan/depends:latest pecan/depends:${IMAGE_VERSION}
fi
fi
fi
fi
echo ""
# require all of PEcAn to build
for x in base web docs; do
${DEBUG} docker build \
--tag pecan/$x:${IMAGE_VERSION} \
--build-arg FROM_IMAGE="${FROM_IMAGE:-depends}" \
--build-arg IMAGE_VERSION="${IMAGE_VERSION}" \
--build-arg PECAN_VERSION="${VERSION}" \
--build-arg PECAN_GIT_BRANCH="${PECAN_GIT_BRANCH}" \
--build-arg PECAN_GIT_CHECKSUM="${PECAN_GIT_CHECKSUM}" \
--build-arg PECAN_GIT_DATE="${PECAN_GIT_DATE}" \
--file docker/$x/Dockerfile \
.
done
# all files in subfolder
for x in models executor data thredds monitor rstudio-nginx; do
${DEBUG} docker build \
--tag pecan/$x:${IMAGE_VERSION} \
--build-arg IMAGE_VERSION="${IMAGE_VERSION}" \
docker/$x
done
# --------------------------------------------------------------------------------
# MODEL BUILD SECTION
# --------------------------------------------------------------------------------
# build biocro
for version in 0.95; do
${DEBUG} docker build \
--tag pecan/model-biocro-${version}:${IMAGE_VERSION} \
--build-arg MODEL_VERSION="${version}" \
--build-arg IMAGE_VERSION="${IMAGE_VERSION}" \
models/biocro
done
# build ed2
for version in git; do
${DEBUG} docker build \
--tag pecan/model-ed2-${version}:${IMAGE_VERSION} \
--build-arg MODEL_VERSION="${version}" \
--build-arg IMAGE_VERSION="${IMAGE_VERSION}" \
models/ed
done
# build maespa
for version in git; do
${DEBUG} docker build \
--tag pecan/model-maespa-${version}:${IMAGE_VERSION} \
--build-arg MODEL_VERSION="${version}" \
--build-arg IMAGE_VERSION="${IMAGE_VERSION}" \
models/maespa
done
# build sipnet
for version in git r136; do
${DEBUG} docker build \
--tag pecan/model-sipnet-${version}:${IMAGE_VERSION} \
--build-arg MODEL_VERSION="${version}" \
--build-arg IMAGE_VERSION="${IMAGE_VERSION}" \
models/sipnet
done