Skip to content

Commit

Permalink
modernize Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed Sep 27, 2024
1 parent 5c5a50c commit 0cd9b03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
32 changes: 17 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 8 additions & 21 deletions rook/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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:
Expand All @@ -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))

Expand Down

0 comments on commit 0cd9b03

Please sign in to comment.