Skip to content

Commit

Permalink
Add backend-specific dockerfiles, publish images (#525)
Browse files Browse the repository at this point in the history
* ci: bump pgstac

* ci, docker: add backend-specific dockerfiles

* Add changelog entry

---------

Co-authored-by: Nathan Zimmerman <[email protected]>
  • Loading branch information
gadomski and moradology authored Feb 23, 2023
1 parent 7f60b8a commit 7ba0a40
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 4 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

services:
db_service:
image: ghcr.io/stac-utils/pgstac:v0.6.12
image: ghcr.io/stac-utils/pgstac:v0.6.13
env:
POSTGRES_USER: username
POSTGRES_PASSWORD: password
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
backend: ["sqlalchemy", "pgstac"]
services:
pgstac:
image: ghcr.io/stac-utils/pgstac:v0.6.11
image: ghcr.io/stac-utils/pgstac:v0.6.13
env:
POSTGRES_USER: username
POSTGRES_PASSWORD: password
Expand Down Expand Up @@ -187,3 +187,41 @@ jobs:
- uses: actions/checkout@v3
- name: Test generating docs
run: make docs

docker-build-push:
runs-on: ubuntu-latest
needs: [test, validate, test-docs]
permissions:
contents: read
packages: write
strategy:
fail-fast: true
matrix:
backend: ["sqlalchemy", "pgstac"]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/stac-utils/stac-fastapi
tags: |
type=schedule,suffix=-${{ matrix.backend }}
type=ref,event=branch,suffix=-${{ matrix.backend }}
type=ref,event=tag,suffix=-${{ matrix.backend }}
type=ref,event=pr,suffix=-${{ matrix.backend }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: docker/Dockerfile.${{ matrix.backend }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Validation checks in CI using [stac-api-validator](github.com/stac-utils/stac-api-validator) ([#508](https://github.com/stac-utils/stac-fastapi/pull/508))
* Required links to the sqlalchemy ItemCollection endpoint ([#508](https://github.com/stac-utils/stac-fastapi/pull/508))
* Publication of docker images to GHCR ([#525](https://github.com/stac-utils/stac-fastapi/pull/525))

### Changed

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ packages:
- **stac_fastapi.types**: Shared types and abstract base classes used by the library.

#### Backends

- **stac_fastapi.sqlalchemy**: Postgres backend implementation with sqlalchemy.
- **stac_fastapi.pgstac**: Postgres backend implementation with [PGStac](https://github.com/stac-utils/pgstac).

Expand Down Expand Up @@ -61,9 +62,25 @@ pip install -e stac_fastapi/sqlalchemy
pip install -e stac_fastapi/pgstac
```

### Pre-built Docker images

Pre-built images are available from the [Github Container Registry](https://github.com/stac-utils/stac-fastapi/pkgs/container/stac-fastapi).
The latest images are tagged with `latest-pgstac` and `latest-sqlalchemy`.
To pull the image to your local system:

```shell
docker pull ghcr.io/stac-utils/stac-fastapi:latest-pgstac # or latest-sqlalchemy
```

This repository provides two example [Docker compose](https://docs.docker.com/compose/) files that demonstrate how you might link the pre-built images with a postgres/pgstac database:

- [docker-compose.pgstac.yml](./docker/docker-compose.pgstac.yml)
- [docker-compose.sqlalchemy.yml](./docker/docker-compose.sqlalchemy.yml)

## Local Development

Use docker-compose via make to start the application, migrate the database, and ingest some example data:

```bash
make image
make docker-run-all
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: stac-fastapi-docs-dev
build:
context: .
dockerfile: Dockerfile.docs
dockerfile: docker/Dockerfile.docs
platform: linux/amd64
environment:
- POSTGRES_USER=username
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
image: stac-utils/stac-fastapi
build:
context: .
dockerfile: Dockerfile
dockerfile: docker/Dockerfile
platform: linux/amd64
environment:
- APP_HOST=0.0.0.0
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions docker/Dockerfile.pgstac
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.8-slim as builder

RUN python -m venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH"

WORKDIR /app

COPY . /app

RUN pip install ./stac_fastapi/types && \
pip install ./stac_fastapi/api && \
pip install ./stac_fastapi/extensions && \
pip install ./stac_fastapi/pgstac[server]


FROM python:3.8-slim as pgstac

ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

COPY --from=builder /opt/venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH"

CMD ["uvicorn", "stac_fastapi.pgstac.app:app", "--host", "0.0.0.0", "--port", "8080"]
27 changes: 27 additions & 0 deletions docker/Dockerfile.sqlalchemy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.8-slim as builder

RUN python -m venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH"

WORKDIR /app

COPY . /app

RUN pip install ./stac_fastapi/types && \
pip install ./stac_fastapi/api && \
pip install ./stac_fastapi/extensions && \
pip install ./stac_fastapi/sqlalchemy[server]


FROM python:3.8-slim as sqlalchemy

ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

COPY --from=builder /opt/venv /opt/venv
COPY ./stac_fastapi/sqlalchemy/alembic /app/alembic
COPY ./stac_fastapi/sqlalchemy/alembic.ini /app/alembic.ini

ENV PATH="/opt/venv/bin:$PATH"

CMD ["uvicorn", "stac_fastapi.sqlalchemy.app:app", "--host", "0.0.0.0", "--port", "8080"]
43 changes: 43 additions & 0 deletions docker/docker-compose.pgstac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3'
services:
stac-fastapi-pgstac:
image: ghcr.io/stac-utils/stac-fastapi:latest-pgstac
platform: linux/amd64
environment:
- APP_HOST=0.0.0.0
- ENVIRONMENT=local
- POSTGRES_USER=username
- POSTGRES_PASS=password
- POSTGRES_DBNAME=postgis
- POSTGRES_HOST_READER=pgstac
- POSTGRES_HOST_WRITER=pgstac
- POSTGRES_PORT=5432
- WEB_CONCURRENCY=10
- VSI_CACHE=TRUE
- GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES
- GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR
- DB_MIN_CONN_SIZE=1
- DB_MAX_CONN_SIZE=1
- USE_API_HYDRATE=${USE_API_HYDRATE:-false}
ports:
- "8080:8080"
depends_on:
- pgstac

pgstac:
image: ghcr.io/stac-utils/pgstac:v0.6.13
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgis
- PGUSER=username
- PGPASSWORD=password
- PGHOST=localhost
- PGDATABASE=postgis
ports:
- "5439:5432"
command: postgres -N 500

networks:
default:
name: stac-fastapi-network
49 changes: 49 additions & 0 deletions docker/docker-compose.sqlalchemy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3'
services:
stac-fastapi-sqlalchemy:
image: ghcr.io/stac-utils/stac-fastapi:latest-sqlalchemy
platform: linux/amd64
environment:
- APP_HOST=0.0.0.0
- APP_PORT=8080
- POSTGRES_USER=username
- POSTGRES_PASS=password
- POSTGRES_DBNAME=postgis
- POSTGRES_HOST_READER=pgstac
- POSTGRES_HOST_WRITER=pgstac
- POSTGRES_PORT=5432
- WEB_CONCURRENCY=10
ports:
- "8080:8080"
depends_on:
- pgstac

pgstac:
image: ghcr.io/stac-utils/pgstac:v0.6.13
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgis
- PGUSER=username
- PGPASSWORD=password
- PGHOST=localhost
- PGDATABASE=postgis
ports:
- "5439:5432"
command: postgres -N 500

migrate:
image: ghcr.io/stac-utils/stac-fastapi:latest-sqlalchemy
command: bash -c "cd /app && alembic upgrade head"
environment:
- POSTGRES_USER=username
- POSTGRES_PASS=password
- POSTGRES_DBNAME=postgis
- POSTGRES_HOST=pgstac
- POSTGRES_PORT=5432
depends_on:
- stac-fastapi-sqlalchemy

networks:
default:
name: stac-fastapi-network

0 comments on commit 7ba0a40

Please sign in to comment.