Skip to content

Commit 8736777

Browse files
committed
ci, docker: add backend-specific dockerfiles
1 parent 0bd1603 commit 8736777

10 files changed

+201
-2
lines changed

.github/workflows/cicd.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,41 @@ jobs:
187187
- uses: actions/checkout@v3
188188
- name: Test generating docs
189189
run: make docs
190+
191+
docker-build-push:
192+
runs-on: ubuntu-latest
193+
needs: [test, validate, test-docs]
194+
permissions:
195+
contents: read
196+
packages: write
197+
strategy:
198+
fail-fast: true
199+
matrix:
200+
backend: ["sqlalchemy", "pgstac"]
201+
steps:
202+
- name: Checkout repository
203+
uses: actions/checkout@v3
204+
- name: Log in to the Container registry
205+
uses: docker/login-action@v2.1.0
206+
with:
207+
registry: ghcr.io
208+
username: ${{ github.actor }}
209+
password: ${{ secrets.GITHUB_TOKEN }}
210+
- name: Extract metadata (tags, labels) for Docker
211+
id: meta
212+
uses: docker/metadata-action@v4.3.0
213+
with:
214+
images: ghcr.io/stac-utils/stac-fastapi
215+
tags: |
216+
type=schedule,suffix=-${{ matrix.backend }}
217+
type=ref,event=branch,suffix=-${{ matrix.backend }}
218+
type=ref,event=tag,suffix=-${{ matrix.backend }}
219+
type=ref,event=pr,suffix=-${{ matrix.backend }}
220+
- name: Build and push Docker image
221+
uses: docker/build-push-action@v4.0.0
222+
with:
223+
context: .
224+
file: docker/Dockerfile.${{ matrix.backend }}
225+
push: true
226+
tags: ${{ steps.meta.outputs.tags }}
227+
labels: ${{ steps.meta.outputs.labels }}

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ packages:
3030
- **stac_fastapi.types**: Shared types and abstract base classes used by the library.
3131

3232
#### Backends
33+
3334
- **stac_fastapi.sqlalchemy**: Postgres backend implementation with sqlalchemy.
3435
- **stac_fastapi.pgstac**: Postgres backend implementation with [PGStac](https://github.com/stac-utils/pgstac).
3536

@@ -61,9 +62,25 @@ pip install -e stac_fastapi/sqlalchemy
6162
pip install -e stac_fastapi/pgstac
6263
```
6364

65+
### Pre-built Docker images
66+
67+
Pre-built images are available from the [Github Container Registry](https://github.com/stac-utils/stac-fastapi/pkgs/container/stac-fastapi).
68+
The latest images are tagged with `latest-pgstac` and `latest-sqlalchemy`.
69+
To pull the image to your local system:
70+
71+
```shell
72+
docker pull ghcr.io/stac-utils/stac-fastapi:latest-pgstac # or latest-sqlalchemy
73+
```
74+
75+
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:
76+
77+
- [docker-compose.pgstac.yml](./docker/docker-compose.pgstac.yml)
78+
- [docker-compose.sqlalchemy.yml](./docker/docker-compose.sqlalchemy.yml)
79+
6480
## Local Development
6581

6682
Use docker-compose via make to start the application, migrate the database, and ingest some example data:
83+
6784
```bash
6885
make image
6986
make docker-run-all

docker-compose.docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
container_name: stac-fastapi-docs-dev
66
build:
77
context: .
8-
dockerfile: Dockerfile.docs
8+
dockerfile: docker/Dockerfile.docs
99
platform: linux/amd64
1010
environment:
1111
- POSTGRES_USER=username

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
image: stac-utils/stac-fastapi
66
build:
77
context: .
8-
dockerfile: Dockerfile
8+
dockerfile: docker/Dockerfile
99
platform: linux/amd64
1010
environment:
1111
- APP_HOST=0.0.0.0
File renamed without changes.
File renamed without changes.

docker/Dockerfile.pgstac

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM python:3.8-slim as builder
2+
3+
RUN python -m venv /opt/venv
4+
5+
ENV PATH="/opt/venv/bin:$PATH"
6+
7+
WORKDIR /app
8+
9+
COPY . /app
10+
11+
RUN pip install ./stac_fastapi/types && \
12+
pip install ./stac_fastapi/api && \
13+
pip install ./stac_fastapi/extensions && \
14+
pip install ./stac_fastapi/pgstac[server]
15+
16+
17+
FROM python:3.8-slim as pgstac
18+
19+
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
20+
21+
COPY --from=builder /opt/venv /opt/venv
22+
23+
ENV PATH="/opt/venv/bin:$PATH"
24+
25+
CMD ["uvicorn", "stac_fastapi.pgstac.app:app", "--host", "0.0.0.0", "--port", "8080"]

docker/Dockerfile.sqlalchemy

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM python:3.8-slim as builder
2+
3+
RUN python -m venv /opt/venv
4+
5+
ENV PATH="/opt/venv/bin:$PATH"
6+
7+
WORKDIR /app
8+
9+
COPY . /app
10+
11+
RUN pip install ./stac_fastapi/types && \
12+
pip install ./stac_fastapi/api && \
13+
pip install ./stac_fastapi/extensions && \
14+
pip install ./stac_fastapi/sqlalchemy[server]
15+
16+
17+
FROM python:3.8-slim as sqlalchemy
18+
19+
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
20+
21+
COPY --from=builder /opt/venv /opt/venv
22+
COPY ./stac_fastapi/sqlalchemy/alembic /app/alembic
23+
COPY ./stac_fastapi/sqlalchemy/alembic.ini /app/alembic.ini
24+
25+
ENV PATH="/opt/venv/bin:$PATH"
26+
27+
CMD ["uvicorn", "stac_fastapi.sqlalchemy.app:app", "--host", "0.0.0.0", "--port", "8080"]

docker/docker-compose.pgstac.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3'
2+
services:
3+
stac-fastapi-pgstac:
4+
image: ghcr.io/stac-utils/stac-fastapi:latest-pgstac
5+
platform: linux/amd64
6+
environment:
7+
- APP_HOST=0.0.0.0
8+
- ENVIRONMENT=local
9+
- POSTGRES_USER=username
10+
- POSTGRES_PASS=password
11+
- POSTGRES_DBNAME=postgis
12+
- POSTGRES_HOST_READER=pgstac
13+
- POSTGRES_HOST_WRITER=pgstac
14+
- POSTGRES_PORT=5432
15+
- WEB_CONCURRENCY=10
16+
- VSI_CACHE=TRUE
17+
- GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES
18+
- GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR
19+
- DB_MIN_CONN_SIZE=1
20+
- DB_MAX_CONN_SIZE=1
21+
- USE_API_HYDRATE=${USE_API_HYDRATE:-false}
22+
ports:
23+
- "8080:8080"
24+
depends_on:
25+
- pgstac
26+
27+
pgstac:
28+
image: ghcr.io/stac-utils/pgstac:v0.6.13
29+
environment:
30+
- POSTGRES_USER=username
31+
- POSTGRES_PASSWORD=password
32+
- POSTGRES_DB=postgis
33+
- PGUSER=username
34+
- PGPASSWORD=password
35+
- PGHOST=localhost
36+
- PGDATABASE=postgis
37+
ports:
38+
- "5439:5432"
39+
command: postgres -N 500
40+
41+
networks:
42+
default:
43+
name: stac-fastapi-network

docker/docker-compose.sqlalchemy.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: '3'
2+
services:
3+
stac-fastapi-sqlalchemy:
4+
image: ghcr.io/stac-utils/stac-fastapi:latest-sqlalchemy
5+
platform: linux/amd64
6+
environment:
7+
- APP_HOST=0.0.0.0
8+
- APP_PORT=8080
9+
- POSTGRES_USER=username
10+
- POSTGRES_PASS=password
11+
- POSTGRES_DBNAME=postgis
12+
- POSTGRES_HOST_READER=pgstac
13+
- POSTGRES_HOST_WRITER=pgstac
14+
- POSTGRES_PORT=5432
15+
- WEB_CONCURRENCY=10
16+
ports:
17+
- "8080:8080"
18+
depends_on:
19+
- pgstac
20+
21+
pgstac:
22+
image: ghcr.io/stac-utils/pgstac:v0.6.13
23+
environment:
24+
- POSTGRES_USER=username
25+
- POSTGRES_PASSWORD=password
26+
- POSTGRES_DB=postgis
27+
- PGUSER=username
28+
- PGPASSWORD=password
29+
- PGHOST=localhost
30+
- PGDATABASE=postgis
31+
ports:
32+
- "5439:5432"
33+
command: postgres -N 500
34+
35+
migrate:
36+
image: ghcr.io/stac-utils/stac-fastapi:latest-sqlalchemy
37+
command: bash -c "cd /app && alembic upgrade head"
38+
environment:
39+
- POSTGRES_USER=username
40+
- POSTGRES_PASS=password
41+
- POSTGRES_DBNAME=postgis
42+
- POSTGRES_HOST=pgstac
43+
- POSTGRES_PORT=5432
44+
depends_on:
45+
- stac-fastapi-sqlalchemy
46+
47+
networks:
48+
default:
49+
name: stac-fastapi-network

0 commit comments

Comments
 (0)