Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove python 3.8, add python 3.13 and unify docker images #203

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
remove python 3.8 and unify docker images
  • Loading branch information
vincentsarago committed Jan 17, 2025
commit ce6fdc842a33515ffcdca785a8f89d9ddac252de
54 changes: 17 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ on:
- '.github/workflows/ci.yml'
pull_request:
env:
LATEST_PY_VERSION: '3.12'
LATEST_PY_VERSION: '3.13'

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -134,12 +134,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
uses: actions/checkout@v4
Expand All @@ -157,40 +151,26 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set tag version
id: tag
run: |
echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

- name: Image name
id: image
run: |
if [ ${{ matrix.image-version }} = 'uvicorn' ]; then
echo "name=${{ github.repository }}:uvicorn-" >> $GITHUB_OUTPUT
else
echo "name=${{ github.repository }}:" >> $GITHUB_OUTPUT
fi

# Push `latest` when commiting to main
- name: Build and push
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
platforms: linux/amd64,linux/arm64
context: .
file: dockerfiles/Dockerfile.${{ matrix.image-version }}
push: true
images: |
ghcr.io/${{ github.repository }}
flavor: |
latest=false
tags: |
ghcr.io/${{ steps.image.outputs.name }}latest
type=semver,pattern={{version}}
type=raw,value=latest,enable={{is_default_branch}}

# Push `{VERSION}` when pushing a new tag
- name: Build and push
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
context: .
file: dockerfiles/Dockerfile.${{ matrix.image-version }}
push: true
tags: |
ghcr.io/${{ steps.image.outputs.name }}${{ steps.tag.outputs.version }}
file: dockerfiles/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 2 additions & 2 deletions .github/workflows/deploy_mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Checkout master
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.11

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
language_version: python

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.8.4
hooks:
- id: ruff
args: ["--fix"]
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin

* fix serialization of UUID columns (author @giorgiobasile, https://github.com/developmentseed/tipg/pull/199)

* Unify Docker images (deprecate `tipg-uvicorn`)

* Remove `python3.8` support

* Add `python3.13` support

## [0.8.0] - 2024-10-17

* update `starlette-cramjam` dependency and set compression-level default to 6
Expand Down
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ More info about configuration options at https://developmentseed.org/tipg/user_g
## Launch

```bash
$ pip install uvicorn
$ python -m pip install uvicorn

# Set your PostGIS database instance URL in the environment
$ export DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis
Expand Down Expand Up @@ -116,32 +116,29 @@ $ docker-compose up app

We are publishing two different docker images on `tag` and on every commit to `main` branch:

| | Gunicorn | Uvicorn |
| -- | -- | -- |
main commit | `ghcr.io/developmentseed/tipg:latest` | `ghcr.io/developmentseed/tipg:uvicorn-latest`
tags | `ghcr.io/developmentseed/tipg:0.0.0` | `ghcr.io/developmentseed/tipg:uvicorn-0.0.0`
dockerfile | [/dockerfiles/Dockerfile.gunicorn](https://github.com/developmentseed/tipg/blob/main/dockerfiles/Dockerfile.gunicorn) | [/dockerfiles/Dockerfile.uvicorn](https://github.com/developmentseed/tipg/blob/main/dockerfiles/Dockerfile.uvicorn)
| | Gunicorn |
| -- | -- |
main commit | `ghcr.io/developmentseed/tipg:latest`
tags | `ghcr.io/developmentseed/tipg:X.X.X`
dockerfile | [/dockerfiles/Dockerfile](https://github.com/developmentseed/tipg/blob/main/dockerfiles/Dockerfile)

See all version at https://github.com/developmentseed/tipg/pkgs/container/tipg

```
# Gunicorn image
$ docker run \
-p 8081:8081 \
-e PORT=8081 \
-p 8000:8000 \
-e DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis \
ghcr.io/developmentseed/tipg:latest
ghcr.io/developmentseed/tipg:latest \
uvicorn tipg.main:app --host 0.0.0.0 --port 8000 --workers 1

# or Uvicorn image
# using Gunicorn
$ docker run \
-p 8081:8081 \
-e PORT=8081 \
-p 8000:8000 \
-e DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis \
ghcr.io/developmentseed/tipg:uvicorn-latest
ghcr.io/developmentseed/tipg:latest \
gunicorn -k uvicorn.workers.UvicornWorker tipg.main:app --bind 0.0.0.0:8000 --workers 1
```

Note: If you are planning to use the docker image in a kubernetes deployment you may want to use the `uvicorn` image (ref: https://fastapi.tiangolo.com/deployment/server-workers/).

## Contribution & Development

See [CONTRIBUTING.md](https://github.com/developmentseed/tipg/blob/main/CONTRIBUTING.md)
Expand Down
32 changes: 2 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
version: '3'

services:
app:
build:
context: .
dockerfile: dockerfiles/Dockerfile.gunicorn
environment:
- HOST=0.0.0.0
- PORT=8081
- PYTHONWARNINGS=ignore
- POSTGRES_USER=username
- POSTGRES_PASS=password
- POSTGRES_DBNAME=postgis
- POSTGRES_HOST=database
- POSTGRES_PORT=5432
- DEBUG=TRUE
ports:
- "${MY_DOCKER_IP:-127.0.0.1}:8081:8081"
depends_on:
- database
command:
bash -c "bash /tmp/scripts/wait-for-it.sh database:5432 --timeout=30 && /start.sh"
volumes:
- ./dockerfiles/scripts:/tmp/scripts

app-uvicorn:
build:
context: .
dockerfile: dockerfiles/Dockerfile.uvicorn
dockerfile: dockerfiles/Dockerfile
environment:
- HOST=0.0.0.0
- PORT=8081
- WEB_CONCURRENCY=1
- PYTHONWARNINGS=ignore
- POSTGRES_USER=username
- POSTGRES_PASS=password
Expand All @@ -44,7 +16,7 @@ services:
depends_on:
- database
command:
bash -c "bash /tmp/scripts/wait-for-it.sh database:5432 --timeout=30 && uvicorn tipg.main:app --host 0.0.0.0 --port 8081"
bash -c "bash /tmp/scripts/wait-for-it.sh database:5432 --timeout=30 && uvicorn tipg.main:app --host 0.0.0.0 --port 8081 --workers 5"
volumes:
- ./dockerfiles/scripts:/tmp/scripts

Expand Down
34 changes: 34 additions & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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

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

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

RUN python -m pip install . --no-cache-dir
RUN rm -rf tipg/ README.md pyproject.toml LICENSE

###################################################
# For compatibility (might be removed at one point)
ENV MODULE_NAME=tipg.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}
16 changes: 0 additions & 16 deletions dockerfiles/Dockerfile.gunicorn

This file was deleted.

21 changes: 0 additions & 21 deletions dockerfiles/Dockerfile.uvicorn

This file was deleted.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "tipg"
description = "Simple and Fast Geospatial OGC Features and Tiles API for PostGIS."
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = {file = "LICENSE"}
authors = [
{name = "Vincent Sarago", email = "vincent@developmentseed.org"},
Expand All @@ -13,10 +13,11 @@ classifiers = [
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: GIS",
]
dynamic = ["version"]
Expand All @@ -33,8 +34,6 @@ dependencies = [
"pygeofilter>=0.2.0,<0.3.0",
"ciso8601~=2.3",
"starlette-cramjam>=0.4,<0.5",
"importlib_resources>=1.1.0; python_version < '3.9'",
"typing_extensions; python_version < '3.9'",
]

[project.optional-dependencies]
Expand Down
7 changes: 1 addition & 6 deletions tipg/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""tipg.db: database events."""

import pathlib
from importlib.resources import files as resources_files
from typing import List, Optional

import orjson
Expand All @@ -11,12 +12,6 @@

from fastapi import FastAPI

try:
from importlib.resources import files as resources_files # type: ignore
except ImportError:
# Try backported to PY<39 `importlib_resources`.
from importlib_resources import files as resources_files # type: ignore

DB_CATALOG_FILE = resources_files(__package__) / "sql" / "dbcatalog.sql"


Expand Down
3 changes: 1 addition & 2 deletions tipg/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""tipg dependencies."""

import re
from typing import Dict, List, Literal, Optional, Tuple, get_args
from typing import Annotated, Dict, List, Literal, Optional, Tuple, get_args

from ciso8601 import parse_rfc3339
from morecantile import Tile
from morecantile import tms as default_tms
from pygeofilter.ast import AstType
from pygeofilter.parsers.cql2_json import parse as cql2_json_parser
from pygeofilter.parsers.cql2_text import parse as cql2_text_parser
from typing_extensions import Annotated

from tipg.collections import Catalog, Collection, CollectionList
from tipg.errors import InvalidBBox, MissingCollectionCatalog, MissingFunctionParameter
Expand Down
13 changes: 11 additions & 2 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
import csv
import re
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, Generator, Iterable, List, Literal, Optional
from typing import (
Annotated,
Any,
Callable,
Dict,
Generator,
Iterable,
List,
Literal,
Optional,
)
from urllib.parse import urlencode

import jinja2
Expand All @@ -13,7 +23,6 @@
from morecantile import tms as default_tms
from morecantile.defaults import TileMatrixSets
from pygeofilter.ast import AstType
from typing_extensions import Annotated

from tipg import model
from tipg.collections import Collection, CollectionList
Expand Down
Loading
Loading