Skip to content

Commit

Permalink
infra: Add deployment scripts for the alerts-ui project
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Sep 16, 2018
1 parent 95fab4c commit 36c866a
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 9 deletions.
1 change: 1 addition & 0 deletions infra/deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vault
app.zip
*.retry
web.zip
22 changes: 20 additions & 2 deletions infra/deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This folder contains all the required scripts to deploy the projects.

These scripts were tested with ansible 2.6.4, higher versions should work too, it might not work with smaller versions.

## alerts-server
## Requirements

1. Register the servers on the ssh config file (`~/.ssh/config`), for example:

```
Expand All @@ -18,5 +19,22 @@ Host test-server

3. Ensure the `hosts.ini` file contains the correct servers.

4. Execute the following command to deploy the application:

## Limitations
- This assumes you will deploy all services to a single server.
- There is no simple way to go to production or a development server.
- There is no SSL support.
- Assumes that the server ports are open.

## alerts-server

Execute the following command to deploy the application:
`ansible-playbook -i hosts.ini --ask-become-pass --vault-password-file .vault alerts-server.yml`


## alerts-ui

1. Ensure the web-ui project is pointing to the correct host [environment.prod.ts](../../alerts-ui/src/environments/environment.prod.ts)

2. Execute the following command to deploy the application:
`ansible-playbook -i hosts.ini --ask-become-pass --vault-password-file .vault alerts-ui.yml`
8 changes: 1 addition & 7 deletions infra/deployment/alerts-server.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

---
- hosts: alerts-server
gather_facts: no
roles:
Expand Down Expand Up @@ -37,12 +37,6 @@
owner: play
group: play

- name: Install unzip tool
become: yes
apt:
name: unzip
state: latest

- name: Unpack the application
become: yes
unarchive:
Expand Down
92 changes: 92 additions & 0 deletions infra/deployment/alerts-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
- hosts: alerts-ui
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/cryptocoinalerts.net
dest: /etc/nginx/sites-available/cryptocoinalerts

- name: Create the symlink
become: yes
file:
src: /etc/nginx/sites-available/cryptocoinalerts
dest: /etc/nginx/sites-enabled/cryptocoinalerts
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-alerts-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
24 changes: 24 additions & 0 deletions infra/deployment/config/cryptocoinalerts.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server {
listen 80 default_server;

root /var/www/html;

index index.html;

server_name cryptocoinalerts.net;

# the backend api
location /api {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://127.0.0.1:9000;
}

# caching static assets
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 7d;
}

location / {
try_files $uri $uri/ /index.html;
}
}
6 changes: 6 additions & 0 deletions infra/deployment/roles/ubuntu-16-04/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
- name: Ensure python2 is present (required by ubuntu 16.04)
become: yes
raw: apt-get -y install python-simplejson

- name: Install unzip tool
become: yes
apt:
name: unzip
state: latest
4 changes: 4 additions & 0 deletions infra/deployment/scripts/build-alerts-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e
cd ../../alerts-ui/ && ng build --prod && zip -r web.zip dist/* && cd -
mv ../../alerts-ui/web.zip web.zip

0 comments on commit 36c866a

Please sign in to comment.