Skip to content

Commit db78e89

Browse files
committed
stg use role_arn too
1 parent 1e3f087 commit db78e89

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

scripts/deploy.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
#!/usr/bin/env bash
22

3-
if [ -z "${ENV}" ]; then
4-
echo "ENV is required."
5-
exit 1
6-
fi
3+
set -u
74

8-
# switch role if production
9-
if [ "${ENV}" = "prod" ]; then
10-
source scripts/switch-production-role.sh
5+
if [ ! -v AWS_SESSION_TOKEN ]; then
6+
source ./scripts/switch-role.sh
117
fi
128

139
# set variables
1410
CDN_URL="https://cdn-${ENV}.hana053.com"
1511
S3_CDN_URL="s3://cdn-${ENV}.hana053.com"
16-
if [ "${ENV}" = "prod" ]; then
17-
MAIN_URL="https://micropost.hana053.com"
18-
else
19-
MAIN_URL="https://micropost-${ENV}.hana053.com"
20-
fi
2112

2213
# build
2314
PUBLIC_PATH=${CDN_URL} yarn run build:prod
@@ -32,4 +23,3 @@ aws s3 sync --delete --acl public-read dist ${S3_CDN_URL}
3223
aws deploy create-deployment --application-name micropost \
3324
--s3-location bucket=cdn-${ENV}.hana053.com,key=codedeploy.tgz,bundleType=tgz \
3425
--deployment-group-name web-frontend
35-

scripts/switch-production-role.sh

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

scripts/switch-role.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Parse variable such as ROLE_ARN_stg, ROLE_ARN_prod and etc.
4+
ROLE_ARN=$(eval echo '$ROLE_ARN_'${ENV})
5+
6+
CREDENTIALS=$(aws sts assume-role --role-arn ${ROLE_ARN} --role-session-name travisci)
7+
8+
export AWS_ACCESS_KEY_ID=$(echo ${CREDENTIALS} | jq --raw-output .Credentials.AccessKeyId)
9+
export AWS_SECRET_ACCESS_KEY=$(echo ${CREDENTIALS} | jq --raw-output .Credentials.SecretAccessKey)
10+
export AWS_SESSION_TOKEN=$(echo ${CREDENTIALS} | jq --raw-output .Credentials.SessionToken)

0 commit comments

Comments
 (0)