diff --git a/infra/deployment/config/xsnexplorer.io b/infra/deployment/config/xsnexplorer.io new file mode 100644 index 0000000..a89a027 --- /dev/null +++ b/infra/deployment/config/xsnexplorer.io @@ -0,0 +1,34 @@ +server { + listen 80 default_server; + + root /var/www/html; + + index index.html; + + server_name xsnexplorer.io; + + # the backend api + location /api/ltc { + rewrite ^/api/ltc/(.*) /$1 break; + proxy_pass http://18.222.26.185:9000; + } + + location /api/xsn { + rewrite ^/api/xsn/(.*) /$1 break; + proxy_pass http://18.224.5.222:9000; + } + + location /api { + rewrite ^/api/(.*) /$1 break; + proxy_pass http://18.224.5.222:9000; + } + + # caching static assets + location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { + expires 7d; + } + + location / { + try_files $uri $uri/ /index.html; + } +} diff --git a/infra/deployment/frontend.yml b/infra/deployment/frontend.yml new file mode 100644 index 0000000..7b706bb --- /dev/null +++ b/infra/deployment/frontend.yml @@ -0,0 +1,92 @@ +--- +- hosts: frontend + gather_facts: no + roles: + - ubuntu-16-04 + + tasks: + - name: Install nginx + become: yes + apt: + name: nginx + state: latest + update_cache: yes + + - name: Disable nginx default site + become: yes + file: + path: /etc/nginx/sites-enabled/default + state: absent + + - name: Remove nginx default site config + become: yes + file: + path: /etc/nginx/sites-available/default + state: absent + + - name: Create nginx log directory + become: yes + file: + path: /var/log/nginx + state: directory + + - name: Copy the nginx config + become: yes + copy: + src: config/xsnexplorer.io + dest: /etc/nginx/sites-available/xsnexplorer + + - name: Create the symlink + become: yes + file: + src: /etc/nginx/sites-available/xsnexplorer + dest: /etc/nginx/sites-enabled/xsnexplorer + state: link + + - name: Restart nginx + become: yes + service: + name: nginx + state: restarted + + - name: Enable nginx to run on system startup + become: yes + systemd: + name: nginx + enabled: yes + + - name: Build the application + shell: ./scripts/build-web-ui.sh + delegate_to: 127.0.0.1 + + - name: Upload the application + synchronize: + src: web.zip + dest: web.zip + + - name: Create the web data directory + become: yes + file: + path: /var/www/html + state: directory + owner: www-data + group: www-data + + - name: Unpack the application + become: yes + unarchive: + remote_src: yes + src: web.zip + dest: /var/www/html + + - name: Move the web content + become: yes + raw: rsync -a /var/www/html/dist/ /var/www/html/ --remove-source-files + + - name: Set the permissions + become: yes + file: + dest: /var/www/html + owner: www-data + group: www-data + recurse: yes diff --git a/infra/deployment/production-frontend.ini b/infra/deployment/production-frontend.ini new file mode 100644 index 0000000..d993643 --- /dev/null +++ b/infra/deployment/production-frontend.ini @@ -0,0 +1,2 @@ +[frontend] +explorer-frontend diff --git a/infra/deployment/scripts/build-web-ui.sh b/infra/deployment/scripts/build-web-ui.sh new file mode 100755 index 0000000..ec9d5ef --- /dev/null +++ b/infra/deployment/scripts/build-web-ui.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd ../../web-ui/ && ng build --prod && zip -r web.zip dist/* && cd - +mv ../../web-ui/web.zip web.zip