Ver código fonte

add deployment configs and helpers

mightyplow 5 anos atrás
pai
commit
7bef85ab2d
4 arquivos alterados com 135 adições e 0 exclusões
  1. 41 0
      Makefile
  2. 12 0
      docker-compose.yml
  3. 35 0
      nginx/nginx.conf
  4. 47 0
      nginx/simple-kalorie-tracker

+ 41 - 0
Makefile

@@ -0,0 +1,41 @@
+clientPath = './'
+serverPath = './server/'
+targetPath = '/srv/www/simple-calorie-tracker'
+
+host = 'mightyserver'
+
+all: build
+
+setup:
+	npm i --prefix ${clientPath}
+	npm i --prefix ${serverPath}
+
+build:
+	npm run build --prefix ${clientPath}
+
+ensure-target-directories:
+	ssh ${host} mkdir -p ${targetPath}/
+
+deploy-server: ensure-target-directories
+	rsync -vzruc --delete-before -e ssh ./{dist,nginx} ${host}:${targetPath}/
+	ssh ${host} mkdir -p ${targetPath}/log
+
+build-and-deploy: build deploy-server
+
+prepare-docker-compose:
+	rsync -vzruc --delete-before -e ssh ./docker-compose.yml ${host}:${targetPath}/
+
+stop-server:
+	ssh ${host} docker-compose -f ${targetPath}/docker-compose.yml down
+
+start-server: prepare-docker-compose
+	ssh ${host} docker-compose -f ${targetPath}/docker-compose.yml up -d --build
+
+restart-server: stop-server deploy-server start-server
+
+stop-and-clean:
+	ssh ${host} docker-compose -f ${targetPath}/docker-compose.yml down --rmi local --remove-orphans -v
+
+redeploy: stop-and-clean deploy-server start-server
+
+

+ 12 - 0
docker-compose.yml

@@ -0,0 +1,12 @@
+version: '3'
+
+services:
+  client:
+    image: nginx:alpine
+    restart: always
+    volumes:
+      - ./dist:/usr/share/nginx/html
+      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
+      - ./nginx/simple-kalorie-tracker:/etc/nginx/conf.d/default.conf
+    ports:
+      - '40180:80'

+ 35 - 0
nginx/nginx.conf

@@ -0,0 +1,35 @@
+
+user  nginx;
+worker_processes  1;
+
+error_log  /var/log/nginx/error.log warn;
+pid        /var/run/nginx.pid;
+
+
+events {
+    worker_connections  1024;
+}
+
+
+http {
+    include       /etc/nginx/mime.types;
+    default_type  application/octet-stream;
+
+    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+                      '$status $body_bytes_sent "$http_referer" '
+                      '"$http_user_agent" "$http_x_forwarded_for"';
+
+    access_log  /var/log/nginx/access.log  main;
+
+    sendfile        on;
+    #tcp_nopush     on;
+
+    keepalive_timeout  65;
+
+    gzip  on;
+    gzip_comp_level 6;
+    gzip_vary on;
+    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
+
+    include /etc/nginx/conf.d/*.conf;
+}

+ 47 - 0
nginx/simple-kalorie-tracker

@@ -0,0 +1,47 @@
+server {
+	root /usr/share/nginx/html;
+
+	# access_log /usr/share/nginx/logs/access.log combined;
+	# error_log /usr/share/nginx/logs/error.log error;
+
+	include mime.types;
+
+	# reuse port on redirects
+	absolute_redirect off;
+
+	try_files $uri $uri/ /index.html =404;
+
+    location = /index.html {
+        expires 0;
+        add_header Cache-Control 'no-cache';
+        break;
+    }
+
+    location = /sw.js {
+        expires 0;
+        add_header Cache-Control 'no-cache';
+        break;
+    }
+
+    location = /favicon.ico {
+        access_log off;
+        break;
+    }
+
+    location = /manifest.json {
+        access_log off;
+        break;
+    }
+
+    location /logs {
+        access_log off;
+        auth_basic 'Restricted';
+        auth_basic_user_file /etc/nginx/.htpasswd;
+    }
+
+    location ~ ^/(favicon\.png|fonts|js|img|css|app\.js|app\.css) {
+        # set cache header
+        expires 0;
+        break;
+    }
+}