From 5f27e167d32c9c61bdffe33a69c91371813c95ba Mon Sep 17 00:00:00 2001
From: ncastejon <castejon.nicolas@gmail.com>
Date: Wed, 11 Apr 2018 15:36:38 +0200
Subject: [PATCH] WIP Dockers for webapp, proxy elastic, nginx

---
 Dockerfile                 |  5 +++++
 docker-compose-staging.yml | 24 ++++++++++++++++++++++++
 proxy.conf                 | 15 +++++++++++++++
 webapp-nginx.conf          | 31 +++++++++++++++++++++++++++++++
 webapp/.dockerignore       |  2 ++
 webapp/Dockerfile          | 22 ++++++++++++++++++++++
 6 files changed, 99 insertions(+)
 create mode 100644 Dockerfile
 create mode 100644 docker-compose-staging.yml
 create mode 100644 proxy.conf
 create mode 100644 webapp-nginx.conf
 create mode 100644 webapp/.dockerignore
 create mode 100644 webapp/Dockerfile

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..12a84004
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,5 @@
+FROM nginx
+
+RUN apt-get update
+
+RUN apt-get --yes --force-yes install nginx-extras
\ No newline at end of file
diff --git a/docker-compose-staging.yml b/docker-compose-staging.yml
new file mode 100644
index 00000000..32a233f5
--- /dev/null
+++ b/docker-compose-staging.yml
@@ -0,0 +1,24 @@
+version: "2"
+
+services:
+
+  node-server:
+    build: ./webapp
+
+  proxy-elasticsearch:
+    image: nginx
+    volumes: 
+      - ./proxy.conf:/etc/nginx/conf.d/default.conf
+    ports: 
+      - 8000:80
+
+  nginx-app:
+    build:
+      context: ./
+    volumes: 
+      - ./webapp-nginx.conf:/etc/nginx/conf.d/default.conf
+      - ./webapp/dist:/usr/share/nginx/html
+    ports: 
+      - 8080:8080
+  
+  
\ No newline at end of file
diff --git a/proxy.conf b/proxy.conf
new file mode 100644
index 00000000..aeb138e0
--- /dev/null
+++ b/proxy.conf
@@ -0,0 +1,15 @@
+server {
+    listen 80;
+    server_name _;
+
+    location / {
+        proxy_pass https://elastic2.recette.data.grandlyon.com/elastic/;
+        proxy_set_header  X-Real-IP  $remote_addr;
+        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header  Host $http_host;
+        add_header 'Access-Control-Allow-Origin' '*';
+        add_header 'Access-Control-Allow-Credentials' 'true';
+        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
+        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
+    }
+}
\ No newline at end of file
diff --git a/webapp-nginx.conf b/webapp-nginx.conf
new file mode 100644
index 00000000..dd41d66b
--- /dev/null
+++ b/webapp-nginx.conf
@@ -0,0 +1,31 @@
+
+server {
+    listen 8080;
+    server_name portail-data;
+    root /usr/share/nginx/html;
+
+location = / {
+rewrite_by_lua '
+for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do
+    if string.sub(lang, 0, 2) == "en" then
+    ngx.redirect("/en/")
+    end
+    if string.sub(lang, 0, 2) == "fr" then
+    ngx.redirect("/fr/")
+    end
+end
+ngx.redirect("/en/")
+';
+#rewrite ^/$ /en/ permanent;
+
+# First attempt to serve request as file, then
+# as directory, then fall back to displaying a 404.
+# Uncomment to enable naxsi on this location
+# include /etc/nginx/naxsi.rules
+}
+    error_page 404 = @notfound;
+
+    location @notfound {
+        return 301 /;
+    }
+}
\ No newline at end of file
diff --git a/webapp/.dockerignore b/webapp/.dockerignore
new file mode 100644
index 00000000..27c38f71
--- /dev/null
+++ b/webapp/.dockerignore
@@ -0,0 +1,2 @@
+**/.git
+**/node_modules
diff --git a/webapp/Dockerfile b/webapp/Dockerfile
new file mode 100644
index 00000000..c381c792
--- /dev/null
+++ b/webapp/Dockerfile
@@ -0,0 +1,22 @@
+FROM node:8.10.0
+
+
+# Copy the current directory contents into the container at /app
+COPY . /app/webapp
+#COPY ../node-server /app/node-server
+
+WORKDIR /app/webapp
+# Install npm dependencies
+RUN npm install
+# Building the Angular app /dist i18n
+RUN npm run win-build-i18n:fr
+#RUN cp -r ./dist ../node-server/dist
+
+# Set the working directory to /node-server
+#WORKDIR /app/node-server
+# Install npm dependencies
+#RUN npm install
+
+#EXPOSE 8080
+
+#CMD npm start
-- 
GitLab