-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·38 lines (31 loc) · 1012 Bytes
/
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
#!/bin/bash
# Author: Ismail Dawoodjee
# Bash script to update EC2, install and start Docker, pull image and run
# the Flask container. Upon successful deployment, exit the VM.
set -euo pipefail
mkdir logs
LOG_LOCATION="./logs"
exec > >(tee -a $LOG_LOCATION/dockerize.log)
exec 2>&1
START_TIME=$(date +"%s")
DATE_TIME=$(date +"%x %r %S %Z")
echo -e "Started deployment at $DATE_TIME \n"
USER_NAME="ismaildawoodjee"
REPO_NAME="flask-app"
function update_and_install () {
# Update, install, start, pull, and run
echo -e "INFO: Updating EC2, installing Docker and starting it up \n"
sudo yum -y -q update
sudo yum -y -q install docker
sudo service docker start
sudo docker pull "$USER_NAME/$REPO_NAME:ec2"
sudo docker run -d \
--name flask-container \
-p 5000:5000 \
"$USER_NAME/$REPO_NAME:ec2"
}
update_and_install
END_TIME=$(date +"%s")
DURATION=$((END_TIME - START_TIME))
echo -e "INFO: Completed deployment within $DURATION seconds. Exiting... \n"
exit