Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp90023-assignment-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matthew O'Halloran
comp90023-assignment-2
Commits
5abc4525
Commit
5abc4525
authored
5 years ago
by
matt01671
Browse files
Options
Downloads
Patches
Plain Diff
react build
parent
9d557613
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ansible/roles/react-build/tasks/main.yaml
+148
-78
148 additions, 78 deletions
ansible/roles/react-build/tasks/main.yaml
with
148 additions
and
78 deletions
ansible/roles/react-build/tasks/main.yaml
+
148
−
78
View file @
5abc4525
...
...
@@ -8,7 +8,7 @@
become
:
yes
apt
:
name
:
[
'
nodejs'
,
'
npm'
]
state
:
presen
t
state
:
lates
t
install_recommends
:
no
update_cache
:
yes
-
debug
:
...
...
@@ -20,7 +20,16 @@
npm
:
name
:
npm
global
:
yes
state
:
present
state
:
latest
-
name
:
install pm2 server
tags
:
'
pm2'
become
:
yes
npm
:
name
:
pm2
global
:
yes
state
:
latest
-
name
:
install react
tags
:
'
react'
...
...
@@ -30,6 +39,38 @@
global
:
yes
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
...
...
@@ -37,127 +78,167 @@
chdir
:
/var/lib/react
register
:
dir_changed
-
name
:
create a new directory for git
become
:
yes
shell
:
mkdir react-app
args
:
chdir
:
/var/lib/react/
register
:
new_dir
when
:
dir_changed.rc ==
0
-
name
:
traverse into the new directory.
become
:
yes
shell
:
cd
args
:
chdir
:
/var/lib/react/react-app
register
:
new_dir_changed
when
:
new_dir.rc ==
0
-
name
:
clone git repo
become
:
yes
git
:
repo
:
https://git
hub.com/advait22/react-server
.git
dest
:
/var/lib/react
repo
:
https://git
lab.eng.unimelb.edu.au/mohalloran/comp90023-assignment-2
.git
dest
:
/var/lib/react
/react-app/
force
:
yes
-
debug
:
msg
:
'
git
repo
cloned'
when
:
dir_changed.rc == 0
when
:
new_
dir_changed.rc == 0
-
name
:
change working directory to the app
-
name
:
navigate into the git directory.
become
:
yes
shell
:
cd
args
:
chdir
:
/var/lib/react/express_react_example
register
:
server
chdir
:
/var/lib/react/react-app/
register
:
nav_git
-
name
:
delete unnecessary directories
become
:
yes
shell
:
rm -rf ansible/ couchDB/ CouchDB/ twitter_harvest/
args
:
chdir
:
/var/lib/react/react-app/
-
debug
:
msg
:
'
delete
unnecessary
directories'
register
:
del_dir
# when: nav_git.rc == 0
-
name
:
navigate to project dir
become
:
yes
shell
:
cd
args
:
chdir
:
/var/lib/react/react-app/reactUI/
-
debug
:
msg
:
'
navigate
successfully'
register
:
nav_project
-
name
:
install all the packages for server
become
:
yes
npm
:
path
:
/var/lib/react/
express_react_example
/
path
:
/var/lib/react/
react-app/reactUI
/
name
:
install
-
debug
:
msg
:
'
inside
server'
when
:
server.rc == 0
register
:
dep_install
-
name
:
install dependencies
become
:
yes
command
:
npm install --save express
-
debug
:
msg
:
'
Client
express
installed'
-
name
:
change working directory to the client
become
:
yes
shell
:
cd
args
:
chdir
:
/var/lib/react/
express_react_example/client
chdir
:
/var/lib/react/
react-app/reactUI/choropleth-map
register
:
client
-
name
:
install dependencies
become
:
yes
npm
:
path
:
/var/lib/react/
express_react_example/client
path
:
/var/lib/react/
react-app/reactUI/choropleth-map
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
path
:
/var/lib/react/
react-app/reactUI/choropleth-map
/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
/
chdir
:
/var/lib/react/
react-app/reactUI/choropleth-map
/
register
:
build_delete
-
debug
:
msg
:
"
build
deleted"
when
:
files_to_delete.stat.exists ==
true
-
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'
# ###workaround for react js bug in build command
-
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/
name
:
express
-
debug
:
msg
:
'
Client
express
installed'
# - name: delete dependencies on client
# become: yes
# shell: rm -rf node_modules package-lock.json
# args:
# chdir: /var/lib/react/react-app/reactUI/choropleth-map/
# register: deleted_modules
# - debug:
# msg: 'Client Dependencies delete'
-
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: clear npm cache
# tags: 'clear cache'
# become: yes
# shell: npm cache clean --force
# args:
# chdir: /var/lib/react/react-app/reactUI/choropleth-map/
# register: cache_cleaned
# when: deleted_modules.rc == 0
# - name: install dependencies
# become: yes
# npm:
# path: /var/lib/react/react-app/reactUI/choropleth-map/
# 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
shell
:
npm install --save react-scripts@3.0.1 react react-dom
jquery @material-ui/core react-chartkick chart.js datamaps
args
:
chdir
:
/var/lib/react/
express_react_example/client
chdir
:
/var/lib/react/
react-app/reactUI/choropleth-map/
register
:
react_scripts
when
:
cache_cleaned.rc ==
0
# 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
chdir
:
/var/lib/react/
react-app/reactUI/choropleth-map/
-
debug
:
msg
:
'
new
build
successfull'
-
name
:
Ansible check directory exists build in server.
stat
:
path
:
/var/lib/react/
express_react_example
/build
path
:
/var/lib/react/
react-app/reactUI
/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/
warn
:
false
chdir
:
/var/lib/react/react-app/reactUI/
register
:
build_delete_server
-
debug
:
msg
:
"
deleting
old
build
from
server"
...
...
@@ -165,35 +246,24 @@
-
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
command
:
cp -r
/var/lib/react/
react-app/reactUI/choropleth-map
/build /var/lib/react/
react-app/reactUI/
register
:
build_copy
-
debug
:
msg
:
'
build
copied'
when
:
build_delete_server.rc ==
0
-
name
:
"
Install
forever
(to
run
Node.js
app)."
become
:
yes
npm
:
name
:
forever
global
:
yes
state
:
present
-
name
:
"
Check
list
of
Node.js
apps
running."
-
name
:
stop all the running server
become
:
yes
command
:
forever list
register
:
forever_list
changed_when
:
false
-
name
:
stop if the server is running
become
:
yes
command
:
forever stopall
command
:
pm2 stop all
register
:
stop_server
-
debug
:
msg
:
"
server
stopped"
when
:
forever_list.stdout.find('/var/lib/react/express_react_example/server.js') == "336"
msg
:
'
all
servers
stopped'
-
name
:
"
S
tart
react.js
app."
-
name
:
s
tart
the server
become
:
yes
command
:
forever
start /var/lib/react/
express_react_example
/server.js
command
:
pm2
start /var/lib/react/
react-app/reactUI
/server.js
-
debug
:
msg
:
"
server
started"
when
:
forever_list.stdout.find('/var/lib/react/express_react_example/server.js') == -1
msg
:
'
yayyyyyyyyyyy
app
is
running'
# when: stop_server.rc == 0
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment