Skip to content

Commit 881709f

Browse files
author
bokuan
committed
Add files for aws deploy
1 parent 41c7c54 commit 881709f

File tree

6 files changed

+388
-0
lines changed

6 files changed

+388
-0
lines changed

DockerDeploy.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Pushing to docker hub
2+
3+
## FE
4+
5+
From root dir:
6+
7+
`docker build -t bokuan/peerprep-frontend:latest . -f .\frontend\Dockerfile`
8+
9+
`docker push bokuan/peerprep-frontend:latest`
10+
11+
## Gateway
12+
13+
`docker build -t bokuan/peerprep-gateway:latest . -f .\gateway\Dockerfile`
14+
15+
`docker push bokuan/peerprep-gateway:latest`
16+
17+
## User service
18+
19+
`docker build -t bokuan/peerprep-user-service:latest . -f .\backend\user-service\Dockerfile`
20+
21+
`docker push bokuan/peerprep-user-service:latest`
22+
23+
## qns service
24+
25+
`docker build -t bokuan/peerprep-question-service:latest . -f .\backend\mongodb-database\Dockerfile`
26+
27+
`docker push bokuan/peerprep-question-service:latest`
28+
29+
## matching svc
30+
31+
`docker build -t bokuan/peerprep-matching-service:latest . -f .\backend\matching-service\Dockerfile`
32+
33+
`docker push bokuan/peerprep-matching-service:latest`
34+
35+
## collab svc
36+
37+
`docker build -t bokuan/peerprep-collaboration-service:latest . -f .\backend\collaboration-service\Dockerfile`
38+
39+
`docker push bokuan/peerprep-collaboration-service:latest`
40+
41+
## compiler svc
42+
43+
`docker build -t bokuan/peerprep-compiler-service:latest . -f .\backend\compiler-service\Dockerfile`
44+
45+
`docker push bokuan/peerprep-compiler-service:latest`
46+
47+
## email svc
48+
49+
`docker build -t bokuan/peerprep-email-service:latest . -f .\backend\email-service\Dockerfile`
50+
51+
`docker push bokuan/peerprep-email-service:latest`
52+
53+
## AI svc
54+
55+
`docker build -t bokuan/peerprep-ai-service:latest . -f .\backend\ai-service\Dockerfile`
56+
57+
`docker push bokuan/peerprep-ai-service:latest`

docker-compose-full-deploy.yml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
version: '3.8'
2+
3+
x-logging:
4+
&default-logging
5+
logging:
6+
driver: json-file
7+
options:
8+
max-size: 100m
9+
10+
services:
11+
frontend:
12+
depends_on:
13+
- gateway
14+
container_name: frontend
15+
image: bokuan/peerprep-frontend:latest
16+
ports:
17+
- "3000:3000"
18+
env_file:
19+
- ./frontend/.env
20+
environment: # Running locally has different url than running on docker (not localhost)
21+
- NEXT_PUBLIC_MATCHING_SERVER_URL=http://matching:3004
22+
- NEXT_PUBLIC_COLLAB_SERVER_URL=http://collaboration:3005
23+
- GATEWAY_SERVER_URL=http://gateway:8080
24+
25+
nginx-web-app:
26+
build: ./nginx
27+
restart: always
28+
volumes:
29+
- ./nginx/default.conf:/tmp/default.conf/:ro
30+
- ./certbot/www:/var/www/certbot/:ro
31+
- ./certbot/conf/:/etc/nginx/ssl/:ro
32+
environment:
33+
- WEB_APP_ADDR=frontend:3000
34+
ports:
35+
- "80:80"
36+
- "443:443"
37+
depends_on:
38+
- frontend
39+
healthcheck:
40+
test: ["CMD-SHELL", "curl --silent --fail localhost:80/health-check || exit 1"]
41+
interval: 1000s
42+
timeout: 10s
43+
retries: 3
44+
command: /app/start.sh
45+
46+
certbot:
47+
image: certbot/certbot:latest
48+
volumes:
49+
- ./certbot/www:/var/www/certbot/:rw
50+
- ./certbot/conf/:/etc/letsencrypt/:rw
51+
52+
gateway:
53+
depends_on:
54+
- users
55+
- questions
56+
- matching
57+
- collaboration
58+
- compiler
59+
- ai
60+
- email
61+
container_name: gateway
62+
image: bokuan/peerprep-gateway:latest
63+
ports:
64+
- "8080:8080"
65+
environment:
66+
- USER_SERVICE_URL=http://users:3001
67+
- QUESTION_SERVICE_URL=http://questions:3002
68+
- RABBITMQ_URL=amqp://user:password@rabbitmq:5672
69+
users:
70+
depends_on:
71+
- email
72+
container_name: user-service
73+
image: bokuan/peerprep-user-service:latest
74+
ports:
75+
- "3001:3001"
76+
env_file:
77+
- ./backend/user-service/.env
78+
environment:
79+
- EMAIL_SERVICE_URL=http://email:3007/email
80+
81+
questions:
82+
container_name: question-service
83+
image: bokuan/peerprep-question-service:latest
84+
ports:
85+
- "3002:3002"
86+
env_file:
87+
- ./backend/mongodb-database/.env
88+
89+
matching:
90+
container_name: matching-service
91+
image: bokuan/peerprep-matching-service:latest
92+
ports:
93+
- "3004:3004"
94+
env_file:
95+
- ./backend/matching-service/.env
96+
environment:
97+
- GATEWAY_SERVER_URL=http://gateway:8080
98+
- USER_SERVICE_URL=http://users:3001/api/session
99+
100+
collaboration:
101+
container_name: collaboration-service
102+
image: bokuan/peerprep-collaboration-service:latest
103+
ports:
104+
- "3005:3005"
105+
106+
compiler:
107+
depends_on:
108+
- server
109+
- workers
110+
- db
111+
- redis
112+
- rabbitmq
113+
container_name: compiler-service
114+
image: bokuan/peerprep-compiler-service:latest
115+
ports:
116+
- "3006:3006"
117+
environment: # Running locally has different url than running on docker (not localhost)
118+
- RABBITMQ_URL=amqp://user:password@rabbitmq:5672
119+
- JUDGE0_URL=http://server:2358/
120+
121+
email:
122+
container_name: email-service
123+
image: bokuan/peerprep-email-service:latest
124+
ports:
125+
- "3007:3007"
126+
env_file:
127+
- ./backend/email-service/.env
128+
129+
ai:
130+
container_name: ai-service
131+
depends_on:
132+
- rabbitmq
133+
image: bokuan/peerprep-ai-service:latest
134+
ports:
135+
- "3008:3008"
136+
env_file:
137+
- ./backend/ai-service/.env
138+
environment: # Running locally has different url than running on docker (not localhost)
139+
- RABBITMQ_URL=amqp://user:password@rabbitmq:5672
140+
141+
server: # Judge0
142+
image: judge0/judge0:1.13.0
143+
volumes:
144+
- ./backend/judge0/judge0.conf:/judge0.conf:ro
145+
ports:
146+
- "2358:2358"
147+
privileged: true
148+
<<: *default-logging
149+
restart: always
150+
151+
workers: # Judge0
152+
image: judge0/judge0:1.13.0
153+
command: ["./scripts/workers"]
154+
volumes:
155+
- ./backend/judge0/judge0.conf:/judge0.conf:ro
156+
privileged: true
157+
<<: *default-logging
158+
restart: always
159+
160+
db: # Judge0
161+
image: postgres:13.0
162+
env_file: ./backend/judge0/judge0.conf
163+
volumes:
164+
- postgres-data:/var/lib/postgresql/data/
165+
<<: *default-logging
166+
restart: always
167+
168+
redis: # Judge0
169+
image: redis:6.0
170+
command: [
171+
"bash", "-c",
172+
'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
173+
]
174+
env_file: ./backend/judge0/judge0.conf
175+
volumes:
176+
- redis-data:/data
177+
<<: *default-logging
178+
restart: always
179+
180+
rabbitmq:
181+
image: rabbitmq:management
182+
hostname: rabbitmq
183+
ports:
184+
- "5672:5672" # AMQP protocol
185+
- "15672:15672" # Management UI
186+
expose:
187+
- 5672
188+
- 15672
189+
environment:
190+
RABBITMQ_DEFAULT_USER: user
191+
RABBITMQ_DEFAULT_PASS: password
192+
volumes:
193+
- rabbitmq_data:/var/lib/rabbitmq
194+
- rabbitmq_log:/var/log/rabbitmq
195+
196+
volumes:
197+
postgres-data:
198+
redis-data:
199+
rabbitmq_data:
200+
rabbitmq_log:
201+

nginx/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM nginx:1.19.7-alpine
2+
3+
# Add bash for boot cmd
4+
RUN apk add bash
5+
6+
# Add nginx.conf to container
7+
COPY --chown=nginx:nginx nginx.conf /etc/nginx/nginx.conf
8+
COPY --chown=nginx:nginx start.sh /app/start.sh
9+
10+
# set workdir
11+
WORKDIR /app
12+
13+
# permissions and nginx user for tightened security
14+
RUN chown -R nginx:nginx /app && chmod -R 755 /app && \
15+
chown -R nginx:nginx /var/cache/nginx && \
16+
chown -R nginx:nginx /var/log/nginx && \
17+
chmod -R 755 /var/log/nginx; \
18+
chown -R nginx:nginx /etc/nginx/conf.d
19+
RUN touch /var/run/nginx.pid && chown -R nginx:nginx /var/run/nginx.pid
20+
21+
# # Uncomment to keep the nginx logs inside the container - Leave commented for logging to stdout and stderr
22+
# RUN mkdir -p /var/log/nginx
23+
# RUN unlink /var/log/nginx/access.log \
24+
# && unlink /var/log/nginx/error.log \
25+
# && touch /var/log/nginx/access.log \
26+
# && touch /var/log/nginx/error.log \
27+
# && chown nginx /var/log/nginx/*log \
28+
# && chmod 644 /var/log/nginx/*log
29+
30+
USER nginx
31+
32+
CMD ["nginx", "-g", "'daemon off;'"]

nginx/default.conf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:10m max_size=500m inactive=60m use_temp_path=off;
2+
3+
server {
4+
listen 443 ssl;
5+
server_name peerprep.mooo.com;
6+
ssl_certificate /etc/nginx/ssl/live/peerprep.mooo.com/fullchain.pem;
7+
ssl_certificate_key /etc/nginx/ssl/live/peerprep.mooo.com/privkey.pem;
8+
9+
location / {
10+
proxy_pass http://$WEB_APP_ADDR;
11+
proxy_set_header Host $host;
12+
proxy_set_header X-Real-IP $remote_addr;
13+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14+
}
15+
16+
location /cache-me {
17+
proxy_pass http://$WEB_APP_ADDR;
18+
proxy_cache cache;
19+
proxy_cache_lock on;
20+
proxy_cache_valid 200 30s;
21+
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
22+
proxy_cache_revalidate on;
23+
proxy_cache_background_update on;
24+
expires 20s;
25+
}
26+
27+
location /health-check {
28+
add_header Content-Type text/plain;
29+
return 200 "success";
30+
}
31+
32+
error_page 497 https://$host$request_uri;
33+
}
34+
35+
server {
36+
listen 80;
37+
server_name peerprep.mooo.com;
38+
server_tokens off;
39+
40+
location /.well-known/acme-challenge/ {
41+
root /var/www/certbot;
42+
}
43+
location / {
44+
return 301 https://peerprep.mooo.com$request_uri;
45+
}
46+
}

nginx/nginx.conf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
worker_processes auto;
2+
pid /var/run/nginx.pid;
3+
4+
events {
5+
worker_connections 1024;
6+
}
7+
8+
http {
9+
include /etc/nginx/mime.types;
10+
default_type application/octet-stream;
11+
12+
# Define the format of log messages.
13+
log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" '
14+
'$status $body_bytes_sent "$http_referer" '
15+
'"$http_user_agent" "$http_x_forwarded_for" '
16+
'"$host" sn="$server_name" '
17+
'rt=$request_time '
18+
'ua="$upstream_addr" us="$upstream_status" '
19+
'ut="$upstream_response_time" ul="$upstream_response_length" '
20+
'cs=$upstream_cache_status' ;
21+
22+
access_log /var/log/nginx/access.log main_ext;
23+
error_log /var/log/nginx/error.log warn;
24+
25+
sendfile on;
26+
27+
keepalive_timeout 65;
28+
29+
# Enable Compression
30+
gzip on;
31+
32+
# Disable Display of NGINX Version
33+
server_tokens off;
34+
35+
# Size Limits
36+
client_body_buffer_size 10K;
37+
client_header_buffer_size 1k;
38+
client_max_body_size 8m;
39+
large_client_header_buffers 2 1k;
40+
41+
# # SSL / TLS Settings - Suggested for Security
42+
# ssl_protocols TLSv1.2 TLSv1.3;
43+
# ssl_session_timeout 15m;
44+
# ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
45+
# ssl_prefer_server_ciphers on;
46+
# ssl_session_tickets off;
47+
48+
include /etc/nginx/conf.d/*.conf;
49+
50+
}

nginx/start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
envsubst '$WEB_APP_ADDR' < /tmp/default.conf > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'

0 commit comments

Comments
 (0)