-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.yml
147 lines (130 loc) · 4.95 KB
/
config.yml
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
version: 2
jobs:
build:
docker:
- image: circleci/openjdk:8-jdk-browsers
working_directory: ~/repo
steps:
- checkout
- restore_cache:
key: circleci-challenge-{{ checksum "pom.xml" }}
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: circleci-challenge-{{ checksum "pom.xml" }}
- run:
name: Start SauceLabs Tunnel (required if testing on CircleCI container)
command: |
curl https://saucelabs.com/downloads/sc-4.4.12-linux.tar.gz -o saucelabs.tar.gz
tar -xzf saucelabs.tar.gz
cd sc-*
# startup saucelabs tunnel as background task (its a blocking command)
bin/sc -u ${SAUCELABS_USER} -k ${SAUCELABS_KEY} &
#wait for sauce tunnel up to 1 minute
wget --retry-connrefused --no-check-certificate -T 60 localhost:4445
- run:
name: Build and test
command: |
mvn package -B #run your tests
killall sc #kill saucelabs tunnel
- run:
name: Copy deployment artifacts to workspace
command: |
cp target/circleci-challenge-*.jar /tmp/standalone-app.jar
cp .circleci/setup-heroku.sh /tmp/setup-heroku.sh
cp src/main/resources/deployment/cf-dev-manifest.yml /tmp/
- store_test_results:
path: target/surefire-reports
- store_artifacts:
path: /tmp/standalone-app.jar
- store_artifacts:
path: /tmp/cf-dev-manifest.yml
- persist_to_workspace:
root: /tmp
paths:
- standalone-app.jar
- setup-heroku.sh
- cf-dev-manifest.yml
deploy-heroku:
docker:
- image: circleci/openjdk:8-jdk-browsers
working_directory: ~/deploy
steps:
# why rebuild something we already tested, rebuilding invalidates any previous confidence?!
- attach_workspace:
at: /tmp
- run:
name: Run setup script
command: bash /tmp/setup-heroku.sh
- run:
name: Heroku Deploy
command: |
cp /tmp/standalone-app.jar .
ls -la
heroku plugins:install heroku-cli-deploy
heroku plugins:install heroku-cli-deploy # when debugging on circle image, first run succeeded, but did not make plugin available
heroku deploy:jar standalone-app.jar --app $HEROKU_APP_NAME
- run:
name: Smoke Test
command: |
# Heroku deploy command will pass even if application crashes. Simple smoke test to make sure app is up.
HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://$HEROKU_APP_NAME.herokuapp.com`
if [ "$HTTPCODE" -ne 200 ];then
echo "heroku app not responding, failing deploy"
exit 1
fi
deploy-cf:
docker:
- image: eddiewebb/queue-circleci-openjdk:8-jdk-browsers
#- image: circleci/openjdk:8-jdk-browsers
working_directory: ~/deploy
steps:
# why rebuild something we already tested, rebuilding invalidates any previous confidence?!
- attach_workspace:
at: /tmp
- run: queueBuildUntilFrontOfLine 5 #do not run parallel deployments
- run:
name: Setup CF CLI
command: |
curl -v -L -o cf-cli_amd64.deb 'https://cli.run.pivotal.io/stable?release=debian64&source=github'
sudo dpkg -i cf-cli_amd64.deb
cf -v
cf api https://api.run.pivotal.io
cf auth $CF_USER $CF_PASSWORD
cf target -o eddies-org -s development
- run:
name: CF Deploy
command: |
# Copy deployable jar and CF Manifest to current dir
cp /tmp/standalone-app.jar .
cp /tmp/cf-dev-manifest.yml .
# Push as "dark" instance
cf push circleci-dark -f cf-dev-manifest.yml -p standalone-app.jar -n circleci-dark
# Verify new version is working on dark URL.
HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://circleci-dark.cfapps.io/`
if [ "$HTTPCODE" -ne 200 ];then
echo "dark route note available, failing deploy"
exit 1
fi
# Send "real" url to new version
cf map-route circleci-dark cfapps.io -n circleci-challenge
# Stop sending traffic to previous version
cf unmap-route circleci-challenge cfapps.io -n circleci-challenge
# stop previous version
cf stop circleci-challenge
# delete previous version
cf delete circleci-challenge -f
# Switch name of "dark" version to claim correct name
cf rename circleci-dark circleci-challenge
workflows:
version: 2
build-deploy:
jobs:
- build
- deploy-heroku:
requires:
- build
- deploy-cf:
requires:
- build