-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdocker
executable file
·288 lines (266 loc) · 8.24 KB
/
docker
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
288
#!/bin/bash
set -e
set -u
##
## Bash configuration
##
. .omero/utils
if [ -f .omeroci/env ]; then
. .omeroci/env
fi
export ACTION=${ACTION:-""}
export TRAVIS=${TRAVIS:-"false"}
export VERBOSE=${VERBOSE:-"set +x"}
export PROJECT=${PROJECT:-$(get_project_name)}
export NETWORK=${NETWORK:-"$PROJECT"_default}
export TARGET=/$(basename $PWD)
export NOCLEAN=${NOCLEAN:-"false"}
export LOGS=${LOGS:-"false"}
export PLUGIN=${PLUGIN:-}
export POLICY_BINARY_ACCESS=${POLICY_BINARY_ACCESS:-+read,+write,+image}
if [ $# -eq 0 ]; then
echo "docker [stage [stage [stage]]]"
echo
echo "Stages:"
echo " app - installs plugin into OMERO.web"
echo " cli - installs plugin into OMERO.server"
echo " lib - builds and runs client-side library"
echo " scripts - installs OMERO.scripts into OMERO.server"
echo
echo "Environment variables:"
echo " PROJECT - name of the docker-compose project ($PROJECT)"
echo " NETWORK - name of the docker network to use ($NETWORK)"
echo " TARGET - name of the component being installed ($TARGET)"
echo " ACTION - use 'echo' to perform a dry-run ($ACTION)"
echo " TRAVIS - whether to print travis_folds ($TRAVIS)"
echo " VERBOSE - set to 'set -x' to see all actions ($VERBOSE)"
echo " NOCLEAN - set to 'true' to prevent container cleanup"
echo " LOGS - set to 'true' to print logs on cleanup"
echo " PLUGIN - name of the plugin (optional) ($PLUGIN)"
echo
echo "Development mode:"
echo " dev ... - run an internal command with args"
echo " dev sh - start a shell inside the server container"
exit 2
elif [ "$1" = dev ]; then
STAGES=dev
shift
else
STAGES="$@"
fi
$VERBOSE
start_up() {
if "$NOCLEAN" in true 1; then
echo "Keeping servers running"
else
clean_up() {
if [ "$LOGS" == "true" ]; then
$ACTION .omero/compose logs
fi
$ACTION .omero/compose down -v
}
trap clean_up EXIT
fi
$ACTION .omero/compose up -d --force-recreate "$@"
}
##
## Stages
##
fold() {
if [ "$TRAVIS" == "true" ]; then
printf "travis_fold:$1:$2\n"
fi
}
run() {
# Primary task which uses the first two arguments to either:
# 1) run .omeroci/$1-$2 if it exists, or
# 2) run the default script in this directory of the same name.
LOCAL=false
CALLAS="-u root"
if [ $1 == "--local" ]; then
LOCAL=true
shift
elif [ $1 == "--user" ]; then
CALLAS="-u $USER"
shift
fi
type=$1
name=$2
file="$1-$2"
var="DONE_${CID}_$(echo $1| tr /a-z/ /A-Z/)_$(echo $2 | tr /a-z/ /A-Z/)"
eval "$var=\${$var:-0}"
if [ "${!var}" == "1" ]; then
echo "$file already run for $CID"
else
eval "$var=1"
fold start $file
if [ -e .omeroci/$file ]; then
PREFIX=/$TARGET
LOCALPREFIX="."
ARGUMENT=.omeroci/$file
elif [ -e $(dirname "$0")/$file ]; then
PREFIX=/infra
LOCALPREFIX=".omero"
ARGUMENT=$file
elif [ -e $(dirname "$0")/$STAGE-$name ]; then
PREFIX=/infra
LOCALPREFIX=".omero"
ARGUMENT=$STAGE-$name
else
echo "No script found:"
echo " .omeroci/$file"
echo " $(dirname "$0")/$file"
echo " $(dirname "$0")/$STAGE-$name"
return 2
fi
if [ "$LOCAL" == true ]; then
$ACTION $LOCALPREFIX/$ARGUMENT
else
$ACTION docker exec $CALLAS \
-e TARGET=$TARGET -e PLUGIN=$PLUGIN \
-e OMERO_DIST=$OMERO_DIST \
-e OMERODIR=$OMERO_DIST \
-e VIRTUAL_ENV=/opt/omero/$COMPONENT/venv3 \
$CID $PREFIX/$ARGUMENT
fi
fold end $file
fi
}
install() {
if [ $# -eq 0 ] || [ $1 != "--nosrc" ]; then
$ACTION docker cp -L . $CID:/$TARGET
$ACTION docker exec -u root -e TARGET=$TARGET $CID sh -c "chown -R $USER:$USER $TARGET"
fi
$ACTION docker cp -L .omero $CID:/infra
$ACTION docker exec -u root $CID sh -c "chown -R $USER:$USER /infra"
}
java() {
$ACTION docker exec -e USER_AGENT=Travis -u root $CID mkdir -p /opt/omero/$COMPONENT/OMERO.$COMPONENT/lib # Web!
$ACTION docker exec -e USER_AGENT=Travis -u root $CID /opt/omero/$COMPONENT/venv3/bin/pip install omego
$ACTION docker exec -e USER_AGENT=Travis -u root $CID /opt/omero/$COMPONENT/venv3/bin/omego download java --sym /opt/omero/java
$ACTION docker exec -u root $CID ln -s /opt/omero/java/libs /opt/omero/web/OMERO.web/lib/client
}
wait_on_login() {
OMERO_HOST="-e OMERO_HOST=omero"
if [ $# -gt 0 ] && [ $1 == "--localhost" ]; then
OMERO_HOST=""
shift
fi
$ACTION docker exec $OMERO_HOST $CID /opt/omero/$COMPONENT/venv3/bin/python /infra/wait-on-login
}
sh() {
$ACTION docker exec -it $CID bash
}
get_cid(){
docker ps -q \
--filter label=com.docker.compose.project=${PROJECT} \
--filter label=com.docker.compose.service=$1
}
##
## RUN STAGES
##
for STAGE in $STAGES; do
export $STAGE
case "$STAGE" in
app)
export COMPONENT=web
export USER=omero-web
export OMERO_DIST="/opt/omero/web/OMERO.web"
start_up
export CID=$(get_cid web)
install
java
run app deps || echo ignore
# As the only web-container action
# give the app a chance to modify
# the docker container. This may
# need to be formalized later.
(
COMPONENT=server
USER=omero-server
OMERO_DIST="/opt/omero/server/OMERO.server"
CID=$(get_cid omero)
install
run app srv || echo ignore
)
wait_on_login
run py common
run py check
run py setup
run app config
run --user app build
;;
cli)
export COMPONENT=server
export USER=omero-server
export OMERO_DIST="/opt/omero/server/OMERO.server"
start_up
export CID=$(get_cid omero)
install
wait_on_login
run py common
run py check
run py setup
run --user cli build
;;
lib)
export COMPONENT=server
export USER=omero-server
export OMERO_DIST="/opt/omero/server/OMERO.server"
start_up
export CID=$(get_cid omero)
install
run --local lib build
wait_on_login
run --user test data || echo ignore
run --local lib test
;;
scripts)
export COMPONENT=server
export USER=omero-server
export OMERO_DIST="/opt/omero/server/OMERO.server"
start_up
export CID=$(get_cid omero)
install
run scripts deps || echo ignore
run py common
run py check
run py setup
run scripts copy
wait_on_login
run --user test data || echo ignore
run py common
run --user scripts build
;;
srv)
export COMPONENT=server
export USER=omero-server
export COMPOSE_FILE=${COMPOSE_FILE:-"srv-compose.yml"}
export OMERO_DIST="/opt/omero/server/OMERO.server"
export TARGET=/src
start_up
export CID=$(get_cid omero)
install --nosrc
wait_on_login --localhost
# Now that the server is running, test it
export USER=1000
export CID=$(get_cid test)
export TARGET="/src"
export OMERO_DIST="/src/dist"
install --nosrc
run --user srv test
;;
dev)
export COMPONENT=server
export USER=omero-server
export CID=$(get_cid omero)
export OMERO_DIST="/opt/omero/server/OMERO.server"
export NOCLEAN=true
"$@"
;;
*)
echo "Unknown stage: $STAGE"
exit 2
;;
esac
done