-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·129 lines (70 loc) · 1.87 KB
/
build.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
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Immediately exit when fail
set -e
echo "RUNNING BUILD SCRIPT FOR PIGGY TRACKING REPO"
# GIT operation
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "PULLING GIT: pulling chages from git repo ..."
git pull
else
echo "ERROR: Not a Git repo. Exiting!!!!"
exit 1
fi
echo "DONE"
printf "PULLING GIT: sucessfully\n\n"
# Docker: Remove old container and images
echo "Docker: removing images and containers..."
echo "Docker: removing containers"
sudo docker rm -f piggyfectn
sudo docker rm -f piggybectn
echo "DONE"
sudo docker rmi -f piggyfe
sudo docker rmi -f piggybe
echo "DONE"
printf "_______________________\n\n"
# Front end
cd frontend
echo "FRONT END BUILDING"
echo "Building image"
sudo docker build -t piggyfe .
echo "Running container"
sudo docker run -it -d --name piggyfectn piggyfe
echo "DONE!"
echo "Copy dist: Docker cp - COPYING dist to /var/html"
sudo docker cp piggyfectn:/app/dist /var/www/html/
echo "DONE!"
echo "STOPING the container front end"
sudo docker stop piggyfectn
echo "REMOVE the container front end"
sudo docker rm -f piggyfectn
echo "REMOVE the container image"
sudo docker rmi -f piggyfe
echo "DONE"
printf "FRONT END build successfully\n\n"
cd ..
# SLEEP
printf "SLEEPING 30s"
sleep 30s
# Back end
cd backend
echo "BACK END building"
echo "Building images"
sudo docker build -t piggybe .
echo "DONE"
echo "Running container"
sudo docker run -it -d --name piggybectn piggybe
echo "DONE!"
echo "Copying the binary to the host"
sudo docker cp piggybectn:/app/piggybe-bin .
echo "DONE!"
echo "Stoping container"
sudo docker stop piggybectn
echo "Removing container"
sudo docker rm -f piggybectn
echo "Removing image"
sudo docker rmi piggybe
# BACK END SERVICE
echo "Piggy Backend ServiceRestart the systemctl service"
sudo systemctl restart piggybe-service.service
printf "DONE\n\n"
echo "FINISHED!"