Skip to content

Commit a709b72

Browse files
authored
Merge pull request #197 from datakind/aws-migration
AWS Colandr 2.0 Migration
2 parents 1f509b4 + bb49def commit a709b72

28 files changed

+975
-2015
lines changed

colandr/app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import apiflask as af
66
import flask
77
import flask.logging
8+
from werkzeug.middleware.proxy_fix import ProxyFix
89

910
from colandr import cli, config, extensions
1011
from colandr.api import v1
@@ -29,6 +30,20 @@ def _create_app_v1_1(
2930
if config_overrides:
3031
app.config.update(config_overrides)
3132

33+
# Trust X-Forwarded-Proto/Host only when the sole client is our reverse proxy.
34+
# See docs/proxy-security.md: never expose port 5000 to the public.
35+
app.wsgi_app = t.cast(t.Any, ProxyFix(app.wsgi_app, x_proto=1, x_host=1))
36+
37+
@app.before_request
38+
def set_openapi_servers_from_request() -> None:
39+
# Ensure Swagger "Try it out" uses the current host+scheme.
40+
#
41+
# In production behind nginx, ProxyFix (above) + X-Forwarded-* headers
42+
# make `request.url_root` resolve to `https://api.colandrapp.com/`.
43+
if flask.request.endpoint in ("openapi.docs", "openapi.spec"):
44+
url_root = flask.request.url_root.rstrip("/")
45+
app.config["SERVERS"] = [{"url": url_root, "description": "API"}]
46+
3247
_configure_logging(app)
3348
_register_extensions(app)
3449
v1.register_api_blueprints(app)

compose.prod.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# compose.prod.yaml
2+
#
3+
# Standalone production Docker Compose file
4+
# Only includes services needed for production: api, worker, broker
5+
#
6+
# Usage:
7+
# docker compose -f compose.prod.yaml up -d
8+
9+
services:
10+
# API service
11+
api:
12+
container_name: colandr-api
13+
build:
14+
context: "."
15+
dockerfile: Dockerfile.api
16+
target: prod
17+
platform: linux/amd64
18+
depends_on:
19+
- broker
20+
- worker
21+
stop_signal: SIGINT
22+
healthcheck:
23+
test: [ "CMD", "curl", "--fail", "--silent", "localhost:5000/api/health" ]
24+
interval: "30s"
25+
timeout: "5s"
26+
start_period: "15s"
27+
retries: 3
28+
env_file: ".env"
29+
environment:
30+
- FLASK_APP=colandr.app:create_app()
31+
- BUILD_TARGET=prod
32+
- FLASK_ENV=production
33+
ports:
34+
# Bind to localhost only so only the reverse proxy (e.g. nginx on this host)
35+
# can reach the API. Required for ProxyFix security (see docs/proxy-security.md).
36+
- "127.0.0.1:5000:5000"
37+
restart: unless-stopped
38+
volumes:
39+
- ${COLANDR_DATA_DIR:-./colandr_data}:${COLANDR_FILESYSTEM_ROOT_DIR:-/app/data}
40+
- ./scripts:/app/scripts
41+
logging:
42+
driver: "json-file"
43+
options:
44+
max-size: "10m"
45+
max-file: "3"
46+
47+
# Worker service
48+
worker:
49+
container_name: colandr-worker
50+
build:
51+
context: "."
52+
dockerfile: Dockerfile.worker
53+
target: prod
54+
platform: linux/amd64
55+
depends_on:
56+
- broker
57+
stop_signal: SIGINT
58+
healthcheck:
59+
test: ["CMD-SHELL", "celery --app=make_celery.celery_app inspect ping --destination celery@$$HOSTNAME"]
60+
interval: "30s"
61+
timeout: "10s"
62+
retries: 3
63+
env_file: ".env"
64+
environment:
65+
- BUILD_TARGET=prod
66+
- FLASK_ENV=production
67+
restart: unless-stopped
68+
volumes:
69+
- ${COLANDR_DATA_DIR:-./colandr_data}:${COLANDR_FILESYSTEM_ROOT_DIR:-/app/data}
70+
logging:
71+
driver: "json-file"
72+
options:
73+
max-size: "10m"
74+
max-file: "3"
75+
76+
# Broker (Redis)
77+
broker:
78+
container_name: colandr-broker
79+
image: "redis:8.0"
80+
restart: unless-stopped
81+
stop_grace_period: 5s
82+
volumes:
83+
- broker-data:/data
84+
healthcheck:
85+
test: "redis-cli ping"
86+
interval: 10s
87+
timeout: 5s
88+
retries: 5
89+
logging:
90+
driver: "json-file"
91+
options:
92+
max-size: "10m"
93+
max-file: "3"
94+
95+
volumes:
96+
broker-data:
97+
driver: local
98+
frontend-storage:
99+
driver: local
100+
101+
networks:
102+
default:
103+
name: "colandr-back"

compose.yml renamed to compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ services:
126126
- broker
127127
stop_signal: SIGINT
128128
healthcheck:
129-
test: ["CMD-SHELL", "celery", "--app=make_celery.celery_app", "inspect", "ping", "--destination celery@$$HOSTNAME"]
129+
test: ["CMD-SHELL", "celery --app=make_celery.celery_app inspect ping --destination celery@$$HOSTNAME"]
130130
interval: "30s"
131131
timeout: "10s"
132132
retries: 3

deployment/README.md

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

0 commit comments

Comments
 (0)