Skip to content

Commit

Permalink
omero-grid now builds separate master and slave images only
Browse files Browse the repository at this point in the history
This is based on ome/omero-server-docker#1
  • Loading branch information
manics committed Jun 5, 2017
1 parent 7904b7d commit e5ab8cc
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 142 deletions.
63 changes: 0 additions & 63 deletions build.py

This file was deleted.

13 changes: 13 additions & 0 deletions master/70-grid-xml.sh
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 15 additions & 0 deletions master/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TODO: Switch to openmicroscopy/omero-server when it's merged
FROM test-omero-server
MAINTAINER [email protected]

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
File renamed without changes.
41 changes: 41 additions & 0 deletions slave/99-run.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions slave/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TODO: Switch to openmicroscopy/omero-server when it's merged
FROM test-omero-server
MAINTAINER [email protected]

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
File renamed without changes.
41 changes: 20 additions & 21 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test_dropbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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"
Expand Down
61 changes: 11 additions & 50 deletions test_login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 6 additions & 6 deletions test_processor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5ab8cc

Please sign in to comment.