Skip to content
Snippets Groups Projects
Commit 687e17d7 authored by matt01671's avatar matt01671
Browse files

web server code

parent f475427d
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
. ./unimelb-comp90024-2020-grp-62-openrc.sh; ansible-playbook -i hosts --ask-become-pass build-web.yaml
\ No newline at end of file
# - hosts: localhost
# vars_files:
# - host_vars/web.yaml
# gather_facts: true
# roles:
# - role: openstack-common
# - role: openstack-volume
# - role: openstack-security-group
# - role: cluster-security-group
# - role: openstack-instance
- hosts: web
vars_files:
- host_vars/react.yaml
gather_facts: true
roles:
# - role: openstack-proxy
# - role: all-dependencies
# - role: all-mount
# - role: all-docker
- role: react-build
\ No newline at end of file
#!/usr/bin/env bash #!/usr/bin/env bash
. ./unimelb-comp90024-2020-grp-62-openrc.sh; ansible-playbook -i hosts --ask-become-pass all-in-one.yaml . ./unimelb-comp90024-2020-grp-62-openrc.sh; ansible-playbook -i hosts --ask-become-pass create-instances.yaml
\ No newline at end of file \ No newline at end of file
...@@ -29,15 +29,7 @@ ...@@ -29,15 +29,7 @@
roles: roles:
- role: react-build - role: react-build
# - hosts: dbs
# roles:
# - role: cluster-build
# - hosts: master
# roles:
# - role: slaves-cluster
\ No newline at end of file
...@@ -9,8 +9,6 @@ volumes: ...@@ -9,8 +9,6 @@ volumes:
vol_size: 50 vol_size: 50
- vol_name: dbvolume3 - vol_name: dbvolume3
vol_size: 50 vol_size: 50
# - vol_name: webvolume
# vol_size: 30
# Security group # Security group
security_groups: security_groups:
...@@ -67,10 +65,6 @@ instances: ...@@ -67,10 +65,6 @@ instances:
volumes: ['dbvolume3'] volumes: ['dbvolume3']
meta: meta:
group: slaves group: slaves
# - name: web
# volumes: ['webvolume']
# meta:
# group: web
instance_image: 45225edb-66d8-4fd0-bf41-132a31a18166 instance_image: 45225edb-66d8-4fd0-bf41-132a31a18166
instance_key_name: test-moh instance_key_name: test-moh
......
react_dir: react-app ---
volumes:
- device: /dev/vdb
mountpoint: /var/lib/react
# Common vars
availability_zone: melbourne-qh2-uom
# Volume
volumes:
- vol_name: webvolume
vol_size: 30
# Security group
security_groups:
- name: ssh
description: "Security group for SSH access"
protocol: tcp
port_range_min: 22
port_range_max: 22
remote_ip_prefix: 0.0.0.0/0
- name: http
description: "Security group for HTTP"
protocol: tcp
port_range_min: 80
port_range_max: 3000
remote_ip_prefix: 0.0.0.0/0
- name: couchDB-cluster4
description: "Security group for CouchDB cluster"
protocol: tcp
port_range_min: 5984
port_range_max: 5984
remote_ip_prefix: 0.0.0.0/0
cluster_security_group:
- name: couchDB-cluster1
description: "Security group for CouchDB cluster"
protocol: tcp
port_range_min: 5984
port_range_max: 5984
sg_remote_group: couchDB-cluster1
- name: couchDB-cluster2
description: "Security group for CouchDB cluster"
protocol: tcp
port_range_min: 9100
port_range_max: 9200
sg_remote_group: couchDB-cluster2
- name: couchDB-cluster3
description: "Security group for CouchDB cluster"
protocol: tcp
port_range_min: 4369
port_range_max: 4369
sg_remote_group: couchDB-cluster3
# Instance
instances:
- name: web
volumes: ['webvolume']
meta:
group: web
instance_image: 45225edb-66d8-4fd0-bf41-132a31a18166
instance_key_name: test-moh
instance_flavor: uom.mse.2c9g
[web] [web]
172.26.131.194 ansible_host=172.26.131.194
[master] [master]
172.26.133.58 ansible_host=172.26.133.58 172.26.133.58 ansible_host=172.26.133.58
......
---
- name: check if packages exits
package_facts:
manager: auto
- name: 'install all the dependencies '
tags: always
become: yes
apt:
name: ['nodejs','npm']
state: latest
install_recommends: no
update_cache: yes
- debug:
msg: "node and npm installed"
- name: make sure the latest npm is installed - name: make sure the latest npm is installed
tags: 'node' tags: 'node'
become: yes become: yes
...@@ -21,3 +37,197 @@ ...@@ -21,3 +37,197 @@
name: create-react-app name: create-react-app
global: yes global: yes
state: present state: present
# - name: Checking folders
# tags: 'volumes'
# become: yes
# stat:
# path: "{{ item.mountpoint }}"
# register: directory_stats
# with_items:
# - "{{ volumes }}"
# - name: Create directory
# tags: 'volumes'
# become: yes
# file:
# path: "{{ item.item.mountpoint }}"
# recurse: yes
# state: directory
# when: item.stat.exists == false
# with_items:
# - "{{ directory_stats.results }}"
# - name: Mount device
# tags: 'volumes'
# become: yes
# mount:
# path: "{{ item.mountpoint }}"
# src: "{{ item.device }}"
# fstype: xfs
# state: mounted
# when: item.device is defined
# with_items:
# - "{{ volumes }}"
- name: traverse into the project directory.
become: yes
shell: cd
args:
chdir: /var/lib/react
register: dir_changed
- name: clone git repo
become: yes
git:
repo: https://github.com/advait22/react-server.git
dest: /var/lib/react
force: yes
- debug:
msg: 'git repo cloned'
when: dir_changed.rc == 0
- name: change working directory to the app
become: yes
shell: cd
args:
chdir: /var/lib/react/express_react_example
register: server
- name: install all the packages for server
become: yes
npm:
path: /var/lib/react/express_react_example/
name: install
- debug:
msg: 'inside server'
when: server.rc == 0
- name: install dependencies
become: yes
command: npm install --save express
- debug:
msg: 'Client express installed'
when: server.rc == 0
- name: change working directory to the client
become: yes
shell: cd
args:
chdir: /var/lib/react/express_react_example/client
register: client
- name: install dependencies
become: yes
npm:
path: /var/lib/react/express_react_example/client
name: install
- debug:
msg: 'Client Dependencies installed'
when: client.rc == 0
- name: Ansible check directory exists build in client.
stat:
path: /var/lib/react/express_react_example/client/build
register: files_to_delete
- name: delete previous build folder
become: yes
shell: rm -rf build
args:
chdir: /var/lib/react/express_react_example/client/
register: build_delete
- debug:
msg: "build deleted"
when: files_to_delete.stat.exists == true
###workaround for react js bug in build command
- name: delete dependencies on client
become: yes
shell: rm -rf node_modules
args:
chdir: /var/lib/react/express_react_example/client/
register: deleted_modules
- debug:
msg: 'Client Dependencies delete'
- name: clear npm cache
tags: 'clear cache'
become: yes
shell: npm cache clean --force
args:
chdir: /var/lib/react/express_react_example/client
register: cache_cleaned
when: deleted_modules.rc == 0
- name: install dependencies
become: yes
npm:
path: /var/lib/react/express_react_example/client
name: install
- debug:
msg: 'Client Dependencies installed'
when: cache_cleaned.rc == 0
- name: install react scripts
tags: 'react scripts'
become: yes
shell: npm install --save react-scripts@3.0.1 react react-dom
args:
chdir: /var/lib/react/express_react_example/client
register: react_scripts
when: cache_cleaned.rc == 0
#################################################################
- name : compile the new build
tags: build
become: yes
shell: npm run build
args:
chdir: /var/lib/react/express_react_example/client
- debug:
msg: 'new build successfull'
- name: Ansible check directory exists build in server.
stat:
path: /var/lib/react/express_react_example/build
register: files_to_delete_from_server
- name: delete previous build folder in server
become: yes
shell: rm -rf build
args:
chdir: /var/lib/react/express_react_example/
register: build_delete_server
- debug:
msg: "deleting old build from server"
when: files_to_delete_from_server.stat.exists == true
- name: copy new build to parent folder
become: yes
command: mv /var/lib/react/express_react_example/client/build /var/lib/react/express_react_example
register: build_copy
- debug:
msg: 'build copied'
when: build_delete_server.rc == 0
# - name: stop all the running server
# become: yes
# command: pm2 stop all
# register: stop_server
# - debug:
# msg: 'all servers stopped'
# # when: build_copy.rc == 0
- name: start the server
become: yes
# command: node /var/lib/react/express_react_example/server.js &
command: pm2 start /var/lib/react/express_react_example/server.js
- debug:
msg: 'yayyyyyyyyyyy app is running'
# when: stop_server.rc == 0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment