Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor startup scripts, envvars for all omero parameter #1

Merged
merged 17 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 50-config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# 1. Run .omero files from /opt/omero/server/config/
# 2. Set omero config properties from CONFIG_ envvars
# Variable names should replace "." with "_" and "_" with "__"
# E.g. CONFIG_omero_web_public_enabled=false

import os
from subprocess import call
from re import sub


CONFIG_OMERO = '/opt/omero/server/config/omero-server-config-update.sh'
OMERO = '/opt/omero/server/OMERO.server/bin/omero'

if os.access(CONFIG_OMERO, os.X_OK):
rc = call([CONFIG_OMERO])
assert rc == 0

for (k, v) in os.environ.iteritems():
if k.startswith('CONFIG_'):
prop = k[7:]
prop = sub('([^_])_([^_])', r'\1.\2', prop)
prop = sub('__', '_', prop)
value = v
rc = call([OMERO, 'config', 'set', '--', prop, value])
assert rc == 0
45 changes: 45 additions & 0 deletions 60-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# 50-config.py or equivalent must be run first to set all omero.db.*
# omero.db.host may require special handling since the default is
# to use `--link postgres:db`

set -eu

omero=/opt/omero/server/OMERO.server/bin/omero
omego=/opt/omero/omego/bin/omego
cd /opt/omero/server

CONFIG_omero_db_host=${CONFIG_omero_db_host:-}
if [ -n "$CONFIG_omero_db_host" ]; then
DBHOST="$CONFIG_omero_db_host"
else
DBHOST=db
$omero config set omero.db.host "$DBHOST"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be outside the if block?

Copy link
Member Author

@manics manics Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, CONFIG_omero_db_host will already be converted into omero.db.host by 50-config.py- I'll update the comment at the top of the file. The only reason for special handling here is that the default of omero.db.host=localhost will never work, instead it defaults to db which should be set by docker run --link ....

fi
DBUSER="${CONFIG_omero_db_user:-omero}"
DBNAME="${CONFIG_omero_db_name:-omero}"
DBPASS="${CONFIG_omero_db_pass:-omero}"
ROOTPASS="${ROOTPASS:-omero}"

export PGPASSWORD="$DBPASS"

i=0
while ! psql -h "$DBHOST" -U "$DBUSER" "$DBNAME" >/dev/null 2>&1 < /dev/null; do
i=$(($i+1))
if [ $i -ge 50 ]; then
echo "$(date) - postgres:5432 still not reachable, giving up"
exit 1
fi
echo "$(date) - waiting for postgres:5432..."
sleep 1
done
echo "postgres connection established"

psql -w -h "$DBHOST" -U "$DBUSER" "$DBNAME" -c \
"select * from dbpatch" 2> /dev/null && {
echo "Upgrading database"
$omego db upgrade --serverdir=OMERO.server
} || {
echo "Initialising database"
$omego db init --rootpass "$ROOTPASS" --serverdir=OMERO.server
}
8 changes: 8 additions & 0 deletions 99-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -eu

omero=/opt/omero/server/OMERO.server/bin/omero
cd /opt/omero/server
echo "Starting OMERO.server"
exec $omero admin start --foreground
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ RUN yum -y install epel-release \
ARG OMERO_VERSION=latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're using the main release version (i.e. 5.3.2) for tags of this repo, then I'm assuming:

  • latest images are considered worst-practice
  • on each OMERO release, we'll branch from master and bump this string to include the version (5.3.3)
  • for bug fixes before an OMERO release, we'll suffix 5.3.3-1

Note: this doesn't yet give us a strategy for breaking changes in the image itself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this has everyone's implicit 👍 but now with 5.4 replacing 5.3

RUN ansible-playbook playbook.yml -e omero_server_release=$OMERO_VERSION

USER omero-server
RUN curl -L -o /usr/local/bin/dumb-init \
https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && \
chmod +x /usr/local/bin/dumb-init
ADD entrypoint.sh /usr/local/bin/
ADD 50-config.py 60-database.sh 99-run.sh /startup/

# 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
USER omero-server

EXPOSE 4061 4063 4064
EXPOSE 4063 4064
VOLUME ["/OMERO", "/opt/omero/server/OMERO.server/var"]

ADD slave.cfg run.sh process_defaultxml.py /opt/omero/server/
ENTRYPOINT ["/opt/omero/server/run.sh"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
OMERO.server Docker
===================

A CentOS 7 based Docker image for OMERO.server.


Running the images
------------------

To run the Docker images start a postgres DB:

docker run -d --name postgres -e POSTGRES_PASSWORD=postgres postgres

Then run OMERO.server passing the database configuration parameters if they differ from the defaults.
This example uses the default `postgres` system database for convenience, in practice you may want to create your own database.

docker run -d --name omero-server --link postgres:db
-e CONFIG_omero_db_user=postgres \
-e CONFIG_omero_db_pass=postgres \
-e CONFIG_omero_db_name=postgres \
-e ROOTPASS=omero-root-password \
-p 4063:4063 -p 4064:4064 \
openmicroscopy/omero-server


Configuration variables
-----------------------

All [OMERO configuration properties](www.openmicroscopy.org/site/support/omero/sysadmins/config.html) can be set be defining environment variables `CONFIG_omero_property_name=`.
Since `.` is not allowed in a variable name `.` must be replaced by `_`, and `_` by `__`, for example

-e CONFIG_omero_web_public_enabled=false


Configuration files
-------------------

Additional configuration files for OMERO can be provided by mounting files into `/opt/omero/server/config/`.
Files will be loaded with `omero load`.
For example:

docker run -d -v
/config/extra.omero:/opt/omero/server/config/extra.omero:ro
openmicroscopy/omero-server

Parameters required for initializing the server such as database configuration *must* be set using environment variables.


Default volumes
---------------

- `/opt/omero/server/OMERO.server/var`: The OMERO.server `var` directory, including logs
- `/OMERO`: The OMERO data directory


Exposed ports
-------------

- 4063
- 4064


Example with named volumes
--------------------------

docker volume create --name omero-db
docker volume create --name omero-data

docker run -d --name postgres -e POSTGRES_PASSWORD=postgres
-v omero-db:/var/lib/postgresql/data postgres
docker run -d --name omero-server --link postgres:db
<-e CONFIG_omero_db_ ...>
-v omero-data:/OMERO
-p 4063:4063 -p 4064:4064 openmicroscopy/omero-server


Running without links
---------------------

As an alternative to running with `--link` the address of the database can be specified using the variable `CONFIG_omero_db_host`
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/local/bin/dumb-init /bin/bash

set -e

for f in /startup/*; do
if [ -f "$f" -a -x "$f" ]; then
echo "Running $f $@"
"$f" "$@"
fi
done
5 changes: 5 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
- role: openmicroscopy.omero-server
vars:
ice_version: "3.6"
ice_install_devel: False
omero_server_database_manage: False
omero_server_systemd_setup: False
omero_server_system_uid: 1000
# You can reduce the size of the image by providing the URL to a
# precompiled Ice Python wheel
#ice_python_wheel:
73 changes: 0 additions & 73 deletions process_defaultxml.py

This file was deleted.

9 changes: 4 additions & 5 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
version: 1.0.0

- src: openmicroscopy.ice
version: 2.0.0
version: 2.1.0

- src: openmicroscopy.java
version: 2.0.0
version: 2.0.1

- src: openmicroscopy.omego
version: 0.1.0
Expand All @@ -18,9 +18,8 @@
- src: openmicroscopy.omero-python-deps
version: 1.1.0

- name: openmicroscopy.omero-server
# version: 2.0.0-m1
src: https://github.com/manics/ansible-role-omero-server/archive/devel.tar.gz
- src: openmicroscopy.omero-server
version: 2.0.0-m2

- src: openmicroscopy.postgresql
version: 2.0.0
Loading