Skip to content

Commit c8f4d0a

Browse files
committed
update travis deployment to use assume role
1 parent e9fd0b9 commit c8f4d0a

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ db/**/*.db
1818
!.elasticbeanstalk/*.global.yml
1919

2020
.deploy
21+
22+
.envrc

.travis.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,19 @@ install:
1111
# install aws cli
1212
- sudo apt-get -y install python-pip
1313
- sudo pip install awscli
14+
- aws --version
1415

1516
script: mvn clean test -Dspring.profiles.active=test
1617

17-
after_success:
18+
before_deploy:
1819
# Parse branch name and determine an environment to deploy
1920
- export ENV=$(echo "${TRAVIS_BRANCH}" | perl -ne "print $& if /(?<=deploy\/).*/")
2021
# Switch AWS Role when ENV is prod
2122
- test "${ENV}" = "prod" && source scripts/switch-production-role.sh
2223

23-
before_deploy:
24-
# Create an archive to deploy
25-
- scripts/create-archives.sh
2624
deploy:
27-
# upload jar and codedeploy scripts
28-
- provider: s3
29-
bucket: deploy-${ENV}.hana053.com
30-
region: ${AWS_DEFAULT_REGION}
31-
local_dir: .deploy
32-
upload-dir: micropost
25+
- provider: script
26+
script: scripts/deploy.sh
3327
skip_cleanup: true
3428
on:
3529
branch: deploy/*
36-
# deploy by using codedeploy
37-
- provider: codedeploy
38-
bucket: deploy-${ENV}.hana053.com
39-
region: ${AWS_DEFAULT_REGION}
40-
key: micropost/codedeploy.tar.gz
41-
application: micropost
42-
deployment_group: web
43-
bundle_type: tgz
44-
on:
45-
branch: deploy/*
46-

scripts/create-archives.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/deploy.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
if [ -z "${ENV}" ]; then
4+
echo "ENV is required."
5+
exit 1
6+
fi
7+
8+
# prepare tmp directory to deploy
9+
TMP_DIR=.deploy
10+
11+
rm -rf ${TMP_DIR}
12+
mkdir ${TMP_DIR}
13+
14+
# create jar
15+
mvn clean package -DskipTests=true -Dmaven.javadoc.skip=true
16+
cp ./target/springboot-angular2-tutorial-0.1.0.jar ${TMP_DIR}/app.jar
17+
18+
# create codedeploy archive
19+
tar cvzf ${TMP_DIR}/codedeploy.tar.gz -C codedeploy .
20+
21+
# upload archives
22+
aws s3 sync .deploy s3://deploy-${ENV}.hana053.com/micropost
23+
24+
# deploy
25+
aws deploy create-deployment --application-name micropost \
26+
--s3-location bucket=deploy-${ENV}.hana053.com,key=micropost/codedeploy.tar.gz,bundleType=tgz \
27+
--deployment-group-name web

0 commit comments

Comments
 (0)