-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
65 lines (65 loc) · 1.99 KB
/
deploy.sh
File metadata and controls
65 lines (65 loc) · 1.99 KB
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
#!/usr/bin/env bash
# Application name, please set
APPLICATION_NAME='adam-blog' # Use hyphens - only as symbols, no _ underscores (NIRD convention)
# Colors for cosmetics
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m'
ACTUAL_BRANCH=${CI_BRANCH} # Obtain actual branch if we are building under CODESHIP
if [ "$ACTUAL_BRANCH" != "staging" -a "$ACTUAL_BRANCH" != "production" -a "$ACTUAL_BRANCH" != "master" ] ; then
echo -e "${YELLOW}Not deploying the branch $ACTUAL_BRANCH."
exit 0;
fi
function rollback {
cf delete $APPLICATION_NAME -f
cf rename ${APPLICATION_NAME}-old $APPLICATION_NAME
}
echo -e "${YELLOW}Starting deployment of $ACTUAL_BRANCH"
######################
# CLI SETUP
######################
echo -e "${GREEN}[+] Download Cli"
cd ../
wget -qO cf-linux-amd64.tgz 'https://cli.run.pivotal.io/stable?release=linux64-binary&source=github' && \
tar -xf cf-linux-amd64.tgz && \
rm cf-linux-amd64.tgz
export PATH=$PATH:$PWD
######################
# CF LOGIN
######################
echo -e "${GREEN}[+] CF Login"
cf api "$CF_API_URL"
cf login -u "$CF_USER" -p "$CF_PASS" -o "$CF_ORG" -s "$ACTUAL_BRANCH"
######################
# APP BACKUP AND PUSH
######################
echo -e "${GREEN}[+] Pushing application"
cd - # Go back to the application's folder
rm -rf vendor/bundle
cf rename $APPLICATION_NAME ${APPLICATION_NAME}-old
if ! cf push $APPLICATION_NAME -f ./${ACTUAL_BRANCH}-manifest.yml --no-start; then
echo -e "${RED}[-] Application could not be pushed, rolling back..."
rollback
exit -1;
fi
######################
# APP ENV SETUP
######################
echo -e "${GREEN}[+] Setting application environment"
######################
# APP START
######################
echo -e "${GREEN}[+] Starting application"
if ! cf start $APPLICATION_NAME; then
echo -e "${RED}[-] Application could not be started, rolling back..."
rollback
exit -1;
fi
######################
# CLEANUP
######################
cf delete ${APPLICATION_NAME}-old -f
cf logout
echo -e "${GREEN}[+] Deploy Complete"
exit 0