Skip to content

Commit 1de7b8b

Browse files
geospatial-jeffc-wygodagadomskimoradology
authored
Add nginx service as second docker-compose stack (#503)
* add nginx service to docker-compose, proxy pgstac and sqlalchemy apps * Update docker-compose.yml Co-authored-by: Christian Wygoda <[email protected]> * feat: add nginx proxy in own docker-compose file Includes a Makefile rule to run it, and some documentation in README.md. Also adds a markdownlint silencer and one or two touchups to the whitespace. * Update changelog --------- Co-authored-by: Christian Wygoda <[email protected]> Co-authored-by: Pete Gadomski <[email protected]> Co-authored-by: Nathan Zimmerman <[email protected]>
1 parent 2482467 commit 1de7b8b

File tree

7 files changed

+75
-1
lines changed

7 files changed

+75
-1
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
* Nginx service as second docker-compose stack to demonstrate proxy ([#503](https://github.com/stac-utils/stac-fastapi/pull/503))
78
* 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))
89
* Required links to the sqlalchemy ItemCollection endpoint ([#508](https://github.com/stac-utils/stac-fastapi/pull/508))
910
* Publication of docker images to GHCR ([#525](https://github.com/stac-utils/stac-fastapi/pull/525))

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ docker-run-sqlalchemy: image
3030
docker-run-pgstac: image
3131
$(run_pgstac)
3232

33+
.PHONY: docker-run-nginx-proxy
34+
docker-run-nginx-proxy:
35+
docker-compose -f docker-compose.yml -f docker-compose.nginx.yml up
36+
3337
.PHONY: docker-shell-sqlalchemy
3438
docker-shell-sqlalchemy:
3539
$(run_sqlalchemy) /bin/bash

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
2+
13
<p align="center">
24
<img src="https://github.com/radiantearth/stac-site/raw/master/images/logo/stac-030-long.png" width=400>
35
<p align="center">FastAPI implemention of the STAC API spec.</p>
@@ -101,7 +103,23 @@ The application will be started on <http://localhost:8080>.
101103
By default, the apps are run with uvicorn hot-reloading enabled. This can be turned off by changing the value
102104
of the `RELOAD` env var in docker-compose.yml to `false`.
103105

104-
#### Note to Docker for Windows users
106+
### nginx proxy
107+
108+
This repo includes an example nginx proxy service.
109+
To start:
110+
111+
```shell
112+
make docker-run-nginx-proxy
113+
```
114+
115+
The proxy will be started on <http://localhost>, with the pgstac app available at <http://localhost/api/v1/pgstac/> and the sqlalchemy app at <http://localhost/api/v1/sqlalchemy/>.
116+
If you need to customize the proxy port, use the `STAC_FASTAPI_NGINX_PORT` environment variable:
117+
118+
```shell
119+
STAC_FASTAPI_NGINX_PORT=7822 make docker-run-nginx-proxy
120+
```
121+
122+
### Note to Docker for Windows users
105123

106124
You'll need to enable experimental features on Docker for Windows in order to run the docker-compose,
107125
due to the "--platform" flag that is required to allow the project to run on some Apple architectures.

docker-compose.nginx.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3'
2+
services:
3+
nginx:
4+
image: nginx
5+
ports:
6+
- ${STAC_FASTAPI_NGINX_PORT:-80}:80
7+
volumes:
8+
- ./nginx.conf:/etc/nginx/nginx.conf
9+
depends_on:
10+
- app-pgstac
11+
- app-sqlalchemy
12+
command: [ "nginx-debug", "-g", "daemon off;" ]
13+
app-pgstac:
14+
environment:
15+
- UVICORN_ROOT_PATH=/api/v1/pgstac
16+
app-sqlalchemy:
17+
environment:
18+
- UVICORN_ROOT_PATH=/api/v1/sqlalchemy

nginx.conf

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
events {}
2+
3+
http {
4+
server {
5+
listen 80;
6+
7+
location /api/v1/pgstac {
8+
rewrite ^/api/v1/pgstac(.*)$ $1 break;
9+
proxy_pass http://app-pgstac:8082;
10+
proxy_set_header HOST $host;
11+
proxy_set_header Referer $http_referer;
12+
proxy_set_header X-Forwarded-For $remote_addr;
13+
proxy_set_header X-Forwarded-Proto $scheme;
14+
}
15+
16+
location /api/v1/sqlalchemy {
17+
rewrite ^/api/v1/sqlalchemy(.*)$ $1 break;
18+
proxy_pass http://app-sqlalchemy:8081;
19+
proxy_set_header HOST $host;
20+
proxy_set_header Referer $http_referer;
21+
proxy_set_header X-Forwarded-For $remote_addr;
22+
proxy_set_header X-Forwarded-Proto $scheme;
23+
}
24+
25+
location / {
26+
proxy_redirect off;
27+
}
28+
}
29+
}

stac_fastapi/pgstac/stac_fastapi/pgstac/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def run():
8888
port=settings.app_port,
8989
log_level="info",
9090
reload=settings.reload,
91+
root_path=os.getenv("UVICORN_ROOT_PATH", ""),
9192
)
9293
except ImportError:
9394
raise RuntimeError("Uvicorn must be installed in order to use command")

stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""FastAPI application."""
2+
import os
3+
24
from stac_fastapi.api.app import StacApi
35
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
46
from stac_fastapi.extensions.core import (
@@ -55,6 +57,7 @@ def run():
5557
port=settings.app_port,
5658
log_level="info",
5759
reload=settings.reload,
60+
root_path=os.getenv("UVICORN_ROOT_PATH", ""),
5861
)
5962
except ImportError:
6063
raise RuntimeError("Uvicorn must be installed in order to use command")

0 commit comments

Comments
 (0)