forked from devops329/jwt-pizza-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployService.sh
executable file
·47 lines (40 loc) · 1.06 KB
/
deployService.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
while getopts k:h:s: flag
do
case "${flag}" in
k) key=${OPTARG};;
h) hostname=${OPTARG};;
esac
done
if [[ -z "$key" || -z "$hostname" ]]; then
printf "\nMissing required parameter.\n"
printf " syntax: deployService.sh -k <pem key file> -h <hostname>\n\n"
exit 1
fi
service="jwt-pizza-service"
printf "\n----> Deploying $service to $hostname with $key\n"
# Step 1
printf "\n----> Build the distribution package\n"
rm -rf dist
mkdir dist
cp -r src/* dist
cp *.json dist
# Step 2
printf "\n----> Clearing out previous distribution on the target\n"
ssh -i "$key" ubuntu@$hostname << ENDSSH
rm -rf services/${service}
mkdir -p services/${service}
ENDSSH
# Step 3
printf "\n----> Copy the distribution package to the target\n"
scp -r -i "$key" dist/* ubuntu@$hostname:services/$service
# Step 4
printf "\n----> Deploy the service on the target\n"
ssh -i "$key" ubuntu@$hostname << ENDSSH
bash -i
cd services/${service}
npm install
pm2 restart ${service}
ENDSSH
# Step 5
printf "\n----> Removing local copy of the distribution package\n"
rm -rf dist