-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.sh
executable file
·112 lines (98 loc) · 5.23 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
# Cleaning device before building the whole thing - needed only on tiny devices...
#docker system prune --all --force
if [[ $1 == docker ]]; then
echo Installing using docker...
sudo docker build -t ghyslainbruno/lazyker .
if [ ! "$(sudo docker ps -q -f name=lazyker)" ]; then
if [ "$(sudo docker ps -aq -f status=exited -f name=lazyker)" ]; then
# cleanup
echo 'Old lazyker container exited - cleaning up'
docker rm lazyker
fi
# run your container
#docker run -d --name <name> my-docker-image
echo 'Running new version of lazyker container'
sudo docker run -p 8080:80 --restart unless-stopped -v /home/ghyslain/lazyker/backend/coverage:/lazyker/app/backend/coverage -v /home/ghyslain/lighthouse:/lighthouse --name lazyker -d ghyslainbruno/lazyker
else
echo 'Lazyker container already running - removing and updating and running new one...'
sudo docker kill lazyker
sudo docker rm lazyker
sudo docker run -p 8080:80 --restart unless-stopped -v /home/ghyslain/lazyker/backend/coverage:/lazyker/app/backend/coverage -v /home/ghyslain/lighthouse:/lighthouse --name lazyker -d ghyslainbruno/lazyker
fi
## Running backend tests - editing report file -> in the running container
#docker exec -it lazyker /bin/sh -c "cd backend;npm test Cloudscrapper;pwd=`pwd` && sed -i -e \"s|\/lazyker\/app\/backend|\/root\/src|g\" coverage/lcov.info"
#
## Run sonarqube analysis on backend part
#cd backend && \
#docker run -v $(pwd):/root/src --link sonarqube newtmitch/sonar-scanner sonar-scanner \
# -Dsonar.projectKey=lazyker-back \
# -Dsonar.projectName='Lazyker Back' \
# -Dsonar.sources=. \
# -Dsonar.tests=. \
# -Dsonar.test.inclusions='**/*.test.js' \
# -Dsonar.exclusions='**/node_modules/**,**/coverage/**,**/*.json/**,**/*.pem/**,**/*.xml/**' \
# -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
# -Dsonar.testExecutionReportPaths=coverage/test-report.xml \
# -Dsonar.host.url='http://sonarqube.ghyslain.xyz:9000' \
# -Dsonar.login=c37d841c739531680ebf8c1f874012806bd01da7 && \
#
## Run sonarqube analysis on frontend part
#cd .. && \
#cd client && \
#docker run -v $(pwd):/root/src --link sonarqube newtmitch/sonar-scanner sonar-scanner \
# -Dsonar.projectKey=lazyker-front \
# -Dsonar.projectName='Lazyker Front' \
# -Dsonar.sources=. \
# -Dsonar.host.url=http://sonarqube.ghyslain.xyz:9000 \
# -Dsonar.login=c37d841c739531680ebf8c1f874012806bd01da7 && \
cd /home/ghyslain/lazyker
elif [[ $1 == test_backend ]]; then
echo Running backend tests...
cd backend
# Only Running these tests for now --> TODO write (a lot) more tests !
sudo docker exec -t lazyker /bin/sh -c "cd backend;npm test Cloudscrapper;pwd=`pwd` && sed -i -e \"s|\/lazyker\/app\/backend|\/root\/src|g\" coverage/lcov.info"
elif [[ $1 == test_frontent ]]; then
echo Running frontend tests...
cd client
# No frontend tests written for now --> TODO write a lot of tests !
elif [[ $1 == backend_analysis ]]; then
echo Running backend analisys...
cd backend
sudo docker run -t -v $(pwd):/usr/src newtmitch/sonar-scanner \
-Dsonar.projectKey=lazyker-back \
-Dsonar.projectName='Lazyker Back' \
-Dsonar.organization=ghyslainbruno \
-Dsonar.sources=. \
-Dsonar.tests=. \
-Dsonar.test.inclusions='**/*.test.js' \
-Dsonar.exclusions='**/node_modules/**,**/coverage/**,**/*.json/**,**/*.pem/**,**/*.xml/**' \
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
-Dsonar.testExecutionReportPaths=coverage/test-report.xml \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=28a4ef2881be958ff37da6deee7b915816c32a04
elif [[ $1 == lighthouse_analysis ]]; then
echo Running Lighthouse analisys...
sudo docker exec -t lazyker /bin/sh -c "cd /lighthouse && echo y | lighthouse 'https://lazyker.ghyslain.xyz' --chrome-flags='--headless --no-sandbox' --output-path='index.html'"
elif [[ $1 == frontend_analysis ]]; then
echo Running frontend analisis...
cd client
sudo docker run -t -v $(pwd):/usr/src newtmitch/sonar-scanner \
-Dsonar.projectKey=lazyker-front \
-Dsonar.projectName='Lazyker Front' \
-Dsonar.organization=ghyslainbruno \
-Dsonar.sources=. \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=28a4ef2881be958ff37da6deee7b915816c32a04
else
# pm2 should already be running (in sudo mode) with watch set to true -> to properly update the whole application
# chromium should be placed in here -> /usr/bin/chromium-browser (a simlink can do the trick if it is not)
echo Installing without docker...
echo Installing backend dependencies...
cd backend && yarn install --ignore-engines && cd ..
echo Installing frontend dependencies...
cd client && yarn install
echo Building frontend build...
cd .. && cd backend && rm -rf client_build && cd .. && cd client
yarn run build && cd ..
fi