fix: nginx dns re-resolve, db healthcheck, explicit bind
This commit is contained in:
@@ -5,8 +5,14 @@ server {
|
|||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
|
# Docker's embedded DNS. Without re-resolving at request time, nginx caches the
|
||||||
|
# api container's IP from startup and keeps returning 502 ("no live upstreams")
|
||||||
|
# after the api container restarts with a new IP.
|
||||||
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://api:3000;
|
set $api_upstream http://api:3000;
|
||||||
|
proxy_pass $api_upstream$request_uri;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@@ -77633,7 +77633,7 @@ async function bootstrap() {
|
|||||||
app.useGlobalPipes(new common_1.ValidationPipe({ whitelist: true, transform: true }));
|
app.useGlobalPipes(new common_1.ValidationPipe({ whitelist: true, transform: true }));
|
||||||
app.useGlobalFilters(new prisma_exception_filter_1.PrismaExceptionFilter());
|
app.useGlobalFilters(new prisma_exception_filter_1.PrismaExceptionFilter());
|
||||||
app.enableCors();
|
app.enableCors();
|
||||||
await app.listen(process.env.PORT ?? 3e3);
|
await app.listen(process.env.PORT ?? 3e3, "0.0.0.0");
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
/*! Bundled license information:
|
/*! Bundled license information:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ async function bootstrap() {
|
|||||||
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
||||||
app.useGlobalFilters(new PrismaExceptionFilter());
|
app.useGlobalFilters(new PrismaExceptionFilter());
|
||||||
app.enableCors();
|
app.enableCors();
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
// Bind all interfaces explicitly so the container is reachable from nginx.
|
||||||
|
await app.listen(process.env.PORT ?? 3000, '0.0.0.0');
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@@ -5,8 +5,14 @@ server {
|
|||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
|
# Docker's embedded DNS. Without re-resolving at request time, nginx caches the
|
||||||
|
# api container's IP from startup and keeps returning 502 ("no live upstreams")
|
||||||
|
# after the api container restarts with a new IP.
|
||||||
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://api:3000;
|
set $api_upstream http://api:3000;
|
||||||
|
proxy_pass $api_upstream$request_uri;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
+8
-1
@@ -13,14 +13,21 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-goldbank}"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 12
|
||||||
|
|
||||||
api:
|
api:
|
||||||
build:
|
build:
|
||||||
context: ./apps/api
|
context: ./apps/api
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: goldbank_api
|
container_name: goldbank_api
|
||||||
|
# Prisma connects on module init, so a not-yet-ready DB crash-loops the API.
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
db:
|
||||||
|
condition: service_healthy
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=${DATABASE_URL:-postgresql://postgres:postgres@db:5432/goldbank?schema=public}
|
- DATABASE_URL=${DATABASE_URL:-postgresql://postgres:postgres@db:5432/goldbank?schema=public}
|
||||||
- PORT=${PORT:-3000}
|
- PORT=${PORT:-3000}
|
||||||
|
|||||||
Reference in New Issue
Block a user