Skip to content

Commit 7ba2d3f

Browse files
authored
Merge pull request #26 from Clever/dapple-envs-and-deploy-strategies
dapple-deploy: allow passing env and deploy strategy
2 parents 6e87dfa + 1172a35 commit 7ba2d3f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

circleci/dapple-deploy

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Usage:
66
#
7-
# dapple-deploy [DAPPLE_URL] [DAPPLE_USER] [DAPPLE_PASS] [APP_NAME]
7+
# dapple-deploy [DAPPLE_URL] [DAPPLE_USER] [DAPPLE_PASS] [APP_NAME] [[DEPLOY_ENV] [DEPLOY_STRATEGY]]
88
#
99
# Required circleci provided environment variables:
1010
#
@@ -15,9 +15,9 @@
1515

1616
set -e
1717

18-
if [ $# -ne 4 ]; then
19-
echo "Incorrect number of arguments given. Expected 4, received $#"
20-
echo "Usage: dapple-deploy [DAPPLE_URL] [DAPPLE_USER] [DAPPLE_PASS] [APP_NAME]"
18+
if [ $# -ne 4 ] && [ $# -ne 5 ] && [ $# -ne 6 ]; then
19+
echo "Incorrect number of arguments given. Expected at least 4, received $#"
20+
echo "Usage: dapple-deploy [DAPPLE_URL] [DAPPLE_USER] [DAPPLE_PASS] [APP_NAME] [[DEPLOY_ENV] [DEPLOY_STRATEGY]]"
2121
exit 1
2222
fi
2323

@@ -26,6 +26,9 @@ DAPPLE_URL=$1
2626
DAPPLE_USER=$2
2727
DAPPLE_PASS=$3
2828
APP_NAME=$4
29+
# deploy env and deploy strategy get default values, if not specified
30+
DEPLOY_ENV=${5:-clever-dev}
31+
DEPLOY_STRATEGY=${6:-confirm-then-deploy}
2932

3033
# Set automatically by CircleCI
3134
: ${CIRCLE_PROJECT_REPONAME?"Missing required env var"}
@@ -34,14 +37,26 @@ REPO=$CIRCLE_PROJECT_REPONAME
3437
USER=$CIRCLE_PROJECT_USERNAME
3538
: ${CIRCLE_BUILD_NUM?"Missing required env var"}
3639
BUILD_NUM=$CIRCLE_BUILD_NUM
40+
BRANCH=$CIRCLE_BRANCH
41+
42+
# Safety Checks
43+
if [ "$DEPLOY_ENV" = "production" -a "$BRANCH" != "master" ]; then
44+
echo "ERROR: Cannot publish into production from a non-master branch"
45+
exit 1
46+
fi
47+
48+
if [ "$DEPLOY_ENV" != "production" -a "$DEPLOY_ENV" != "clever-dev" -a "$DEPLOY_ENV" != "dev-infra" ]; then
49+
echo "ERROR: Only 'production', 'clever-dev', and 'dev-infra' are supported deployment environments"
50+
exit 1
51+
fi
3752

3853
echo "Publishing to dapple..."
3954
SC=$(curl -u $DAPPLE_USER:$DAPPLE_PASS \
4055
-w "%{http_code}" \
4156
--output dapple.out \
4257
-H "Content-Type: application/json" \
4358
-X POST \
44-
-d "{\"username\":\"$USER\",\"reponame\":\"$REPO\",\"buildnum\":$BUILD_NUM,\"appname\":\"$APP_NAME\"}" \
59+
-d "{\"username\":\"$USER\",\"reponame\":\"$REPO\",\"buildnum\":$BUILD_NUM,\"appname\":\"$APP_NAME\",\"environment\":\"$DEPLOY_ENV\",\"strategy\":\"$DEPLOY_STRATEGY\"}" \
4560
$DAPPLE_URL)
4661

4762
if [ "$SC" -eq 200 ]; then

0 commit comments

Comments
 (0)