Skip to content

Commit

Permalink
feat: improce build and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
claughinghouse committed Jun 14, 2021
1 parent 78b23de commit dc33129
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 79 deletions.
2 changes: 2 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ ENV ENABLE_CIRCUITBREAKER=true

RUN python setup.py install

EXPOSE 8080

CMD /bin/sh entrypoint.sh
72 changes: 29 additions & 43 deletions contrib/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
root /usr/share/nginx/html;

client_max_body_size 0;
proxy_request_buffering off;
proxy_read_timeout 7200;

resolver 127.0.0.11 valid=5s;
set $backend_upstream backend;
set $frontend_upstream frontend;

listen 80;
server_name localhost;
resolver 127.0.0.11;
location / {
set $frontend_upstream frontend;
proxy_pass http://$frontend_upstream:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP ip_address;
}
location /api {
set $backend_upstream backend;
proxy_pass http://$backend_upstream:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 3600s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP ip_address;
}

location / {
proxy_pass http://$frontend_upstream:8000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 3600s;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
}
21 changes: 9 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#

---
version: "3.7"

services:
nginx:
image: nginx:stable-alpine
ports:
- "80:80"
- "8081:80"
volumes:
- ./contrib/nginx.conf:/etc/nginx/nginx.conf
networks:
- tuber

frontend:
build: ./frontend
image: magfest/tuber:latest-frontend
ports:
- "8000:8000"
image: ghcr.io/claughinghouse/tuber-frontend:latest
networks:
- tuber

backend:
build: ./backend
image: magfest/tuber:latest-backend
image: ghcr.io/claughinghouse/tuber-backend:latest
depends_on:
- postgres
- redis
Expand All @@ -33,16 +30,16 @@ services:
FLASK_ENV: production
WORKERS: 4
CIRCUITBREAKER_THREADS: 4
scale: 1
# scale: 1
networks:
- tuber

postgres:
image: postgres:10.4
image: postgres:alpine
environment:
POSTGRES_PASSWORD: tuber
POSTGRES_USER: tuber
POSTGRES_DB: tuber
- POSTGRES_PASSWORD=tuber
- POSTGRES_USER=tuber
- POSTGRES_DB=tuber
ports:
- "5432"
volumes:
Expand Down
3 changes: 2 additions & 1 deletion frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
**/node_modules
**/dist
22 changes: 6 additions & 16 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# build stage
FROM node:lts-alpine as build-stage

FROM node:alpine as build-stage
WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

COPY ./ .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage

COPY --from=build-stage /app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
FROM nginx:alpine as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
34 changes: 27 additions & 7 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
server {
listen ${PORT};
server_name ${SERVER_NAME};
root /var/www/;
index index.html;

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
try_files $uri /index.html;
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}

0 comments on commit dc33129

Please sign in to comment.