From 0cd9b037a95338379bcb03bee2fbdc6f07eed21a Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:36:27 -0400 Subject: [PATCH] modernize Dockerfile --- Dockerfile | 32 +++++++++++++++++--------------- rook/cli.py | 29 ++++++++--------------------- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba41fe4..8ff560d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,30 @@ # vim:set ft=dockerfile: -FROM continuumio/miniconda3 +FROM condaforge/mambaforge +ARG DEBIAN_FRONTEND=noninteractive +ENV PIP_ROOT_USER_ACTION=ignore +LABEL org.opencontainers.image.authors="https://github.com/roocs/rook" LABEL Description="rook WPS" Vendor="Birdhouse" Version="0.13.1" -# Update Debian system -RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/* +# Set the working directory to /code +WORKDIR /code -# Update conda -RUN conda update -n base conda +# Create conda environment +COPY environment.yml . +RUN mamba env create -n rook -f environment.yml && mamba install -n rook gunicorn && mamba clean --all --yes -# Copy WPS project -COPY . /opt/wps +# Add the rook conda environment to the path +ENV PATH=/opt/conda/envs/rook/bin:$PATH -WORKDIR /opt/wps +# Copy rook source code +COPY . /code -# Create conda environment with PyWPS -RUN ["conda", "env", "create", "-n", "wps", "-f", "environment.yml"] - -# Install WPS -RUN ["/bin/bash", "-c", "source activate wps && pip install -e ."] +# Install rook +RUN pip install . --no-deps # Start WPS service on port 5000 on 0.0.0.0 EXPOSE 5000 -ENTRYPOINT ["/bin/bash", "-c"] -CMD ["source activate wps && exec rook start -b 0.0.0.0 -c /opt/wps/etc/demo.cfg"] + +CMD ["gunicorn", "--bind=0.0.0.0:5000", "rook.wsgi:application"] # docker build -t roocs/rook . # docker run -p 5000:5000 roocs/rook diff --git a/rook/cli.py b/rook/cli.py index 6e308f2..9498c6c 100644 --- a/rook/cli.py +++ b/rook/cli.py @@ -6,13 +6,14 @@ ########################################################### import os -import psutil +from urllib.parse import urlparse + import click +import psutil from jinja2 import Environment, PackageLoader from pywps import configuration from . import wsgi -from urllib.parse import urlparse PID_FILE = os.path.abspath(os.path.join(os.path.curdir, "pywps.pid")) @@ -34,7 +35,7 @@ def get_host(): url = configuration.get_config_value("server", "url") url = url or "http://localhost:5000/wps" - click.echo("starting WPS service on {}".format(url)) + click.echo(f"starting WPS service on {url}") parsed_url = urlparse(url) if ":" in parsed_url.netloc: @@ -56,7 +57,7 @@ def run_process_action(action=None): p = psutil.Process(pid) if action == "stop": p.terminate() - msg = "pid={}, status=terminated".format(p.pid) + msg = f"pid={p.pid}, status=terminated" else: from psutil import _pprint_secs @@ -172,16 +173,6 @@ def stop(): default="sqlite:///pywps-logs.sqlite", help="database in PyWPS configuration", ) -@click.option( - "--outputurl", - default="", - help="base URL for file downloads" -) -@click.option( - "--outputpath", - default="", - help="base directory where outputs are written" -) def start( config, bind_host, @@ -194,14 +185,12 @@ def start( log_level, log_file, database, - outputurl, - outputpath, ): """Start PyWPS service. This service is by default available at http://localhost:5000/wps """ if os.path.exists(PID_FILE): - click.echo('PID file exists: "{}". Service still running?'.format(PID_FILE)) + click.echo(f'PID file exists: "{PID_FILE}". Service still running?') os._exit(0) cfgfiles = [] cfgfiles.append( @@ -214,8 +203,6 @@ def start( wps_log_level=log_level, wps_log_file=log_file, wps_database=database, - wps_outputurl=outputurl, - wps_outputpath=outputpath, ) ) if config: @@ -231,9 +218,9 @@ def start( try: pid = os.fork() if pid: - click.echo("forked process id: {}".format(pid)) + click.echo(f"forked process id: {pid}") with open(PID_FILE, "w") as fp: - fp.write("{}".format(pid)) + fp.write(f"{pid}") except OSError as e: raise Exception("%s [%d]" % (e.strerror, e.errno))