-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
164 lines (156 loc) · 6.39 KB
/
docker-compose.yml
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
networks:
frontend:
driver: bridge # Uses the bridge driver for the frontend network
backend:
driver: bridge # Uses the bridge driver for the backend network
volumes:
pgdata: # Volume for persisting PostgreSQL data
driver: local # Uses local Docker storage for saving data
pgadmin-data: # Volume for persisting pgAdmin data
driver: local # Uses local Docker storage for pgAdmin configuration
redis-data: # Add the missing volume definition for Redis data
driver: local # Uses local Docker storage for Redis data
services:
frontend:
build:
context: ./frontend # Builds from the frontend directory
dockerfile: Dockerfile.frontend # Uses the Dockerfile.frontend for React app
container_name: react-frontend # Names the container "react-frontend"
ports:
- "3000:3000" # Maps port 3000 on host to container
environment:
- REACT_APP_API_URL=http://express-api:8080 # Points to the API container
depends_on:
- express-api # Ensures API is running before frontend starts
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000 || exit 1"] # Health check using curl to check if frontend is up
interval: 30s
timeout: 10s
retries: 3
networks:
- frontend # Connects to the frontend network
express-api:
build:
context: ./backend # Builds from the backend directory
dockerfile: Dockerfile # Uses the Dockerfile located in the backend directory
container_name: express-api
expose:
- "8080" # Exposes port 8080 to other services in the same network
ports:
- "8080:8080" # Maps port 8080 on the host to port 8080 on the container
environment:
- NODE_ENV=production # Sets the environment variable for Node.js to production
- MONGODB_URI=${MONGODB_URI} # Sets the MongoDB URI from an environment variable
- JWT_SECRET=${JWT_SECRET} # Sets the JWT secret from an environment variable
- EMAIL_USER=${EMAIL_USER} # Sets the email user from an environment variable
- EMAIL_PASS=${EMAIL_PASS} # Sets the email password from an environment variable
- PG_USER=${PG_USER} # Sets PostgreSQL user from an environment variable
- PG_PASS=${PG_PASS} # Sets PostgreSQL password from an environment variable
- PG_DB=${PG_DB} # Sets PostgreSQL database name from an environment variable
- PG_HOST=${PG_HOST}
- PGADMIN_EMAIL=${PGADMIN_EMAIL}
- PGADMIN_PASS=${PGADMIN_PASS}
- DATABASE_URL=${DATABASE_URL}
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
- postgres
- redis-cache
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"] # Health check using curl to check if API is up
interval: 30s
timeout: 10s
retries: 5
networks:
- frontend # Connects to the frontend network
- backend # Connects to the backend network
go-service:
build:
context: ./backend/go # Points to the go directory inside backend
dockerfile: Dockerfile.go.backend # Uses your renamed Dockerfile
container_name: go-backend
ports:
- "8181:8181" # Maps port 8181 on host to container
environment:
- PG_USER=${PG_USER} # Sets PostgreSQL user from an environment variable
- PG_PASS=${PG_PASS} # Sets PostgreSQL password from an environment variable
- PG_DB=${PG_DB} # Sets PostgreSQL database name from an environment variable
- PG_HOST=${PG_HOST}
depends_on:
- postgres
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8181/health || exit 1"] # Health check using curl to check if Go service is up
interval: 30s
timeout: 10s
retries: 5
networks:
- backend # Connects to the backend network
nginx:
build:
context: ./backend # Builds from the backend directory
dockerfile: Dockerfile.nginx # Uses the Dockerfile.nginx
container_name: express-nginx
ports:
- "8081:8081" # Maps port 8081 on the host to port 8081 on the container
depends_on:
- express-api # Ensures the express-api service is started before nginx
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8081/health || exit 1"] # Health check using curl to check if nginx is up
interval: 30s
timeout: 10s
retries: 5
networks:
- frontend # Connects to the frontend network
postgres:
image: postgres:latest # Use the latest PostgreSQL image
container_name: postgres # Names the container "postgres"
environment:
POSTGRES_USER: ${PG_USER} # Use environment variable for PostgreSQL user
POSTGRES_PASSWORD: ${PG_PASS} # Use environment variable for PostgreSQL password
POSTGRES_DB: ${PG_DB} # Use environment variable for PostgreSQL database name
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${PG_USER} || exit 1"] # PostgreSQL health check with pg_isready
interval: 10s
timeout: 5s
retries: 5
networks:
- backend # Connects to the backend network
pgadmin:
image: dpage/pgadmin4:latest # Use the latest pgAdmin image
container_name: pgadmin # Names the container "pgadmin"
ports:
- "8082:80" # Maps port 8082 on the host to port 80 on the container
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL} # Sets the default email for pgAdmin
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASS} # Sets the default password for pgAdmin
volumes:
- pgadmin-data:/var/lib/pgadmin # Persistent storage for pgAdmin data
depends_on:
- postgres # Ensures the postgres service is started before pgadmin
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:80/misc/ping || exit 1"]
interval: 30s
timeout: 10s
retries: 5
networks:
- backend # Connects to the backend network
redis-cache:
image: redis:alpine
container_name: redis-cache
ports:
- "6379:6379"
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf
- redis-data:/data
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD}
networks:
- backend
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5