docker-compose.yml + .env and setup for postgres, jwt, hostnames + healthchecks
This commit is contained in:
22
.env
Normal file
22
.env
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Trusted hostname
|
||||||
|
HOSTNAME=localhost
|
||||||
|
|
||||||
|
# --- Container ports and hostnames ---
|
||||||
|
|
||||||
|
BACKEND_HOST=personal-site-backend
|
||||||
|
FRONTEND_HOST=personal-site-frontend
|
||||||
|
DB_HOST=personal-site-db
|
||||||
|
|
||||||
|
# --- Database settings ---
|
||||||
|
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=postgres
|
||||||
|
DB_DB=data
|
||||||
|
|
||||||
|
# --- JWT token settings ---
|
||||||
|
|
||||||
|
JWT_SECRET=ThisValueIsObviouslyVerySecret
|
||||||
|
JWT_EXPIRATION_ACCESS=2m # Expiration time for access tokens
|
||||||
|
JWT_EXPIRATION_REFRESH=7d # Expiration time for refresh tokens
|
||||||
|
JWT_ISSUER=personal-site
|
||||||
|
JWT_AUDIENCE=users
|
||||||
@@ -4,28 +4,53 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
depends_on:
|
hostname: ${FRONTEND_HOST}
|
||||||
- backend
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://${FRONTEND_HOST}:3000/health"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=postgresql://user:password@database:5432/db # Adjust as needed
|
- DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_DB}
|
||||||
|
- JWT_SECRET=${JWT_SECRET}
|
||||||
|
- JWT_EXPIRATION_ACCESS=${JWT_EXPIRATION_ACCESS}
|
||||||
|
- JWT_EXPIRATION_REFRESH=${JWT_EXPIRATION_REFRESH}
|
||||||
|
- JWT_ISSUER=${JWT_ISSUER}
|
||||||
|
- JWT_AUDIENCE=${JWT_AUDIENCE}
|
||||||
networks:
|
networks:
|
||||||
- internal_network
|
- internal_network
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
hostname: ${BACKEND_HOST}
|
||||||
links:
|
links:
|
||||||
- db:database
|
- db:database
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://${BACKEND_HOST}:3000/health"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: user # Change to your desired username
|
POSTGRES_USER: ${DB_USER}
|
||||||
POSTGRES_PASSWORD: password # Change to your desired password
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
POSTGRES_DB: db # Change to your desired database name
|
POSTGRES_DB: ${DB_DB}
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
hostname: ${DB_HOST}
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "pg_isready", "-U", "user"]
|
||||||
|
interval: 1s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 20
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user