Production env for the front

This commit is contained in:
2023-03-14 18:59:56 +01:00
parent b598e7a147
commit 2ba34a675d
5 changed files with 107 additions and 17 deletions

33
docker-compose.prod.yml Normal file
View File

@@ -0,0 +1,33 @@
version: "3.9"
services:
back:
build:
context: ${ROOT_PATH}/back
restart: always
ports:
- "8000:8000"
volumes:
- ${ROOT_PATH}/back/app:/code/app
- ${ROOT_PATH}/back/media:/code/media
nginx:
build:
context: ${ROOT_PATH}/front
dockerfile: prod.Dockerfile
restart: always
ports:
- "3820:80"
mongo:
image: "mongo:4.4.18"
restart: always
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
volumes:
- database:/data/db
volumes:
database:

View File

@@ -1,22 +1,11 @@
FROM node:lts-alpine
# install simple http server for serving static content
RUN npm install -g http-server
# make the 'app' folder the current working directory
WORKDIR /app
RUN npm install -g @angular/cli
# copy both 'package.json' and 'package-lock.json' (if available)
RUN npm install -g @angular/cli http-server
COPY app/package*.json ./
# install project dependencies
RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY app/ .
# build app for production with minification
RUN npm run build
EXPOSE 4200

View File

@@ -13,7 +13,8 @@
"sourceLocale": "en-US",
"locales": {
"fr": {
"translation": "src/locale/messages.fr.xlf"
"translation": "src/locale/messages.fr.xlf",
"baseHref": ""
}
}
},
@@ -63,9 +64,6 @@
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
},
"fr": {
"localize": ["fr"]
}
},
"defaultConfiguration": "production"
@@ -80,7 +78,7 @@
"browserTarget": "app:build:development"
},
"fr": {
"browserTarget": "App:build:fr"
"browserTarget": "app:build:fr"
}
},
"defaultConfiguration": "development"

53
front/nginx.prod.conf Normal file
View File

@@ -0,0 +1,53 @@
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
upstream docker-back {
server back:8000;
}
types {
module js;
}
include /etc/nginx/mime.types;
server {
listen 80;
gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /usr/share/nginx/html/index.html =404;
}
location ~* ^.+\.css$ {
default_type text/css;
}
location ~* ^.+\.js$ {
default_type text/javascript;
}
location /api/v1/ {
proxy_pass http://docker-back/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}

17
front/prod.Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM node:lts-alpine AS builder
WORKDIR /app
RUN npm install -g @angular/cli
COPY app/package*.json ./
RUN npm install
COPY app/ .
RUN npm run build --prod
FROM nginx:alpine
COPY nginx.prod.conf /etc/nginx/nginx.conf
COPY --from=builder /app/dist/app/fr/ /usr/share/nginx/html/