Skip to content

Commit

Permalink
Update docker image to python 3.12
Browse files Browse the repository at this point in the history
Make image versatile to run as a client or as API
  • Loading branch information
charalamm committed Mar 13, 2024
1 parent f4539e8 commit 9d6ca0c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
3 changes: 3 additions & 0 deletions docker/.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ coverage.xml
.gitignore
.github
.gitattributes
.pre-commit-config.yaml
*.egg-info
.mypy_cache
.pytest_cache
.hypothesis
build
docker
!docker/resources
20 changes: 11 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
Expand Down
21 changes: 14 additions & 7 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand All @@ -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=<url to terracotta tiler> myregistry.com/terracotta:test
```
22 changes: 22 additions & 0 deletions docker/resources/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
12 changes: 12 additions & 0 deletions docker/resources/entrypoint_client.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions terracotta/client/client_app.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9d6ca0c

Please sign in to comment.