diff --git a/docker/.dockerignore b/.dockerignore similarity index 83% rename from docker/.dockerignore rename to .dockerignore index 67d0e5d4..cb148ae2 100644 --- a/docker/.dockerignore +++ b/.dockerignore @@ -18,8 +18,11 @@ coverage.xml .gitignore .github .gitattributes +.pre-commit-config.yaml *.egg-info .mypy_cache .pytest_cache .hypothesis build +docker +!docker/resources diff --git a/docker/Dockerfile b/docker/Dockerfile index bace8945..9ba06cb5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10.12-slim-bullseye as build_tarball +FROM python:3.12.2-slim-bullseye AS build_wheel RUN apt-get update \ && apt-get install \ @@ -8,24 +8,26 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* COPY ./ /terracotta -COPY ./docker/entrypoint.sh /entrypoint.sh WORKDIR /terracotta RUN python -m pip install --upgrade pip \ - && python setup.py sdist + && python setup.py bdist_wheel -FROM python:3.10.12-slim-bullseye +FROM python:3.12.2-slim-bullseye -COPY --from=build_tarball /terracotta/dist/terracotta-*.tar.gz /terracotta/terracotta.tar.gz +COPY --from=build_wheel /terracotta/dist/*.whl /terracotta/ -RUN pip install --upgrade pip \ - && pip install psycopg2-binary gunicorn \ - && pip install /terracotta/terracotta.tar.gz \ +RUN pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir \ + $(ls /terracotta/*.whl) \ + pymysql>=1.0.0 \ + psycopg2-binary \ + gunicorn \ && rm -rf /terracotta -COPY --from=build_tarball /entrypoint.sh /entrypoint.sh +COPY docker/resources / ENV TC_SERVER_PORT=5000 EXPOSE $TC_SERVER_PORT diff --git a/docker/README.md b/docker/README.md index 0c53f168..1376a11c 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,6 +1,7 @@ # Terracotta docker -This directory contains the files to build the Terracotta docker image. +This directory contains the files to build the Terracotta docker image. This image can be used to serve the tile server. +It can also be used to connect to a running terracotta tiler and serve the client depending on the value of the environment variable `TERRACOTTA_SERVICE`. By default, the tiler server is started. ## Build the image @@ -14,12 +15,6 @@ Build using a custom registry, image name and tag: $ make build REGISTRY=myregistry.com IMAGE=terracotta TAG=test ``` -## Start the server (locally) - -```bash -$ docker run -v /path/to/database:/mnt -e TC_DRIVER_PATH=/mnt/db.sqlite -t myregistry.com/terracotta:test -``` - ## Push the image to a registry Push using the default image name and tag: @@ -31,3 +26,15 @@ Push using a custom registry, image name and tag: ```bash $ make push REGISTRY=myregistry.com IMAGE=terracotta TAG=test ``` + +## Start the server (local database) + +```bash +$ docker run -v /path/to/database:/mnt TERRACOTTA_SERVICE=tiler -e TC_DRIVER_PATH=/mnt/db.sqlite myregistry.com/terracotta:test +``` + +## Start the client + +```bash +$ docker run -e TERRACOTTA_SERVICE=client -e TERRACOTTA_API_URL= myregistry.com/terracotta:test +``` diff --git a/docker/resources/entrypoint.sh b/docker/resources/entrypoint.sh new file mode 100755 index 00000000..64318352 --- /dev/null +++ b/docker/resources/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +DEFAULT_TERRACOTTA_SERVICE="tiler" +API_SERVICE_KEYWORD="tiler" +CLIENT_SERVICE_KEYWORD="client" + + +# Validate that environment variables are set +if [ -z "$TERRACOTTA_SERVICE" ]; then + echo "TERRACOTTA_SERVICE is not set. Using default value: $DEFAULT_TERRACOTTA_SERVICE" + TERRACOTTA_SERVICE=$DEFAULT_TERRACOTTA_SERVICE +fi + + +if [ $TERRACOTTA_SERVICE = $API_SERVICE_KEYWORD ]; then + ./entrypoint_api.sh +elif [ $TERRACOTTA_SERVICE = $CLIENT_SERVICE_KEYWORD ]; then + ./entrypoint_client.sh +else + echo "TERRACOTTA_SERVICE is not set to a valid value. Exiting." + exit 1 +fi diff --git a/docker/entrypoint.sh b/docker/resources/entrypoint_api.sh similarity index 100% rename from docker/entrypoint.sh rename to docker/resources/entrypoint_api.sh diff --git a/docker/resources/entrypoint_client.sh b/docker/resources/entrypoint_client.sh new file mode 100755 index 00000000..0fdcd83c --- /dev/null +++ b/docker/resources/entrypoint_client.sh @@ -0,0 +1,12 @@ +#!/bin/sh + + +# Validate that environment variables are set +if [ -z "$TERRACOTTA_API_URL" ]; then + echo "TERRACOTTA_API_URL is not set. Exiting." + exit 1 +fi + + +# Start the server +gunicorn terracotta.client.client_app:client_app --bind 0.0.0.0:$TC_SERVER_PORT diff --git a/terracotta/client/client_app.py b/terracotta/client/client_app.py new file mode 100644 index 00000000..0753611c --- /dev/null +++ b/terracotta/client/client_app.py @@ -0,0 +1,6 @@ +import os +from terracotta.client.flask_api import create_app + +TERRACOTTA_API_URL = os.environ["TERRACOTTA_API_URL"] + +client_app = create_app(TERRACOTTA_API_URL)