forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
185 lines (177 loc) · 4.98 KB
/
Copy pathdocker-compose.yml
File metadata and controls
185 lines (177 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
services:
postgres:
build:
context: ./postgres
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- .env.example
environment:
POSTGRES_DB: ${POSTGRES_DB:-nova_rewards}
POSTGRES_USER: ${POSTGRES_USER:-nova}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./database:/docker-entrypoint-initdb.d:ro
- ./backups/wal:/var/lib/postgresql/wal-archive
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-nova} -d ${POSTGRES_DB:-nova_rewards}"]
interval: 5s
timeout: 5s
retries: 10
ports:
- "5432:5432"
command:
- postgres
- -c
- wal_level=replica
- -c
- archive_mode=on
- -c
- archive_timeout=60s
- -c
- max_wal_senders=3
- -c
- archive_command=/usr/local/bin/archive-wal.sh %p %f
# Runs pending migrations once on every `docker compose up`
migrate:
image: node:20-alpine
working_dir: /app
command: sh -c "npm install --prefix /app/database 2>/dev/null; node database/migrate.js"
env_file:
- .env.example
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-nova}:${POSTGRES_PASSWORD:-changeme}@postgres:5432/${POSTGRES_DB:-nova_rewards}
NODE_ENV: ${NODE_ENV:-development}
volumes:
- .:/app
depends_on:
postgres:
condition: service_healthy
restart: "no"
redis:
image: redis:7-alpine
restart: unless-stopped
command: >
redis-server
--appendonly yes
--appendfsync everysec
--save 900 1
--save 300 10
--save 60 10000
--maxmemory ${REDIS_MAXMEMORY:-256mb}
--maxmemory-policy allkeys-lru
ports:
- "6379:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
# Scheduled PostgreSQL backups (runs every 6 hours via supercronic)
pg-backup:
image: postgres:16-alpine
restart: unless-stopped
env_file:
- .env.example
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-nova}:${POSTGRES_PASSWORD:-changeme}@postgres:5432/${POSTGRES_DB:-nova_rewards}
BACKUP_RETAIN_DAYS: ${BACKUP_RETAIN_DAYS:-7}
BACKUP_S3_BUCKET: ${BACKUP_S3_BUCKET:-}
AWS_REGION: ${AWS_REGION:-us-east-1}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}
volumes:
- ./scripts/pg-backup.sh:/usr/local/bin/pg-backup.sh:ro
- pg_backups:/backups
depends_on:
postgres:
condition: service_healthy
# Run backup on container start, then every 6 hours via crond
command: >
sh -c "
apk add --no-cache aws-cli &&
chmod +x /usr/local/bin/pg-backup.sh &&
echo '0 */6 * * * /usr/local/bin/pg-backup.sh >> /var/log/pg-backup.log 2>&1' | crontab - &&
/usr/local/bin/pg-backup.sh &&
crond -f -l 8
"
# One-shot service: runs all pending migrations then exits.
# backend depends on this completing successfully before it starts.
migrate:
build:
context: ./backend
dockerfile: Dockerfile
command: ["node", "/migrations/migrate.js"]
env_file:
- .env
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-nova}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nova_rewards}
volumes:
- ./database:/migrations:ro
depends_on:
postgres:
condition: service_healthy
restart: on-failure
backend:
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- .env.example
environment:
PORT: 3001
NODE_ENV: ${NODE_ENV:-development}
DATABASE_URL: postgresql://${POSTGRES_USER:-nova}:${POSTGRES_PASSWORD:-changeme}@postgres:5432/${POSTGRES_DB:-nova_rewards}
REDIS_URL: redis://redis:6379
REDIS_MODE: single
ALLOWED_ORIGIN: http://localhost:3000
ports:
- "3001:3001"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
volumes:
- ./backend:/app
- backend_node_modules:/app/node_modules
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- .env.example
environment:
NODE_ENV: development
HOST: 0.0.0.0
NEXT_PUBLIC_API_URL: http://localhost:3001
ports:
- "3000:3000"
depends_on:
backend:
condition: service_started
volumes:
- ./frontend:/app
- frontend_node_modules:/app/node_modules
gateway:
image: nginx:1.25-alpine
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ../deployment/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- backend
volumes:
postgres_data:
redis_data:
pg_backups:
backend_node_modules:
frontend_node_modules: