From 6fd1c028b759547e1bd88b9c84c6febcfce215ad Mon Sep 17 00:00:00 2001 From: Ernesto Montada Romero Date: Thu, 28 Feb 2019 23:56:20 +0100 Subject: [PATCH] Aggiunto supporto Docker. * Aggiunto Dockerfile e docker-compose.yml per testing * App remote env set * Url del server socket.io tramite ENV * Stampa tutte le ENV (docker debug) * Build immagine; Configurazione reverse proxy nginx * Aggiunto client al network privato docker * Reverse proxy al server api * Serving del archivio e api * Rimosso "backend" da docker file e docker compose * Rimosso script di debug * Riportato VueSocket a configurazione di default * aggiunto proxypass per socket.io * Rimosso "/" che causava problemi * Update main.js * Nuova configurazione per proxy socket.io * Socket.io rp; pics; images FIXME: cartella /client servita staticamente nella root del api * Socket io reverse proxy * Unlimited body size! --- .dockerignore | 2 ++ Dockerfile | 15 ++++++++++++ docker-compose.yml | 50 +++++++++++++++++++++++++++++++++++++ nginx/nginx.conf | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..04c01ba --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..df80007 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ + +FROM node:10.15.1-jessie-slim as builder + +WORKDIR /tmp +COPY package.json package.json +RUN yarn + +COPY . . +RUN yarn build + +FROM nginx:latest +COPY ./nginx/nginx.conf /etc/nginx/nginx.conf +WORKDIR /usr/nginx/html +COPY --from=builder /tmp/dist . +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..87cad19 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +version: "2" + +services: + frontend: + build: . + image: archivio-fermi-client + restart: always + container_name: archivio-client + ports: + - 80:80 + depends_on: + - backend + networks: + - api-network + + backend: # Usa sempre backend come nome del server api PS: se lo cambi cambia anche nginx.conf + image: prons/archivio-fermi-server:latest + container_name: archivio-server + restart: always + environment: + MONGODB_URI: "mongodb://database:27017/archivio" + JWT_SECRET: 3xWXqcDzt86YGKr2zP + NODE_ENV: development + volumes: + - server-data:/usr/app/server/public + depends_on: + - database + networks: + - api-network + + database: + image: mongo:3.4.19-jessie + container_name: archivio-db + restart: always + volumes: + - database-data:/data/db + - database-config:/data/configdb + environment: + MONGO_INITDB_DATABASE: archivio + networks: + - api-network + +networks: + api-network: + driver: bridge + +volumes: + database-data: + database-config: + server-data: diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..05f3ee2 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,61 @@ +worker_processes 1; ## Default: 1 + +events { worker_connections 1024; } + +http { + sendfile on; + client_max_body_size 0; + + upstream backendapi { + server backend:3000; + } + + server { + listen 80; + allow all; + + root /usr/nginx/html; + + location /signup { + proxy_pass http://backendapi$uri$is_args$args; + } + location /login { + proxy_pass http://backendapi$uri$is_args$args; + } + location /logout { + proxy_pass http://backendapi$uri$is_args$args; + } + location /api { + proxy_pass http://backendapi$uri$is_args$args; + } + location /public { + proxy_pass http://backendapi$uri$is_args$args; + } + location /pics { + proxy_pass http://backendapi$uri$is_args$args; + } + location /images { + proxy_pass http://backendapi$uri$is_args$args; + } + + location /socket.io { + 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; + proxy_set_header X-NginX-Proxy true; + + proxy_pass http://backendapi$uri$is_args$args; + proxy_redirect off; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + location / { + include /etc/nginx/mime.types; + try_files $uri $uri/ /index.html; + index index.html index.html; + } + } +} \ No newline at end of file