Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USAGOV-1779: add script to create domain services for www and cms with appropriate plans #2111

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions bin/cloudgov/create-domain-services-for-space
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

# Create the domains and domain services for the "cms" and "www" hosts in one of these spaces:
# - dev
# - dr
# - stage
# - prod
#
# This is a one-time operation we would need to do when re-creating a space.
# NB: the DNS records for the domain must already be set up, including the _acme-challenge
# records, as described at https://cloud.gov/docs/services/external-domain-service/#how-to-create-an-instance-of-this-service


# we might be running in circleci
if [ -f /home/circleci/project/env.local ]; then
. /home/circleci/project/env.local
fi
# we might be running from a local dev machine
SCRIPT_DIR="$(dirname "$0")"
if [ -f $SCRIPT_DIR/env.local ]; then
. $SCRIPT_DIR/env.local
fi
if [ -f ./env.local ]; then
. ./env.local
fi
if [ -f $SCRIPT_DIR/../deploy/includes ]; then
. $SCRIPT_DIR/../deploy/includes
else
echo Cannot find $SCRIPT_DIR/../deploy/includes
exit 1
fi

# just testing?
if [ x$1 = x"--dryrun" ]; then
export echo=echo
shift
fi

SPACE=${1:-please-provide-space-name-as-first-argument}
SPACE=$(echo "$SPACE" | tr '[:upper:]' '[:lower:]')
assertCurSpace $SPACE

ORG=$(getOrg)

# -p domain-with-cdn-dedicated-waf -c '{"alarm_notification_email": "[email protected]"}'
CMS_DOMAIN="cms-${SPACE}.usa.gov"
WWW_DOMAIN="beta-${SPACE}.usa.gov"
WWW_DOMAIN_PLAN="domain-with-cdn-dedicated-waf"
if [ ${SPACE} = 'prod' ]; then
CMS_DOMAIN="cms.usa.gov"
WWW_DOMAIN="www.usa.gov"
fi

# dev and dr are restricted to the GSA network, so a cloudfront CDN isn't appropriate
if [ ${SPACE} = 'dev' ]; then
WWW_DOMAIN_PLAN="domain"
fi
if [ ${SPACE} = 'dr' ]; then
WWW_DOMAIN_PLAN="domain"
fi

echo "Creating domains ${CMS_DOMAIN} and ${WWW_DOMAIN}"
$echo cf create-domain $ORG $CMS_DOMAIN
$echo cf create-domain $ORG $WWW_DOMAIN

echo
echo "Creating external domain services. Each of these could take awhile to come up."

# Passing JSON to this command inline works on the command line, but not when it is
# called from the shell (why?). So we create a file and pass that instead.
tmpfile=$(mktemp)
domainjson=`printf "{\"domains\": \"%s\"}" ${CMS_DOMAIN}`
echo $domainjson > $tmpfile

echo cf create-service external-domain domain ${SPACE}-cms-usagov-domain -c $tmpfile
$echo cf create-service external-domain domain ${SPACE}-cms-usagov-domain -c $tmpfile

if [ ${WWW_DOMAIN_PLAN} = "domain" ]; then
domainjson=`printf "{\"domains\": \"%s\"}" ${WWW_DOMAIN}`
else
domainjson=`printf "{\"domains\": \"%s\", \"alarm_notification_email\": \"[email protected]\"}" ${WWW_DOMAIN}`
fi
echo $domainjson > $tmpfile
echo cf create-service external-domain domain-with-cdn ${SPACE}-www-usagov-domain -c $tmpfile
$echo cf create-service external-domain domain-with-cdn ${SPACE}-www-usagov-domain -c $tmpfile

rm $tmpfile
# The above commands output a message saying how to check them, so we don't need to explain further.
8 changes: 0 additions & 8 deletions bin/cloudgov/deploy-waf
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ SPACE=$( cf target | grep space: | awk '{ print $2 }')
# The Image digest for this tag should be looked up from cloud.gov storage
# Any tag with a stored Image digest should be referenced by hash instead of tag

# Need to create 'external-domain' service for custom routes: *.usa.gov
# cf delete-service dev-usagov-domain
# cf create-service external-domain domain dev-usagov-domain -c '{"domains": "cms-dev.usa.gov,beta-dev.usa.gov"}'
# cf create-service external-domain domain-with-cdn stage-usagov-domain -c '{"domains": "cms-stage.usa.gov,beta-stage.usa.gov"}'
# cf create-service external-domain domain-with-cdn prod-www-usagov-domain -c '{"domains": "beta.usa.gov"}'
# cf create-service external-domain domain prod-cms-usagov-domain -c '{"domains": "cms.usa.gov"}'
# cf service prod-cms-usagov-domain

if ! command -v jq >/dev/null; then
printf "\nMust have JQ installed\n"
exit 1
Expand Down
Loading