diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 00000000..fa2a2b68 --- /dev/null +++ b/docker-compose.prod.yml @@ -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: diff --git a/front/Dockerfile b/front/Dockerfile index fc67953f..dbddc61d 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -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 diff --git a/front/app/angular.json b/front/app/angular.json index 2f55e6a3..e7502548 100644 --- a/front/app/angular.json +++ b/front/app/angular.json @@ -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" diff --git a/front/nginx.prod.conf b/front/nginx.prod.conf new file mode 100644 index 00000000..267b3315 --- /dev/null +++ b/front/nginx.prod.conf @@ -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; + } + } +} diff --git a/front/prod.Dockerfile b/front/prod.Dockerfile new file mode 100644 index 00000000..6bb54ac7 --- /dev/null +++ b/front/prod.Dockerfile @@ -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/