Skip to content

Commit 2916966

Browse files
committed
Frontend Dockerfile with nginx
1 parent 2e92a0d commit 2916966

File tree

7 files changed

+150
-1
lines changed

7 files changed

+150
-1
lines changed

docker-compose.dev.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ services:
6363
networks:
6464
- mlnet
6565

66+
ml-client:
67+
build:
68+
context: ./ml-client
69+
dockerfile: ./Dockerfile
70+
environment:
71+
DOMAIN: localhost
72+
BE_HOST: ml-api
73+
BE_PORT: 8081
74+
container_name: ml-client
75+
restart: unless-stopped
76+
ports:
77+
- 80:80
78+
command: sh -c "./custom_nginx.sh && nginx -g 'daemon off;'"
79+
networks:
80+
- mlnet
81+
82+
6683
networks:
6784
mlnet:
6885

ml-client/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.git
3+
.gitignore

ml-client/Dockerfile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# update soon
1+
FROM node:14.17-alpine3.13 as builder
2+
3+
WORKDIR /app
4+
5+
ENV PATH /app/node_modules/.bin:$PATH
6+
7+
COPY ./package.json /app/package.json
8+
COPY ./package-lock.json /app/package-lock.json
9+
RUN npm i -g
10+
COPY . .
11+
RUN yarn build:production
12+
13+
FROM nginx
14+
15+
WORKDIR /usr/share/nginx/html
16+
17+
RUN rm -v /etc/nginx/nginx.conf
18+
RUN rm -v /etc/nginx/conf.d/default.conf
19+
COPY ./nginx.conf /etc/nginx/
20+
21+
RUN rm -rf ./*
22+
23+
COPY ./m_nginx.conf .
24+
COPY ./local_nginx.conf .
25+
COPY ./custom_nginx.sh .
26+
RUN chmod +x custom_nginx.sh
27+
28+
COPY --from=builder /app/build .
29+
30+
EXPOSE 80 443

ml-client/custom_nginx.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
if [ "${DOMAIN}" = "localhost" ]; then
3+
echo 'Deploy server on localhost..........'
4+
envsubst '$${DOMAIN} $${BE_HOST} $${BE_PORT}' < local_nginx.conf > /etc/nginx/conf.d/app.conf
5+
else
6+
echo 'Deploy server on staging or prodution.........'
7+
envsubst '$${DOMAIN} $${BE_HOST} $${BE_PORT}' < m_nginx.conf > /etc/nginx/conf.d/app.conf
8+
fi
9+
exec "$@"

ml-client/local_nginx.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Đây là file cấu hình cho nigix localhost
2+
server {
3+
listen 80;
4+
charset utf-8;
5+
server_name ${DOMAIN};
6+
location /api/ {
7+
proxy_pass http://${BE_HOST}:${BE_PORT}/api/;
8+
proxy_set_header Host $host;
9+
proxy_set_header X-Real-IP $remote_addr;
10+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
11+
}
12+
location / {
13+
root /usr/share/nginx/html;
14+
try_files $uri $uri.html $uri/ /index.html = 404;
15+
}
16+
}

ml-client/m_nginx.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# load frontend và backend ra port 80
2+
server {
3+
listen 80;
4+
charset utf-8;
5+
server_name ${DOMAIN};
6+
}
7+
server {
8+
listen 443 ssl;
9+
server_name ${DOMAIN};
10+
charset utf-8;
11+
ssl_certificate /etc/letsencrypt/live/${DOMAIN}/fullchain.pem;
12+
ssl_certificate_key /etc/letsencrypt/live/${DOMAIN}/privkey.pem;
13+
14+
location /api/ {
15+
proxy_pass http://${BE_HOST}:${BE_PORT}/api/;
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19+
client_max_body_size 16M;
20+
}
21+
location / {
22+
root /usr/share/nginx/html;
23+
try_files $uri $uri.html $uri/ /index.html =404;
24+
}
25+
}

ml-client/nginx.conf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#file này config cho phiên chạy nginx
2+
3+
# ông chủ
4+
user nginx;
5+
6+
# số lượng nhân viên
7+
worker_processes auto;
8+
9+
# lấy lỗi
10+
error_log /var/log/nginx/error.log warn;
11+
12+
# file chứa id cho nginx
13+
pid /var/run/nginx.pid;
14+
15+
# maximum connect với worker processes
16+
events {
17+
worker_connections 1024;
18+
}
19+
20+
# nigix cấu hình handle http
21+
http {
22+
# Include the file defining the list of file types that are supported by NGINX
23+
include /etc/nginx/mime.types;
24+
# Define the default file type that is returned to the user
25+
default_type text/html;
26+
27+
# Define the format of log messages.
28+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
29+
'$status $body_bytes_sent "$http_referer" '
30+
'"$http_user_agent" "$http_x_forwarded_for"';
31+
32+
# Define the location of the log of access attempts to NGINX
33+
access_log /var/log/nginx/access.log main;
34+
35+
# Define the parameters to optimize the delivery of static content
36+
sendfile on;
37+
tcp_nopush on;
38+
tcp_nodelay on;
39+
40+
client_max_body_size 20M;
41+
42+
# Define the timeout value for keep-alive connections with the client
43+
keepalive_timeout 65;
44+
45+
# Define the usage of the gzip compression algorithm to reduce the amount of data to transmit
46+
# gzip on;
47+
48+
# Include additional parameters for virtual host(s)/server(s)
49+
include /etc/nginx/conf.d/*.conf;
50+
}

0 commit comments

Comments
 (0)