-
Notifications
You must be signed in to change notification settings - Fork 8
/
deploy.sh
executable file
·48 lines (36 loc) · 1.08 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
#!/bin/bash
# Deploys a Vapor project to an EC2 instance
#
# run with ./deploy.sh SERVER_IP
# Example:
# ./deploy.sh ec2-12-34-456-890.compute-1.amazonaws.com
if [ "$1" == "" ]; then
echo "ERROR: 1st parameter is missing. Should be USER@SERVER"
exit
fi
ARCHIVE="/tmp/app.zip"
FOLDER="~/app"
echo "starting deployment to $1"
echo "zipping the project’s Git HEAD to $ARCHIVE"
git archive -o $ARCHIVE HEAD
echo "uploading to $1, please wait"
scp -r $ARCHIVE $1:/tmp/
echo "optionally (re)creating folder $FOLDER on server"
CMD="mkdir -p $FOLDER"
ssh $1 $CMD
echo "unzipping uploaded file to $FOLDER on server"
CMD="unzip -o -q $ARCHIVE -d $FOLDER"
ssh $1 $CMD
echo "deleting optionally existing .gitignore & .travis.yml on server"
CMD="cd $FOLDER && rm -f .gitignore* && rm -f .travis*"
ssh $1 $CMD
echo "building project, please wait"
CMD="cd $FOLDER && swift package update && vapor build --release"
ssh $1 "bash -lc \"$CMD\""
echo "restarting service"
CMD="sudo systemctl restart app"
ssh $1 $CMD
echo "service status:"
CMD="sudo systemctl status app"
ssh $1 $CMD
echo "Finished!"