-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsimplified_galaxy_stable_container_creation.sh
executable file
·287 lines (222 loc) · 10.5 KB
/
simplified_galaxy_stable_container_creation.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
# vi: fdm=marker
set -e
### Constants ###
SCRIPT_NAME="${0##*/}"
TRUE='true'
FALSE='false'
DFT_DOCKER_PUSH_ENABLED=$TRUE
### Functions ###
function log() {
echo -e "$@" >&2
}
function error {
local msg=$1
local code=$2
[[ -z $code ]] && code=1
log "[ERROR] $msg"
exit $code
}
function debug {
local msg=$1
local level=$2
[[ -n $level ]] || level=1
[[ $DEBUG -lt $level ]] || log "[DEBUG] $msg"
}
function warning {
local msg=$1
log "[WARNING] ##### $msg #####"
}
function print_help {
(
echo "Usage: $SCRIPT_NAME [options]"
echo
echo "Build PhenoMeNal Galaxy docker images."
echo
echo "Options:"
echo " -g, --debug Debug mode. [false]"
echo " -h, --help Print this help message."
echo " -p, --push Push docker images. You can also set environment variable DOCKER_PUSH_ENABLED to \"true\". [true]"
echo " +p, --no-push Do not push dockers. You can also set environment variable DOCKER_PUSH_ENABLED to \"false\"."
echo " --push-intermediate Also push intermediate images [false]"
echo " --no-cache Tell Docker not to use cached images. [false]"
echo " --init-tag <tag> Set the tag for the Galaxy Init Flavour container image."
echo " --postgres-tag <tag> Set the tag for the Galaxy Postgres container image."
echo " --proftpd-tag <tag> Set the tag for the Galaxy Proftpd container image."
echo " --web-tag <tag> Set the tag for the Galaxy Web k8s container image."
echo " -u, --container-user <user> Set the container user. You can also set the environment variable CONTAINER_USER. [pcm32]"
echo " -r, --container-registry <reg> Set the container registry. You can also set the environment variable CONTAINER_REGISTRY."
echo " --maintenance-build Build in maintence mode (build only init image from Dockerfile_init in repository)."
echo
) >&2
}
function read_args {
local args="$*" # save arguments for debugging purpose
# Read options
while [[ $# > 0 ]] ; do
shift_count=1
case $1 in
-g|--debug) DEBUG=$((DEBUG + 1)) ;;
-h|--help) print_help ; exit 0 ;;
-p|--push) DOCKER_PUSH_ENABLED=$TRUE ;;
+p|--no-push) DOCKER_PUSH_ENABLED=$FALSE ;;
--push-intermediate) PUSH_INTERMEDIATE_IMAGES=$TRUE ;;
--no-cache) NO_CACHE="--no-cache" ;;
--postgres-tag) OVERRIDE_POSTGRES_TAG="$2" ; shift_count=2 ;;
--proftpd-tag) OVERRIDE_PROFTPD_TAG="$2" ; shift_count=2 ;;
--init-tag) OVERRIDE_GALAXY_INIT_PHENO_FLAVOURED_TAG="$2" ; shift_count=2 ;;
--web-tag) OVERRIDE_GALAXY_WEB_K8S_TAG="$2" ; shift_count=2 ;;
-u|--container-user) CONTAINER_USER="$2" ; shift_count=2 ;;
-r|--container-registry) CONTAINER_REGISTRY="$2" ; shift_count=2 ;;
--maintenance-build) MAINTENANCE_BUILD=$TRUE ;;
*) error "Illegal option $1." 98 ;;
esac
shift $shift_count
done
# Debug messages
debug "Command line arguments: $args"
debug "Argument DEBUG=$DEBUG"
debug "Argument DOCKER_PUSH_ENABLED=$DOCKER_PUSH_ENABLED"
debug "Argument DOCKER_USER=$DOCKER_USER"
debug "Argument OVERRIDE_GALAXY_INIT_PHENO_FLAVOURED_TAG=$OVERRIDE_GALAXY_INIT_PHENO_FLAVOURED_TAG"
debug "Argument OVERRIDE_GALAXY_WEB_K8S_TAG=$OVERRIDE_GALAXY_WEB_K8S_TAG"
debug "Argument OVERRIDE_POSTGRES_TAG=$OVERRIDE_POSTGRES_TAG"
debug "Argument OVERRIDE_PROFTPD_TAG=$OVERRIDE_PROFTPD_TAG"
debug "Argument MAINTENANCE_BUILD=$MAINTENANCE_BUILD"
debug "shift_count=$shift_count"
}
function run_maintenance_build() {
docker build $NO_CACHE -t $GALAXY_INIT_PHENO_FLAVOURED_TAG -f $DOCKERFILE_INIT_FLAVOUR .
if [[ "${DOCKER_PUSH_ENABLED:-}" = "true" ]]; then
docker push $GALAXY_INIT_PHENO_FLAVOURED_TAG
fi
log "Relevant containers:"
echo "Init Flavour: $GALAXY_INIT_PHENO_FLAVOURED_TAG"
log "Web, Postgres and Proftpd containers were not updated. Use the previous ones."
}
function run_standard_build() {
if [ -n $ANSIBLE_REPO ]
then
log "Making custom galaxy-base-pheno:$TAG from $ANSIBLE_REPO at $ANSIBLE_RELEASE"
docker build $NO_CACHE --build-arg ANSIBLE_REPO=$ANSIBLE_REPO --build-arg ANSIBLE_RELEASE=$ANSIBLE_RELEASE -t $GALAXY_BASE_PHENO_TAG docker-galaxy-stable/compose/galaxy-base/
if [[ ! -z ${PUSH_INTERMEDIATE_IMAGES:-} ]];
then
log "Pushing intermediate image $DOCKER_REPO$DOCKER_USER/galaxy-base-pheno:$TAG"
docker push $GALAXY_BASE_PHENO_TAG
fi
fi
if [ -n $GALAXY_REPO ]
then
log "Making custom galaxy-init-pheno:$TAG from $GALAXY_REPO at $GALAXY_RELEASE"
DOCKERFILE_INIT_1=Dockerfile
if [ -n $ANSIBLE_REPO ]
then
sed s+$GALAXY_BASE_FROM_TO_REPLACE+$GALAXY_BASE_PHENO_TAG+ docker-galaxy-stable/compose/galaxy-init/Dockerfile > docker-galaxy-stable/compose/galaxy-init/Dockerfile_init
FROM=$(grep ^FROM docker-galaxy-stable/compose/galaxy-init/Dockerfile_init | awk '{ print $2 }')
log "Using FROM $FROM for galaxy init"
DOCKERFILE_INIT_1=Dockerfile_init
fi
docker build $NO_CACHE --build-arg GALAXY_REPO=$GALAXY_REPO --build-arg GALAXY_RELEASE=$GALAXY_RELEASE --build-arg ISATOOLS_LITE_INSTALL=True -t $GALAXY_INIT_PHENO_TAG -f docker-galaxy-stable/compose/galaxy-init/$DOCKERFILE_INIT_1 docker-galaxy-stable/compose/galaxy-init/
if [[ ! -z ${PUSH_INTERMEDIATE_IMAGES:-} ]];
then
log "Pushing intermediate image $GALAXY_INIT_PHENO_TAG"
docker push $GALAXY_INIT_PHENO_TAG
fi
fi
if [ -n $GALAXY_REPO ]
then
log "Making custom galaxy-init-pheno-flavoured:$TAG starting from galaxy-init-pheno:$TAG"
sed s+pcm32/galaxy-init-pheno$+$GALAXY_INIT_PHENO_TAG+ $DOCKERFILE_INIT_FLAVOUR > Dockerfile_init_tagged
DOCKERFILE_INIT_FLAVOUR=Dockerfile_init_tagged
fi
docker build $NO_CACHE -t $GALAXY_INIT_PHENO_FLAVOURED_TAG -f $DOCKERFILE_INIT_FLAVOUR .
if [[ "${DOCKER_PUSH_ENABLED:-}" = "true" ]]; then
docker push $GALAXY_INIT_PHENO_FLAVOURED_TAG
fi
if [ -n $GALAXY_REPO ]
then
log "Making custom galaxy-web-k8s:$TAG from $GALAXY_REPO at $GALAXY_RELEASE"
sed s+$GALAXY_BASE_FROM_TO_REPLACE+$GALAXY_BASE_PHENO_TAG+ docker-galaxy-stable/compose/galaxy-web/Dockerfile > docker-galaxy-stable/compose/galaxy-web/Dockerfile_web
DOCKERFILE_WEB=Dockerfile_web
fi
docker build $NO_CACHE --build-arg GALAXY_ANSIBLE_TAGS=supervisor,startup,scripts,nginx,k8,k8s -t $GALAXY_WEB_K8S_TAG -f docker-galaxy-stable/compose/galaxy-web/$DOCKERFILE_WEB docker-galaxy-stable/compose/galaxy-web/
if [[ "${DOCKER_PUSH_ENABLED:-}" = "true" ]]; then
docker push $GALAXY_WEB_K8S_TAG
fi
# Build postgres
docker build -t $POSTGRES_TAG -f docker-galaxy-stable/compose/galaxy-postgres/Dockerfile docker-galaxy-stable/compose/galaxy-postgres/
if [[ "${DOCKER_PUSH_ENABLED:-}" = "true" ]]; then
docker push $POSTGRES_TAG
fi
# Build proftpd
docker build -t $PROFTPD_TAG -f docker-galaxy-stable/compose/galaxy-proftpd/Dockerfile docker-galaxy-stable/compose/galaxy-proftpd/
if [[ "${DOCKER_PUSH_ENABLED:-}" = "true" ]]; then
docker push $PROFTPD_TAG
fi
log "Relevant containers:"
echo "Web: $GALAXY_WEB_K8S_TAG"
echo "Init Flavour: $GALAXY_INIT_PHENO_FLAVOURED_TAG"
echo "Postgres: $POSTGRES_TAG"
echo "Proftpd: $PROFTPD_TAG"
}
function main() {
read_args "$@"
DOCKER_PUSH_ENABLED=${DOCKER_PUSH_ENABLED:-$DFT_DOCKER_PUSH_ENABLED}
DOCKER_REPO=${CONTAINER_REGISTRY:-}
DOCKER_USER=${CONTAINER_USER:-pcm32}
ANSIBLE_REPO=galaxyproject/ansible-galaxy-extras
ANSIBLE_RELEASE=18.01-k8s
GALAXY_BASE_FROM_TO_REPLACE=quay.io/bgruening/galaxy-base:18.01
GALAXY_REPO=phnmnl/galaxy
GALAXY_RELEASE=release_18.01_plus_isa_runnerRJ_clean
GALAXY_VER_FOR_POSTGRES=18.01
# Default tag. Note that this is overridden if CONTAINER_TAG_PREFIX and BUILD_NUMBER are set
TAG=v18.01-pheno-dev
if [[ -n ${CONTAINER_TAG_PREFIX:-} && -n ${BUILD_NUMBER:-} ]]; then
TAG=${CONTAINER_TAG_PREFIX}.${BUILD_NUMBER}
fi
DOCKERFILE_INIT_FLAVOUR=Dockerfile_init
DOCKERFILE_WEB=Dockerfile
if [[ -n "${DOCKER_REPO}" ]]; then
# Append slash, avoiding double slash
DOCKER_REPO="${DOCKER_REPO%/}/"
fi
GALAXY_BASE_PHENO_TAG=$DOCKER_REPO$DOCKER_USER/galaxy-base-pheno:$TAG
GALAXY_INIT_PHENO_TAG=$DOCKER_REPO$DOCKER_USER/galaxy-init-pheno:$TAG
### Set tags ###
if [[ -n "${OVERRIDE_GALAXY_INIT_PHENO_FLAVOURED_TAG:-}" ]]; then
GALAXY_INIT_PHENO_FLAVOURED_TAG="${OVERRIDE_GALAXY_INIT_PHENO_FLAVOURED_TAG}"
else
GALAXY_INIT_PHENO_FLAVOURED_TAG=$DOCKER_REPO$DOCKER_USER/galaxy-init-pheno-flavoured:$TAG
fi
if [[ -n "${OVERRIDE_GALAXY_WEB_K8S_TAG:-}" ]]; then
GALAXY_WEB_K8S_TAG="${OVERRIDE_GALAXY_WEB_K8S_TAG}"
else
GALAXY_WEB_K8S_TAG=$DOCKER_REPO$DOCKER_USER/galaxy-web-k8s:$TAG
fi
if [[ -n "${OVERRIDE_POSTGRES_TAG:-}" ]]; then
POSTGRES_TAG="${OVERRIDE_POSTGRES_TAG}"
else
PG_Dockerfile="docker-galaxy-stable/compose/galaxy-postgres/Dockerfile"
[[ -f "${PG_Dockerfile}" ]] || error "The galaxy-postgres Dockerfile is missing under docker-galaxy-stable/. Have you updated the repository submodules?" 99
POSTGRES_VERSION=$(grep FROM "${PG_Dockerfile}" | awk -F":" '{ print $2 }')
POSTGRES_TAG=$DOCKER_REPO$DOCKER_USER/galaxy-postgres:$POSTGRES_VERSION"_for_"$GALAXY_VER_FOR_POSTGRES
fi
if [[ -n "${OVERRIDE_PROFTPD_TAG:-}" ]]; then
PROFTPD_TAG="${OVERRIDE_PROFTPD_TAG}"
else
PROFTPD_TAG=$DOCKER_REPO$DOCKER_USER/galaxy-proftpd:for_galaxy_v$GALAXY_VER_FOR_POSTGRES
fi
if [[ -n "${MAINTENANCE_BUILD:-}" ]]; then
run_maintenance_build
else
run_standard_build
fi
if [[ "${DOCKER_PUSH_ENABLED:-}" != "true" ]]; then
log "Container images not pushed. They are only available in your current Docker daemon"
fi
}
### MAIN ###
if [[ "${BASH_SOURCE}" == "${0}" ]]; then
main "${@}"
fi