From 2aa887fbb09060901bedb0ad25ffe3a5c7a09ef5 Mon Sep 17 00:00:00 2001
From: "guilhem.carron" <gcarron@grandlyon.com>
Date: Thu, 12 Aug 2021 09:18:29 +0200
Subject: [PATCH] Change prod conf file + add local docker

---
 Dockerfile               |  2 +-
 docker-compose.local.yml | 67 +++++++++++++++++++++++++++++++++-------
 docker-compose.yml       |  6 ++--
 nginx/site.conf          | 16 +++++-----
 nginx/site.pro.conf      | 10 ------
 nginx/site.prod.conf     | 26 ++++++++++++++++
 6 files changed, 93 insertions(+), 34 deletions(-)
 delete mode 100644 nginx/site.pro.conf
 create mode 100644 nginx/site.prod.conf

diff --git a/Dockerfile b/Dockerfile
index d4796bef..0086ad46 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,6 +11,6 @@ RUN npm run build
 FROM nginx:1.16
 COPY --from=build-stage /app/build/ /usr/share/nginx/html
 COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
-COPY ./nginx/site.pro.conf /etc/nginx/conf.d/default.conf
+COPY ./nginx/site.prod.conf /etc/nginx/conf.d/default.conf
 EXPOSE 80
 CMD ["nginx", "-g", "daemon off;"]
\ No newline at end of file
diff --git a/docker-compose.local.yml b/docker-compose.local.yml
index 7d966d37..66b922b3 100644
--- a/docker-compose.local.yml
+++ b/docker-compose.local.yml
@@ -6,13 +6,14 @@ services:
     volumes:
       - ./nginx/site.conf:/etc/nginx/conf.d/default.conf
       - ./nginx/nginx.conf:/etc/nginx/nginx.conf
-    command: ["nginx", "-g", "daemon off;"]
+      - ./cert.pem:/etc/nginx/cert.pem
+      - ./key.pem:/etc/nginx/key.pem
+    command: ['nginx', '-g', 'daemon off;']
     ports:
-        - 8081:8080
-    networks:
-      backoffice:
-    depends_on:
-      - front
+      - 8080:8080
+    # depends_on:
+    #   front:
+    #     condition: service_healthy
     links:
       - front
 
@@ -23,10 +24,52 @@ services:
       - ./:/usr/app
     working_dir: /usr/app
     ports:
-        - 3000:3000
-    networks:
-        backoffice:
+      - 3000:3000
+    healthcheck:
+      test: curl localhost:3000
+      interval: 5s
+      timeout: 10s
+      retries: 60
+
+  database:
+    image: mysql:5
+    ports:
+      - 3306:3306
+    environment:
+      MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
+      MYSQL_DATABASE: ${DATABASE_NAME}
+    healthcheck:
+      test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MYSQL_ROOT_PASSWORD
+      interval: 5s
+      timeout: 10s
+      retries: 60
 
-networks:
-    backoffice:
-      
\ No newline at end of file
+  backend:
+    image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:dev
+    depends_on:
+      database:
+        condition: service_healthy
+    restart: unless-stopped
+    volumes:
+      - /etc/localtime:/etc/localtime:ro
+      - ./configs:/app/configs
+      - ./letsencrypt_cache:/app/letsencrypt_cache
+      - ./data:/app/data
+    ports:
+      - ${HTTPS_PORT}:${HTTPS_PORT}
+      - 8090:8090
+    environment:
+      - HOSTNAME=${HOSTNAME}
+      - HTTPS_PORT=${HTTPS_PORT}
+      - ADMIN_ROLE=${ADMIN_ROLE}
+      - REDIRECT_URL=${REDIRECT_URL}
+      - CLIENT_ID=${CLIENT_ID}
+      - CLIENT_SECRET=${CLIENT_SECRET}
+      - AUTH_URL=${AUTH_URL}
+      - TOKEN_URL=${TOKEN_URL}
+      - USERINFO_URL=${USERINFO_URL}
+      - DEBUG_MODE=${DEBUG_MODE}
+      - DATABASE_USER=${DATABASE_USER}
+      - DATABASE_NAME=${DATABASE_NAME}
+      - DATABASE_PASSWORD=${DATABASE_PASSWORD}
+      - DATABASE_HOST=database
diff --git a/docker-compose.yml b/docker-compose.yml
index 9c6be045..1c8ceab2 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,14 +1,14 @@
 version: '3.7'
 services:
   nginx:
-    image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-client:latest
+    image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-client:dev
     restart: unless-stopped
     ports:
       - 443:443
     networks:
       backoffice:
     volumes:
-      - ./nginx/site.conf:/etc/nginx/conf.d/default.conf
+      - ./nginx/site.prod.conf:/etc/nginx/conf.d/default.conf
       - ./nginx/nginx.conf:/etc/nginx/nginx.conf
       - ./cert.pem:/etc/nginx/cert.pem
       - ./key.pem:/etc/nginx/key.pem
@@ -29,7 +29,7 @@ services:
       retries: 60
 
   backend:
-    image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:latest
+    image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:dev
     networks:
       backoffice:
     depends_on:
diff --git a/nginx/site.conf b/nginx/site.conf
index e6d27c77..913c94c8 100644
--- a/nginx/site.conf
+++ b/nginx/site.conf
@@ -1,15 +1,15 @@
 server {
-        listen 443 ssl;
+        listen 8080 ;
         server_name         localhost;
-        ssl_certificate     /etc/nginx/cert.pem;
-        ssl_certificate_key /etc/nginx/key.pem;
-        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
-        ssl_ciphers         HIGH:!aNULL:!MD5;
 
         location / {
-            root /usr/share/nginx/html;
-            index index.html index.htm;
-            try_files $uri $uri/ /index.html =404;
+            proxy_pass https://front:3000;
+            proxy_set_header Upgrade $http_upgrade;
+            proxy_set_header Connection $http_connection;
+            proxy_set_header Host $host;
+            proxy_set_header X-Forwarded-Proto $scheme;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         }
         location /api {  
             proxy_pass https://backend:1443/api;
diff --git a/nginx/site.pro.conf b/nginx/site.pro.conf
deleted file mode 100644
index a99902a9..00000000
--- a/nginx/site.pro.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-server {
-        listen 80;
-        server_name localhost;
-
-        location / {
-            root /usr/share/nginx/html;
-            index index.html index.htm;
-            try_files $uri $uri/ /index.html =404;
-        }
-}
diff --git a/nginx/site.prod.conf b/nginx/site.prod.conf
new file mode 100644
index 00000000..e6d27c77
--- /dev/null
+++ b/nginx/site.prod.conf
@@ -0,0 +1,26 @@
+server {
+        listen 443 ssl;
+        server_name         localhost;
+        ssl_certificate     /etc/nginx/cert.pem;
+        ssl_certificate_key /etc/nginx/key.pem;
+        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
+        ssl_ciphers         HIGH:!aNULL:!MD5;
+
+        location / {
+            root /usr/share/nginx/html;
+            index index.html index.htm;
+            try_files $uri $uri/ /index.html =404;
+        }
+        location /api {  
+            proxy_pass https://backend:1443/api;
+        }
+        location /OAuth2Login {
+            proxy_pass https://backend:1443/OAuth2Login;
+        }
+        location /OAuth2Callback {
+            proxy_pass https://backend:1443/OAuth2Callback;
+        }
+        location /Logout {
+            proxy_pass https://backend:1443/Logout;
+        }
+}
-- 
GitLab