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:
|
||||
context: ./frontend
|
||||
dockerfile: Dockerfile
|
||||
depends_on:
|
||||
- backend
|
||||
hostname: ${FRONTEND_HOST}
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://${FRONTEND_HOST}:3000/health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ./backend
|
||||
dockerfile: Dockerfile
|
||||
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:
|
||||
- internal_network
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
hostname: ${BACKEND_HOST}
|
||||
links:
|
||||
- db:database
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://${BACKEND_HOST}:3000/health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
db:
|
||||
image: postgres:latest
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_USER: user # Change to your desired username
|
||||
POSTGRES_PASSWORD: password # Change to your desired password
|
||||
POSTGRES_DB: db # Change to your desired database name
|
||||
POSTGRES_USER: ${DB_USER}
|
||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||
POSTGRES_DB: ${DB_DB}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
hostname: ${DB_HOST}
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "user"]
|
||||
interval: 1s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
Reference in New Issue
Block a user