diff --git a/build.py b/build.py deleted file mode 100755 index 870834f..0000000 --- a/build.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -# Helper script for building omero-grid Dockerfiles -# Could use docker-py instead? - -import argparse -import subprocess -import os -import re -import sys - - -parser = argparse.ArgumentParser( - description='Build and tag omero-grid Docker images. ' - 'The tag will be based on any non-default parameters passed.') -parser.add_argument('image', help='Folder containing Dockerfile') -parser.add_argument('--release', default='latest', help='Release or branch') -parser.add_argument('--ci', help='CI server address') -parser.add_argument('--omego', help='Additional omego arguments') -parser.add_argument( - '--no-cache', action='store_true', help='Build without Docker cache') -parser.add_argument( - '--tag', help='The full name/tag for the image, overrides all other naming') - - -args = parser.parse_args() -cmdline = ['docker', 'build'] - -image = os.path.basename(args.image) - -user = 'openmicroscopy' -if args.ci: - cmdline.extend(['--build-arg', 'CI_SERVER=%s' % args.ci]) - user = re.match('(\w+://)?([^/]+)', args.ci, re.I).group(2) - user = re.subn('[^\w]+', '-', user)[0] - -if args.release: - cmdline.extend(['--build-arg', 'OMERO_VERSION=%s' % args.release]) - -name = image -if args.omego: - cmdline.extend(['--build-arg', 'OMEGO_ARGS=%s' % args.omego]) - name = 'X-%s' % image - -if args.no_cache: - cmdline.append('--no-cache') - -if args.tag: - tag = args.tag -else: - tag = '%s/%s:%s' % (user, name, args.release) -tag = tag.lower() - -cmdline.extend(['-t', tag]) -cmdline.append(image) - -print 'Running: %s' % ' '.join(cmdline) -rc = subprocess.call(cmdline) -if rc: - sys.stderr.write('ERROR: Non-zero return code: %d: rc\n' % rc) -else: - print 'Built: %s' % tag -sys.exit(rc) diff --git a/master/70-grid-xml.sh b/master/70-grid-xml.sh new file mode 100755 index 0000000..82947e2 --- /dev/null +++ b/master/70-grid-xml.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -eu + +omero=/opt/omero/server/OMERO.server/bin/omero +cd /opt/omero/server + +# Args are the servers to run, default (no args) is to run all +./process_defaultxml.py OMERO.server/etc/templates/grid/default.xml.orig \ + "$@" > OMERO.server/etc/templates/grid/default.xml + +MASTER_IP=$(hostname -i) +$omero config set omero.master.host "$MASTER_IP" diff --git a/master/Dockerfile b/master/Dockerfile new file mode 100644 index 0000000..f3e6628 --- /dev/null +++ b/master/Dockerfile @@ -0,0 +1,15 @@ +# TODO: Switch to openmicroscopy/omero-server when it's merged +FROM test-omero-server +MAINTAINER ome-devel@lists.openmicroscopy.org.uk + +USER root +ADD process_defaultxml.py /opt/omero/server/ +ADD 70-grid-xml.sh /startup/ + +USER omero-server + +# default.xml may be modified at runtime for a multinode configuration +RUN cp /opt/omero/server/OMERO.server/etc/templates/grid/default.xml /opt/omero/server/OMERO.server/etc/templates/grid/default.xml.orig + +# TODO: Don't expose 4061 (internal links only) +EXPOSE 4061 4063 4064 diff --git a/omero-grid/process_defaultxml.py b/master/process_defaultxml.py similarity index 100% rename from omero-grid/process_defaultxml.py rename to master/process_defaultxml.py diff --git a/slave/99-run.sh b/slave/99-run.sh new file mode 100755 index 0000000..566d28b --- /dev/null +++ b/slave/99-run.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -eu + +TARGET="${1}" +if [ -z "$TARGET" ]; then + echo "ERROR: Slave-name required" + exit 2 +fi + +omero=/opt/omero/server/OMERO.server/bin/omero +cd /opt/omero/server + +CONFIG_omero_master_host=${CONFIG_omero_master_host:-} +if [ -n "$CONFIG_omero_master_host" ]; then + MASTER_ADDR="$CONFIG_omero_master_host" +else + MASTER_ADDR=master + $omero config set omero.master.host "$MASTER_ADDR" +fi + +SLAVE_ADDR=$(hostname -i) + +# Is this needed on a slave? +#if stat -t /config/* > /dev/null 2>&1; then +# for f in /config/*; do +# echo "Loading $f" +# $omero load "$f" +# done +#fi + +echo "Master addr: $MASTER_ADDR Slave addr: $SLAVE_ADDR" +sed -e "s/@omero.slave.host@/$SLAVE_ADDR/" -e "s/@slave.name@/$TARGET/" \ + slave.cfg > OMERO.server/etc/$TARGET.cfg +grep '^Ice.Default.Router=' OMERO.server/etc/ice.config || \ + echo Ice.Default.Router= >> OMERO.server/etc/ice.config +sed -i -r "s|^(Ice.Default.Router=).*|\1OMERO.Glacier2/router:tcp -p 4063 -h $MASTER_ADDR|" \ + OMERO.server/etc/ice.config + +echo "Starting node $TARGET" +exec $omero node $TARGET start --foreground diff --git a/slave/Dockerfile b/slave/Dockerfile new file mode 100644 index 0000000..b2d9afc --- /dev/null +++ b/slave/Dockerfile @@ -0,0 +1,15 @@ +# TODO: Switch to openmicroscopy/omero-server when it's merged +FROM test-omero-server +MAINTAINER ome-devel@lists.openmicroscopy.org.uk + +USER root +ADD slave.cfg /opt/omero/server/ +# Don't configure database in a slave +RUN rm /startup/60-database.sh +# Replace existing 99-run.sh +ADD 99-run.sh /startup/ + +USER omero-server + +# TODO: Not needed? +EXPOSE 4063 4064 diff --git a/omero-grid/slave.cfg b/slave/slave.cfg similarity index 100% rename from omero-grid/slave.cfg rename to slave/slave.cfg diff --git a/test.sh b/test.sh index 973a7d1..425bc54 100755 --- a/test.sh +++ b/test.sh @@ -2,19 +2,15 @@ set -e set -u -set -x -PREFIX=omero-grid-test -IMAGE=omero-grid:$PREFIX -IMAGEWEB=omero-grid-web:$PREFIX -BUILD=${BUILD:-} -CLEAN=${CLEAN:-y} +PREFIX=test +IMAGEMASTER=omero-master:$PREFIX +IMAGESLAVE=omero-slave:$PREFIX -# Script must be run from omero-grid/ -cd "$(dirname $0)" +CLEAN=${CLEAN:-y} cleanup() { - docker rm -f -v $PREFIX-db $PREFIX-master $PREFIX-slave-1 $PREFIX-web + docker rm -f -v $PREFIX-db $PREFIX-server $PREFIX-slave-1 } if [ "$CLEAN" = y ]; then @@ -23,29 +19,32 @@ fi cleanup || true -# From the README -./build.py --tag $IMAGE $BUILD omero-grid -./build.py --tag $IMAGEWEB $BUILD omero-grid-web + +docker build -t $IMAGEMASTER master +docker build -t $IMAGESLAVE slave docker run -d --name $PREFIX-db -e POSTGRES_PASSWORD=postgres postgres -docker run -d --name $PREFIX-master --link $PREFIX-db:db \ - -e DBUSER=postgres -e DBPASS=postgres -e DBNAME=postgres $IMAGE master \ +docker run -d --name $PREFIX-server --link $PREFIX-db:db \ + -p 4063:4063 -p 4064:4064 \ + -e CONFIG_omero_db_user=postgres \ + -e CONFIG_omero_db_pass=postgres \ + -e CONFIG_omero_db_name=postgres \ + -e ROOTPASS=omero-root-password \ + $IMAGEMASTER \ master:Blitz-0,Indexer-0,DropBox,MonitorServer,FileServer,Storm,PixelData-0,Tables-0 \ slave-1:Processor-0 -docker run -d --name $PREFIX-slave-1 --link $PREFIX-master:master $IMAGE slave-1 -docker run -d --name $PREFIX-web --link $PREFIX-master:master -P $IMAGEWEB - -echo "Exposed web port:" -docker port $PREFIX-web +docker run -d --name $PREFIX-slave-1 --link $PREFIX-server:master $IMAGESLAVE slave-1 # Smoke tests export OMERO_USER=root -export OMERO_PASS=omero +export OMERO_PASS=omero-root-password export PREFIX -# Login to web +# Login to server bash test_login.sh +# Wait a minute to ensure other servers are running +sleep 60 # Now that we know the server is up, test Dropbox bash test_dropbox.sh # And Processor (slave-1) diff --git a/test_dropbox.sh b/test_dropbox.sh index f7e188c..4142904 100755 --- a/test_dropbox.sh +++ b/test_dropbox.sh @@ -7,8 +7,9 @@ set -x # Must be exported by the caller: # OMERO_USER OMERO_PASS PREFIX +OMERO=/opt/omero/server/OMERO.server/bin/omero FILENAME=$(date +%Y%m%d-%H%M%S-%N).fake -docker exec $PREFIX-master sh -c \ +docker exec $PREFIX-server sh -c \ "mkdir -p /OMERO/DropBox/root && touch /OMERO/DropBox/root/$FILENAME" echo -n "Checking for imported DropBox image $FILENAME " @@ -17,7 +18,7 @@ i=0 result= while [ $i -lt 60 ]; do sleep 4 - result=$(docker exec $PREFIX-master OMERO.server/bin/omero hql -q -s localhost -u $OMERO_USER -w $OMERO_PASS "SELECT COUNT (*) FROM Image WHERE name='$FILENAME'" --style plain) + result=$(docker exec $PREFIX-server $OMERO hql -q -s localhost -u $OMERO_USER -w $OMERO_PASS "SELECT COUNT (*) FROM Image WHERE name='$FILENAME'" --style plain) if [ "$result" = "0,1" ]; then echo echo "Found image: $result" diff --git a/test_login.sh b/test_login.sh index 7e74f39..4f08640 100755 --- a/test_login.sh +++ b/test_login.sh @@ -7,56 +7,17 @@ set -x # Must be exported by the caller: # OMERO_USER OMERO_PASS PREFIX -WEB_PORT=$(docker inspect --format='{{(index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort}}' $PREFIX-web) +OMERO=/opt/omero/server/OMERO.server/bin/omero -LOGIN_URL="http://localhost:$WEB_PORT/webclient/login/" -SERVER="1" -URL="url=%2Fwebclient%2F" -COOKIES=cookies.txt - -rm -f $COOKIES -CURL_BIN="curl -i -k -s -c $COOKIES -b $COOKIES -e $LOGIN_URL" - -echo -n "Getting CRSF token " -# Retry for 2 mins -i=0 -csrf_token= -while [ -z "$csrf_token" -a $i -lt 60 ]; do - sleep 2 - $CURL_BIN $LOGIN_URL > /dev/null || true - csrf_token=$(grep csrftoken cookies.txt | awk '{print $7}') - echo -n "." - let ++i -done -echo - -if [ -z "$csrf_token" ]; then - echo "Failed to get CSRF token" - exit 2 -fi - -echo "CSRF token: $csrf_token" -echo -n "Attempting to login " -# Retry for 2 mins -DJANGO_TOKEN="csrfmiddlewaretoken=$csrf_token" +# Wait up to 2 mins i=0 -session_id= -# Retry for 2 mins -while [ -z "$session_id" -a $i -lt 60 ]; do - sleep 2 - $CURL_BIN -d \ - "$DJANGO_TOKEN&username=$OMERO_USER&password=$OMERO_PASS&server=$SERVER&url=$URL" \ - -X POST $LOGIN_URL > /dev/null || true - session_id=$(grep sessionid cookies.txt | awk '{print $7}') - echo -n "." - let ++i +while ! docker exec test-server $OMERO login -C -s localhost -u "$OMERO_USER" -q -w "$OMERO_PASS"; do + i=$(($i+1)) + if [ $i -ge 24 ]; then + echo "$(date) - OMERO.server still not reachable, giving up" + exit 1 + fi + echo "$(date) - waiting for OMERO.server..." + sleep 5 done -echo - -if [ -z "$session_id" ]; then - echo "Failed to login" - exit 2 -fi - -echo "Session id: $session_id" -rm -f $COOKIES +echo "OMERO.server connection established" diff --git a/test_processor.sh b/test_processor.sh index c502200..193af4f 100755 --- a/test_processor.sh +++ b/test_processor.sh @@ -7,20 +7,20 @@ set -x # Must be exported by the caller: # OMERO_USER OMERO_PASS PREFIX +OMERO=/opt/omero/server/OMERO.server/bin/omero DSNAME=$(date +%Y%m%d-%H%M%S-%N) FILENAME=$(date +%Y%m%d-%H%M%S-%N).fake SCRIPT=/omero/util_scripts/Dataset_To_Plate.py -dataset_id=$(docker exec $PREFIX-master OMERO.server/bin/omero obj -q -s localhost -u $OMERO_USER -w $OMERO_PASS new Dataset name=$DSNAME | cut -d: -f2) +dataset_id=$(docker exec $PREFIX-server $OMERO obj -q -s localhost -u $OMERO_USER -w $OMERO_PASS new Dataset name=$DSNAME | cut -d: -f2) -docker exec $PREFIX-master sh -c \ - "touch $FILENAME && OMERO.server/bin/omero import -d $dataset_id $FILENAME" +docker exec $PREFIX-server sh -c \ + "touch /tmp/$FILENAME && $OMERO import -d $dataset_id /tmp/$FILENAME" -docker exec $PREFIX-master OMERO.server/bin/omero script launch $SCRIPT \ - IDs=$dataset_id +docker exec $PREFIX-server $OMERO script launch $SCRIPT IDs=$dataset_id echo "Completed with code $?" -result=$(docker exec $PREFIX-master OMERO.server/bin/omero hql -q -s localhost -u $OMERO_USER -w $OMERO_PASS "SELECT COUNT(w) FROM WellSample w WHERE w.well.plate.name='$DSNAME' AND w.image.name='$FILENAME'" --style plain) +result=$(docker exec $PREFIX-server $OMERO hql -q -s localhost -u $OMERO_USER -w $OMERO_PASS "SELECT COUNT(w) FROM WellSample w WHERE w.well.plate.name='$DSNAME' AND w.image.name='$FILENAME'" --style plain) if [ "$result" != "0,1" ]; then echo "Script failed: $result" exit 2