Skip to content

Commit df1de10

Browse files
authored
Update makefile, compose files (#379)
- rename docker-compose.yml to compose.yml - created a separate compose file for tests, allows api to be run locally via docker compose up without tests running - fixed make docker-run-nginx-proxy which relied on a non-existent file before - added volumes to app and tests service to allow for changes without re-building
1 parent 0d758af commit df1de10

9 files changed

Lines changed: 198 additions & 110 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- remove pgstac 0.8.6 in tests and update documentation ([#354](https://github.com/stac-utils/stac-fastapi-pgstac/pull/354))
88
- simplify `extensions.query.Operator` class, by removing unused `operator` method and unncessary dependencies ([#364](https://github.com/stac-utils/stac-fastapi-pgstac/pull/364))
99
- handle `ENABLE_TRANSACTIONS_EXTENSIONS`, `ENABLED_EXTENSIONS` and `UVICORN_ROOT_PATH` environment configuration variables via the `config.Settings` class ([#368](https://github.com/stac-utils/stac-fastapi-pgstac/pull/368))
10+
- Refactor Docker Compose files and Makefile for better organization and modularity. ([#379](https://github.com/stac-utils/stac-fastapi-pgstac/pull/379))
1011

1112
### Added
1213

Makefile

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,41 @@ run = docker compose run --rm \
1010
-e APP_PORT=${APP_PORT} \
1111
app
1212

13-
runtests = docker compose run --rm tests
13+
runtests = docker compose -f compose.yml -f compose.tests.yml run --rm tests
1414

1515
.PHONY: image
1616
image:
1717
docker compose build
1818

19+
.PHONY: image-tests
20+
image-tests:
21+
docker compose -f compose.yml -f compose.tests.yml build
22+
1923
.PHONY: docker-run
2024
docker-run: image
2125
docker compose up
2226

2327
.PHONY: docker-run-nginx-proxy
24-
docker-run-nginx-proxy:
25-
docker compose -f docker-compose.yml -f docker-compose.nginx.yml up
28+
docker-run-nginx-proxy: image
29+
docker compose -f compose.yml -f compose.nginx.yml up
30+
31+
.PHONY: docker-down
32+
docker-down:
33+
docker compose down
34+
35+
.PHONY: docker-down-nginx
36+
docker-down-nginx:
37+
docker compose -f compose.yml -f compose.nginx.yml down
38+
39+
.PHONY: docker-down-tests
40+
docker-down-tests:
41+
docker compose -f compose.yml -f compose.tests.yml down
42+
43+
.PHONY: docker-down-all
44+
docker-down-all:
45+
docker compose down
46+
docker compose -f compose.yml -f compose.nginx.yml down
47+
docker compose -f compose.yml -f compose.tests.yml down
2648

2749
.PHONY: docker-shell
2850
docker-shell:
@@ -36,9 +58,9 @@ test:
3658
run-database:
3759
docker compose run --rm database
3860

39-
.PHONY: run-joplin
40-
run-joplin:
41-
docker compose run --rm loadjoplin
61+
.PHONY: load-joplin
62+
load-joplin:
63+
python scripts/ingest_joplin.py http://localhost:8082
4264

4365
.PHONY: install
4466
install:

README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pypgstac migrate
6161

6262
## Development
6363

64+
### Quick Start
65+
6466
Install the packages in editable mode:
6567

6668
We recommend using [`uv`](https://docs.astral.sh/uv) as project manager for development.
@@ -71,17 +73,60 @@ See https://docs.astral.sh/uv/getting-started/installation/ for installation
7173
uv sync --dev
7274
```
7375

74-
To run the tests:
76+
### Running the API Locally
77+
78+
Start the API with Docker Compose:
79+
80+
```shell
81+
make docker-run
82+
```
83+
84+
The API will be available at `http://localhost:8082`
85+
86+
### Running with Nginx Proxy
87+
88+
To run the API behind an Nginx proxy:
89+
90+
```shell
91+
make docker-run-nginx-proxy
92+
```
93+
94+
The API will be available at:
95+
- Direct: `http://localhost:8082`
96+
- Via Nginx: `http://localhost:8080/api/v1/pgstac/`
97+
98+
### Loading Demo Data
99+
100+
To load the Joplin demo dataset:
101+
102+
```shell
103+
make load-joplin
104+
```
105+
106+
### Running Tests
107+
108+
To run tests locally (requires postgres/postgis system packages):
75109

76110
```shell
77111
uv run pytest
78112
```
79113

80-
**NOTE:** In order for the above commands to work, you need a number of postgres/postgis system packages to be installed. If running the tests directly on your machine doesn't work, another way is to spin up a test container and run the tests in that container. You need [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed.
114+
**NOTE:** If running tests directly on your machine doesn't work, you can use Docker Compose instead. You need [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed.
115+
116+
To run tests in a container:
117+
118+
```shell
119+
make test
120+
```
121+
122+
### Stopping Services
123+
124+
To stop running services:
81125

82-
To run the tests in the test container:
83126
```shell
84-
docker compose run --build --rm tests python -m pytest -s -vv
127+
make docker-down # Stop the default app
128+
make docker-down-nginx # Stop the nginx variant
129+
make docker-down-all # Stop all services
85130
```
86131

87132
## Contributing

compose.nginx.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
app:
3+
command: >
4+
bash -c "
5+
scripts/wait-for-it.sh database:5432 &&
6+
uvicorn stac_fastapi.pgstac.app:app --host 0.0.0.0 --port 8082 --proxy-headers --forwarded-allow-ips=* --root-path=/api/v1/pgstac
7+
"
8+
9+
nginx:
10+
image: nginx
11+
ports:
12+
- ${STAC_FASTAPI_NGINX_PORT:-8080}:80
13+
volumes:
14+
- ./nginx.conf:/etc/nginx/nginx.conf
15+
depends_on:
16+
- app
17+
command: [ "nginx-debug", "-g", "daemon off;" ]

compose.tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
tests:
3+
image: stac-utils/stac-fastapi-pgstac-test
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.tests
7+
environment:
8+
- ENVIRONMENT=local
9+
- DB_MIN_CONN_SIZE=1
10+
- DB_MAX_CONN_SIZE=1
11+
- USE_API_HYDRATE=${USE_API_HYDRATE:-false}
12+
volumes:
13+
- ./stac_fastapi:/app/stac_fastapi
14+
- ./tests:/app/tests
15+
depends_on:
16+
- database
17+
command: bash -c "python -m pytest -s -vv"

compose.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
services:
2+
app:
3+
image: stac-utils/stac-fastapi-pgstac
4+
build: .
5+
environment:
6+
- APP_HOST=0.0.0.0
7+
- APP_PORT=8082
8+
- RELOAD=true
9+
- ENVIRONMENT=local
10+
- PGUSER=username
11+
- PGPASSWORD=password
12+
- PGDATABASE=postgis
13+
- PGHOST=database
14+
- PGPORT=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+
- ENABLE_TRANSACTIONS_EXTENSIONS=TRUE
23+
ports:
24+
- "8082:8082"
25+
volumes:
26+
- ./stac_fastapi:/app/stac_fastapi
27+
depends_on:
28+
- database
29+
command: bash -c "scripts/wait-for-it.sh database:5432 && python -m stac_fastapi.pgstac.app"
30+
develop:
31+
watch:
32+
- action: rebuild
33+
path: ./stac_fastapi/pgstac
34+
35+
database:
36+
image: ghcr.io/stac-utils/pgstac:v0.9.8
37+
environment:
38+
- POSTGRES_USER=username
39+
- POSTGRES_PASSWORD=password
40+
- POSTGRES_DB=postgis
41+
- PGUSER=username
42+
- PGPASSWORD=password
43+
- PGDATABASE=postgis
44+
ports:
45+
- "5439:5432"
46+
command: postgres -N 500
47+
48+
networks:
49+
default:
50+
name: stac-fastapi-network

docker-compose.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

nginx.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ http {
66

77
location /api/v1/pgstac {
88
rewrite ^/api/v1/pgstac(.*)$ $1 break;
9-
proxy_pass http://app-nginx:8082;
9+
proxy_pass http://app:8082;
1010
proxy_set_header HOST $http_host;
1111
proxy_set_header Referer $http_referer;
1212
proxy_set_header X-Forwarded-For $remote_addr;
@@ -18,4 +18,4 @@ http {
1818
proxy_redirect off;
1919
}
2020
}
21-
}
21+
}

scripts/load-joplin.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Load Joplin demo dataset into the STAC API
3+
4+
set -e
5+
6+
# Default to regular app
7+
APP_HOST=${APP_HOST:-"http://localhost:8082"}
8+
MAX_RETRIES=60
9+
RETRY_DELAY=1
10+
11+
echo "Waiting for API to be ready at $APP_HOST..."
12+
13+
# Wait for the API to be ready
14+
for i in $(seq 1 $MAX_RETRIES); do
15+
if curl -s "$APP_HOST" > /dev/null 2>&1; then
16+
echo "API is ready!"
17+
break
18+
fi
19+
if [ $i -eq $MAX_RETRIES ]; then
20+
echo "API did not become ready after ${MAX_RETRIES} seconds"
21+
exit 1
22+
fi
23+
echo "Attempt $i/$MAX_RETRIES: Waiting for API..."
24+
sleep $RETRY_DELAY
25+
done
26+
27+
echo "Installing dependencies..."
28+
python -m pip install -q pip -U
29+
python -m pip install -q requests
30+
31+
echo "Loading Joplin Collection..."
32+
python /app/scripts/ingest_joplin.py "$APP_HOST"
33+
34+
echo "All Done! Joplin data loaded successfully."

0 commit comments

Comments
 (0)