Last active
February 12, 2018 17:21
-
-
Save pjcdawkins/95276fdc793b3254f18e103595c45477 to your computer and use it in GitHub Desktop.
Get a production CNAME for a Platform.sh project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e -o pipefail | |
project=${1:-$(platform project:info id)} | |
default_route='https://{default}/' | |
route=${2:-$default_route} | |
prod='master' | |
other='' | |
# Find an active environment that isn't master. | |
if [ -z "$other" ] || [ "$other" = "$prod" ]; then | |
other=$(platform environment:list -p "$project" --no-inactive --pipe | grep -v "$prod" | head -n1 || true) | |
[ -z "$other" ] && echo "Failed to find an active environment that is not: $prod" && exit 1 | |
fi | |
# Find the URL of the $other environment. | |
url=$(platform route:get -p "$project" -e "$other" "$route" -P url) | |
# Find the machine name of the $other environment. | |
other_machine_name=$(platform environment:info machine_name -p "$project" -e "$other") | |
# Find the machine name of the $prod environment. | |
prod_machine_name=$(platform environment:info machine_name -p "$project" -e "$prod") | |
# Get the hostname of the URL. | |
host=$(echo "$url" | sed "s#https*://##;" | cut -d/ -f1) | |
[ -z "$host" ] && echo "Failed to find hostname for URL: $url" && exit 1 | |
# Replace the $other machine name with the $prod machine name in the URL. | |
echo "$host" | sed "s#${other_machine_name}#${prod_machine_name}#" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment