From e0611113e2c529b4a6c1a3576444637f70f61dae Mon Sep 17 00:00:00 2001 From: jmoore Date: Wed, 30 Jan 2019 14:36:34 +0000 Subject: [PATCH] Import on startup all files in /import --- 99-run.sh | 2 ++ Dockerfile | 2 ++ import-all | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100755 import-all diff --git a/99-run.sh b/99-run.sh index ec83b89..ff5cddb 100755 --- a/99-run.sh +++ b/99-run.sh @@ -4,5 +4,7 @@ set -eu omero=/opt/omero/server/OMERO.server/bin/omero cd /opt/omero/server +echo "Running importer in the background" +sh -c "/tools/wait-on-login && /tools/import-all" & echo "Starting OMERO.server" exec $omero admin start --foreground diff --git a/Dockerfile b/Dockerfile index 6231eaa..8674a32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ RUN curl -L -o /usr/local/bin/dumb-init \ chmod +x /usr/local/bin/dumb-init ADD entrypoint.sh /usr/local/bin/ ADD 50-config.py 60-database.sh 99-run.sh /startup/ +ADD wait-on-login import-all /tools/ +RUN mkdir /import && touch /import/test.fake USER omero-server diff --git a/import-all b/import-all new file mode 100755 index 0000000..ca65e6b --- /dev/null +++ b/import-all @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import atexit +import os +import socket +import sys +import time + + +OMERO_DIST = os.environ.get("OMERO_DIST", "/opt/omero/server/OMERO.server") +if not os.path.exists(OMERO_DIST): + OMERO_DIST = "/opt/omero/web/OMERO.web" + +sys.path.append("/".join([OMERO_DIST, "lib/python"])) +import omero +from omero.cli import cli_login +from omero.util.import_candidates import as_dictionary + + +OMERO_HOST = os.environ.get("OMERO_HOST", "localhost") +OMERO_USER = os.environ.get("OMERO_USER", "root") +OMERO_PASS = os.environ.get("OMERO_PASS", "omero") +OMERO_PORT = int(os.environ.get("OMERO_PORT", "4064")) +SLEEP_TIME = int(os.environ.get("SLEEP_TIME", "30")) + + +with cli_login("-s", OMERO_HOST, + "-u", OMERO_USER, + "-p", str(OMERO_PORT), + "-w", OMERO_PASS) as cli: + + for k, v in as_dictionary(("/import",)).items(): + cli.onecmd(["import", k])