-
Notifications
You must be signed in to change notification settings - Fork 3
/
ci_cd.sh
executable file
·32 lines (27 loc) · 992 Bytes
/
ci_cd.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
#!/bin/sh
# chmod +x ci_cid.sh
# sudo crontab -e & paste:
# Put this in sudo crontab -e ->
# * * * * * cd /home/ubuntu/dailyWord-bot/ && . ./ci_cd.sh > ./ci_cd.log 2>&1
# 0,10,15,20,30,40,50 * * * * cd /home/ubuntu/dailyWord-bot/ && . ./ci_cd.sh$
echo "Running pipeline on "$(date "+%d/%m/%y %H:%M:%S")""
CURRENT_TAG=$(git describe --tags)
# fetch the remote tags available
git fetch --tags
# retrieve the latest tag available by using the “git describe” command
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo Current tag: $CURRENT_TAG, Latest tag: $LATEST_TAG
if [ $CURRENT_TAG = $LATEST_TAG ]
then
echo "Not updating"
else
echo "updating"
export VERSION=$LATEST_TAG
echo "Checking out to '$VERSION'"
git checkout $VERSION
echo "Deploying version: '$VERSION'"
sudo docker-compose build
sudo docker-compose down
sudo -E docker-compose up -d
echo "Deployed version: '$VERSION' on "$(date "+%d/%m/%y %H:%M:%S")""
fi