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#
1515
1616set -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
2222fi
2323
@@ -26,6 +26,9 @@ DAPPLE_URL=$1
2626DAPPLE_USER=$2
2727DAPPLE_PASS=$3
2828APP_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
3437USER=$CIRCLE_PROJECT_USERNAME
3538: ${CIRCLE_BUILD_NUM?" Missing required env var" }
3639BUILD_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
3853echo " Publishing to dapple..."
3954SC=$( 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
4762if [ " $SC " -eq 200 ]; then
0 commit comments