Skip to content

Commit

Permalink
Merge pull request #217 from stac-utils/refactor/docker-images
Browse files Browse the repository at this point in the history
unify docker images
  • Loading branch information
vincentsarago authored Feb 13, 2025
2 parents 07f4a71 + 5699880 commit 69dd186
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 150 deletions.
18 changes: 2 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ jobs:
needs: [tests]
if: github.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
runs-on: ubuntu-latest
strategy:
matrix:
image-version:
- 'uvicorn'
- 'gunicorn'

steps:
- name: Checkout
Expand All @@ -189,15 +184,6 @@ jobs:
run: |
echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Image name
id: image
run: |
if [ ${{ matrix.image-version }} = 'uvicorn' ]; then
echo "name=titiler-pgstac:uvicorn-" >> $GITHUB_OUTPUT
else
echo "name=titiler-pgstac:" >> $GITHUB_OUTPUT
fi
# Push `latest` when comiting to main
- name: Build and push latest
if: github.ref == 'refs/heads/main'
Expand All @@ -208,7 +194,7 @@ jobs:
file: Dockerfile.${{ matrix.image-version }}
push: true
tags: |
ghcr.io/stac-utils/${{ steps.image.outputs.name }}latest
ghcr.io/stac-utils/titiler-pgstac:latest
# Push `{VERSION}` when pushing a new tag
- name: Build and push tag
Expand All @@ -220,4 +206,4 @@ jobs:
file: Dockerfile.${{ matrix.image-version }}
push: true
tags: |
ghcr.io/stac-utils/${{ steps.image.outputs.name }}${{ steps.tag.outputs.version }}
ghcr.io/stac-utils/titiler-pgstac:${{ steps.tag.outputs.version }}
2 changes: 1 addition & 1 deletion .github/workflows/tests/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

host = os.environ.get("HOST", "0.0.0.0")
port = os.environ.get("PORT", "8081")
port = os.environ.get("PORT", "8083")


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def search_id():
"""Mosaic ID fixture"""
host = os.environ.get("HOST", "0.0.0.0")
port = os.environ.get("PORT", "8081")
port = os.environ.get("PORT", "8083")

query = {"collections": ["world"]}
response = httpx.post(f"http://{host}:{port}/searches/register", json=query)
Expand Down
42 changes: 42 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
# Release Notes

## 1.7.0 (2025-02-13)

* update titiler requirement to `>=0.21,<0.22`
* use `URN` style CRS notation in WMTS document
* Unify Docker images (deprecate `uvicorn-*` tags)

```
# Uvicorn
# before
docker run \
--platform=linux/amd64 \
-p 8000:8000 \
--env PORT=8000 \
--env DATABASE_URL=postgresql://username:[email protected]:5439/postgis \
--rm -it ghcr.io/stac-utils/titiler-pgstac:uvicorn-latest
# now
docker run \
--platform=linux/amd64 \
-p 8000:8000 \
--env DATABASE_URL=postgresql://username:[email protected]:5439/postgis \
--rm -it ghcr.io/stac-utils/titiler-pgstac:latest \
uvicorn titiler.pgstac.main:app --host 0.0.0.0 --port 8000 --workers 1
# Gunicorn
# before
docker run \
--platform=linux/amd64 \
-p 8000:8000 \
--env PORT=8000 \
--env DATABASE_URL=postgresql://username:[email protected]:5439/postgis \
--rm -it ghcr.io/stac-utils/titiler-pgstac:latest
# now
docker run \
--platform=linux/amd64 \
-p 8000:8000 \
--env DATABASE_URL=postgresql://username:[email protected]:5439/postgis \
--rm -it ghcr.io/stac-utils/titiler-pgstac:latest \
gunicorn -k uvicorn.workers.UvicornWorker titiler.pgstac.main:app --bind 0.0.0.0:8000 --workers 1
```
## 1.6.0 (2025-01-13)
* remove `rescale_dependency` and `color_formula_dependency` attributes in TilerFactory class **breaking change**
Expand Down
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ARG PYTHON_VERSION=3.12

FROM bitnami/python:${PYTHON_VERSION}
RUN apt update && apt upgrade -y \
&& apt install curl -y \
&& rm -rf /var/lib/apt/lists/*

# Ensure root certificates are always updated at evey container build
# and curl is using the latest version of them
RUN mkdir /usr/local/share/ca-certificates/cacert.org
RUN cd /usr/local/share/ca-certificates/cacert.org && curl -k -O https://www.cacert.org/certs/root.crt
RUN cd /usr/local/share/ca-certificates/cacert.org && curl -k -O https://www.cacert.org/certs/class3.crt
RUN update-ca-certificates
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

WORKDIR /tmp

RUN python -m pip install -U pip
RUN python -m pip install uvicorn uvicorn-worker gunicorn

COPY titiler/ titiler/
COPY pyproject.toml pyproject.toml
COPY README.md README.md
COPY LICENSE LICENSE

RUN python -m pip install --no-cache-dir --upgrade .["psycopg-binary"]
RUN rm -rf titiler/ pyproject.toml README.md LICENSE

###################################################
# For compatibility (might be removed at one point)
ENV MODULE_NAME=titiler.pgstac.main
ENV VARIABLE_NAME=app
ENV HOST=0.0.0.0
ENV PORT=80
ENV WEB_CONCURRENCY=1
CMD gunicorn -k uvicorn.workers.UvicornWorker ${MODULE_NAME}:${VARIABLE_NAME} --bind ${HOST}:${PORT} --workers ${WEB_CONCURRENCY}
19 changes: 0 additions & 19 deletions Dockerfile.gunicorn

This file was deleted.

21 changes: 0 additions & 21 deletions Dockerfile.uvicorn

This file was deleted.

14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ $ python -m pip install -e .

In `titiler.pgstac` setup.py, we have added three options to let users choose which psycopg install to use:

- `pip install titiler.pgstac["psycopg"]`: pure python
- `pip install titiler.pgstac["psycopg-c"]`: use the C wrapper (requires development packages installed on the client machine)
- `pip install titiler.pgstac["psycopg-binary"]`: binary wheels
- `python -m pip install titiler.pgstac["psycopg"]`: pure python
- `python -m pip install titiler.pgstac["psycopg-c"]`: use the C wrapper (requires development packages installed on the client machine)
- `python -m pip install titiler.pgstac["psycopg-binary"]`: binary wheels

## Launch

Expand All @@ -83,7 +83,7 @@ export POSTGRES_PORT=5432
```

```
$ pip install uvicorn
$ python -m pip install uvicorn
$ uvicorn titiler.pgstac.main:app --reload
```

Expand All @@ -93,11 +93,7 @@ $ uvicorn titiler.pgstac.main:app --reload
$ git clone https://github.com/stac-utils/titiler-pgstac.git
$ cd titiler-pgstac
$ docker compose up --build tiler
```

It runs `titiler.pgstac` using Gunicorn web server. To run Uvicorn based version:

```
# or
$ docker compose up --build tiler-uvicorn
```

Expand Down
2 changes: 1 addition & 1 deletion benchmark/create_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _xy(lon, lat):
with open("urls.txt", "w") as fin:
fin.write("PROT=http\n")
fin.write("HOST=localhost\n")
fin.write("PORT=8080\n")
fin.write("PORT=8081\n")
fin.write("PATH=\n")
fin.write("EXT=pbf\n")
for zoom in range(0, maxzoom + 1):
Expand Down
89 changes: 7 additions & 82 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ services:
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile.gunicorn
dockerfile: Dockerfile
ports:
- "8081:8081"
command: ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "titiler.pgstac.main:app", "--bind", "0.0.0.0:8081", "--workers", "1"]
environment:
# Application
- HOST=0.0.0.0
- PORT=8081
- WEB_CONCURRENCY=1
- WORKERS_PER_CORE=1
# Postgres connection
- POSTGRES_USER=username
- POSTGRES_PASS=password
Expand Down Expand Up @@ -58,86 +54,15 @@ services:

tiler-uvicorn:
container_name: tiler-pgstac-uvicorn
# At the time of writing, rasterio and psycopg wheels are not available for arm64 arch
# so we force the image to be built with linux/amd64
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile.uvicorn
extends:
service: tiler
ports:
- "8081:8081"
environment:
# Application
- HOST=0.0.0.0
- PORT=8081
- WEB_CONCURRENCY=1
# Postgres connection
- POSTGRES_USER=username
- POSTGRES_PASS=password
- POSTGRES_DBNAME=postgis
- POSTGRES_HOST=database
- POSTGRES_PORT=5432
# PG connection
- DB_MIN_CONN_SIZE=1
- DB_MAX_CONN_SIZE=10
# - DB_MAX_QUERIES=10
# - DB_MAX_IDLE=10
# GDAL Config
- CPL_TMPDIR=/tmp
# This option controls the default GDAL raster block cache size.
# If its value is small (less than 100000), it is assumed to be measured in megabytes, otherwise in bytes.
- GDAL_CACHEMAX=200
- GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR
- GDAL_INGESTED_BYTES_AT_OPEN=32768
- GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES
- GDAL_HTTP_MULTIPLEX=YES
- GDAL_HTTP_VERSION=2
# The file can be cached in RAM by setting the configuration option VSI_CACHE to TRUE.
# The cache size defaults to 25 MB, but can be modified by setting the configuration option VSI_CACHE_SIZE (in bytes).
# Content in that cache is discarded when the file handle is closed.
- VSI_CACHE=TRUE
- VSI_CACHE_SIZE=536870912
# In addition, a global least-recently-used cache of 16 MB shared among all downloaded content is enabled by default,
# and content in it may be reused after a file handle has been closed and reopen,
# during the life-time of the process or until VSICurlClearCache() is called.
# Starting with GDAL 2.3, the size of this global LRU cache can be modified by
# setting the configuration option CPL_VSIL_CURL_CACHE_SIZE (in bytes).
- CPL_VSIL_CURL_CACHE_SIZE=200000000
# TiTiler Config
- MOSAIC_CONCURRENCY=5
# - RIO_TILER_MAX_THREADS=2
# AWS S3 endpoint config
# - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
# - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
volumes:
- ./benchmark:/tmp/benchmark
depends_on:
- database

stac-fastapi:
image: ghcr.io/stac-utils/stac-fastapi-pgstac:3.0.0
ports:
- "${MY_DOCKER_IP:-127.0.0.1}:8082:8082"
environment:
# Postgres connection
- POSTGRES_USER=username
- POSTGRES_PASS=password
- POSTGRES_DBNAME=postgis
- POSTGRES_HOST_READER=database
- POSTGRES_HOST_WRITER=database
- POSTGRES_PORT=5432
- DB_MIN_CONN_SIZE=1
- DB_MAX_CONN_SIZE=1
depends_on:
- database
command:
bash -c "uvicorn stac_fastapi.pgstac.app:app --host 0.0.0.0 --port 8082"
volumes:
- ./dockerfiles/scripts:/tmp/scripts
- "8083:8083"
command: ["uvicorn", "titiler.pgstac.main:app", "--host", "0.0.0.0", "--port", "8083", "--workers", "1"]

database:
container_name: stac-db
image: ghcr.io/stac-utils/pgstac:v${PGSTAC_VERSION-0.9.1}
image: ghcr.io/stac-utils/pgstac:v${PGSTAC_VERSION-0.9.2}
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
Expand Down

0 comments on commit 69dd186

Please sign in to comment.