From bd633ff7ce54b6fec07c272ea4b1a322cd0e0f4b Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Mon, 22 May 2017 08:15:53 -0700 Subject: [PATCH 01/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 360aa5f..c8216ca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Triton Docker CLI helper -This script installs known-good, tested versions of the Docker (now Moby) and Docker Compose CLI tools for use with Triton. +This script installs known good, tested versions of the Docker (now Moby) and Docker Compose CLI tools for use with Triton. Additionally, this script will automatically configure those tools for use with Triton when you use them, making it easy to switch between Docker on your laptop and Docker on Triton. @@ -8,7 +8,7 @@ Additionally, this script will automatically configure those tools for use with This is designed and tested for Linux and MacOS X. -This code also requires [the Triton CLI tools](https://docs.joyent.com/public-cloud/api-access/cloudapi) and [a Triton account](https://docs.joyent.com/public-cloud/getting-started) on either the Triton Public Cloud (Joyent public cloud) or in a private cloud powered by Triton. +This code also requires [the Triton CLI tools](https://docs.joyent.com/public-cloud/api-access/cloudapi) and [a Triton account](https://docs.joyent.com/public-cloud/getting-started) on either Triton public cloud (Joyent public cloud) or in a private cloud powered by Triton. Use of this software also requires [a Triton profile configured in the Triton CLI tool](https://docs.joyent.com/public-cloud/api-access/cloudapi#configuration). From 677fdca805bc4648c776279e7c2ad8ffcea1193b Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 08:47:24 -0700 Subject: [PATCH 02/12] add option to show profile don't show profile by default --- triton-docker | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) mode change 100644 => 100755 triton-docker diff --git a/triton-docker b/triton-docker old mode 100644 new mode 100755 index f79c962..d09a800 --- a/triton-docker +++ b/triton-docker @@ -23,7 +23,7 @@ function currentProfile () { local profile_source='default; use `triton profile set ` to change' fi - echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source}) at $(date +'%r')" + echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source})" } # Check if the Docker binary (named triton-docker-helper) @@ -74,10 +74,17 @@ function install () { # Run all checks function checkAll () { checkTritonInstalled && - checkDockerInstalled && - currentProfile + checkDockerInstalled } +# Special case handling if the sub-command is `profile` +if [ "profile" == "$1" ] +then + currentProfile + exit 1 +fi + +# Change behavior based on the calling name of this executable case "`basename $0`" in triton-docker) checkAll && From c71f61589e86756da8623d138dffe10523303e9f Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 08:56:47 -0700 Subject: [PATCH 03/12] execute in subshell --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8216ca..7b76619 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Use of this software also requires [a Triton profile configured in the Triton CL In a terminal window, run the following command: ```bash -sudo curl -o /usr/local/bin/triton-docker https://raw.githubusercontent.com/joyent/triton-docker-cli/master/triton-docker && chmod +x /usr/local/bin/triton-docker && ln -Fs /usr/local/bin/triton-docker /usr/local/bin/triton-compose && ln -Fs /usr/local/bin/triton-docker /usr/local/bin/triton-docker-install +sudo bash -c 'curl -o /usr/local/bin/triton-docker https://raw.githubusercontent.com/joyent/triton-docker-cli/master/triton-docker && chmod +x /usr/local/bin/triton-docker && ln -Fs /usr/local/bin/triton-docker /usr/local/bin/triton-compose && ln -Fs /usr/local/bin/triton-docker /usr/local/bin/triton-docker-install' ``` That command will copy the `triton-docker` shell script from this repo, and link it as `triton-compose` and `triton-docker-install`. From f5f02cb1e92abc8284b6ffae29f31c389a4e2baf Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 09:12:45 -0700 Subject: [PATCH 04/12] shellcheck improvements --- triton-docker | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/triton-docker b/triton-docker index d09a800..4cdea60 100755 --- a/triton-docker +++ b/triton-docker @@ -32,10 +32,10 @@ function checkDockerInstalled () { if [ ! -f /usr/local/bin/triton-docker-helper ] || [ ! -x /usr/local/bin/triton-docker-helper ] || - [ "${triton_docker_version}," != $(/usr/local/bin/triton-docker-helper -v | awk '{print $3}') ] || + [ "${triton_docker_version}," != "$(/usr/local/bin/triton-docker-helper -v | awk '{print $3}')" ] || [ ! -f /usr/local/bin/triton-compose-helper ] || [ ! -x /usr/local/bin/triton-compose-helper ] || - [ "${triton_compose_version}," != $(/usr/local/bin/triton-compose-helper -v | awk '{print $3}') ] + [ "${triton_compose_version}," != "$(/usr/local/bin/triton-compose-helper -v | awk '{print $3}')" ] then echo 'Additional or updated components are required.' echo 'Please run `sudo triton-docker-install` to continue.' @@ -55,7 +55,7 @@ function install () { # Install the specific version of Docker for Triton rm -Rf /tmp/triton-docker /usr/local/bin/triton-docker-helper mkdir -p /tmp/triton-docker - curl https://get.docker.com/builds/$(uname -a | awk '{ print $1 }')/x86_64/docker-${triton_docker_version}.tgz | tar zxvf - -C /tmp/triton-docker + curl https://get.docker.com/builds/"$(uname -a | awk '{ print $1 }')"/x86_64/docker-${triton_docker_version}.tgz | tar zxvf - -C /tmp/triton-docker mv /tmp/triton-docker/docker/docker /usr/local/bin/triton-docker-helper rm -Rf /tmp/triton-docker chmod +x /usr/local/bin/triton-docker-helper @@ -64,7 +64,7 @@ function install () { echo # Install the specific version of Docker Compose for Triton - curl -Lo /usr/local/bin/triton-compose-helper https://github.com/docker/compose/releases/download/${triton_compose_version}/docker-compose-$(uname -a | awk '{ print $1 }')-x86_64 + curl -Lo /usr/local/bin/triton-compose-helper https://github.com/docker/compose/releases/download/${triton_compose_version}/docker-compose-"$(uname -a | awk '{ print $1 }')"-x86_64 chmod +x /usr/local/bin/triton-compose-helper echo "The triton-compose-helper is now installed." @@ -85,7 +85,7 @@ then fi # Change behavior based on the calling name of this executable -case "`basename $0`" in +case "$(basename $0)" in triton-docker) checkAll && eval "$(triton env)" && From 15c72d38c6b3a6cdd6618e029221db206c6f0dda Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 09:46:34 -0700 Subject: [PATCH 05/12] add extra env vars for CNS --- triton-docker | 60 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/triton-docker b/triton-docker index 4cdea60..6523e5f 100755 --- a/triton-docker +++ b/triton-docker @@ -14,18 +14,6 @@ function checkCurlInstalled () { command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required to complete this installation. Please install before continuing."; exit 1; } } -# Emit the current Triton profile and time -function currentProfile () { - if [ -n "$TRITON_PROFILE" ] - then - local profile_source='via env var; use `eval "$(triton env )"` to change' - else - local profile_source='default; use `triton profile set ` to change' - fi - - echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source})" -} - # Check if the Docker binary (named triton-docker-helper) # and Docker Compose (named triton-compose-helper) are installed and executable function checkDockerInstalled () { @@ -71,6 +59,52 @@ function install () { echo } +# Emit the current Triton profile and time +function currentProfile () { + if [ -n "$TRITON_PROFILE" ] + then + local profile_source='via env var; use `eval "$(triton env )"` to change' + else + local profile_source='default; use `triton profile set ` to change' + fi + + echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source})" +} + +# Extra env vars +function extraEnvVars () { + + # Get the user's UUID and current data center name + local triton_account="$(triton account get)" + export TRITON_ACCOUNT_UUID="$(echo "$triton_account" | awk -F": " '/id:/{print $2}')" + export TRITON_DC="$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}')" + + # Set the CNS base for public and private names + if [ ! -n "$TRITON_CNS_SUFFIX_PUBLIC" ] + then + export TRITON_CNS_SUFFIX_PUBLIC="${TRITON_ACCOUNT}.${TRITON_DC}.triton.zone" + fi + if [ ! -n "$TRITON_CNS_SUFFIX_PRIVATE" ] + then + export TRITON_CNS_SUFFIX_PRIVATE="${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com" + fi + + # Check if CNS is enabled, require it + local triton_cns_enabled="$(echo "$triton_account" | awk -F": " '/cns/{print $2}')" + if [ ! "true" == "$triton_cns_enabled" ]; then + echo + tput rev # reverse + tput bold # bold + echo 'Error! Triton CNS is required and not enabled.' + tput sgr0 # clear + echo + echo 'Please run:' + echo ' triton account update triton_cns_enabled=true' + echo + exit 1 + fi +} + # Run all checks function checkAll () { checkTritonInstalled && @@ -89,12 +123,14 @@ case "$(basename $0)" in triton-docker) checkAll && eval "$(triton env)" && + extraEnvVars && exec /usr/local/bin/triton-docker-helper $@ ;; triton-compose) checkAll && eval "$(triton env)" && export COMPOSE_HTTP_TIMEOUT=750 && + extraEnvVars && exec /usr/local/bin/triton-compose-helper $@ ;; triton-docker-install) From e4a13854391a9c9f1d045d42461df79e67def444 Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 10:17:19 -0700 Subject: [PATCH 06/12] refactor It seemed wise to expose only the CNS variables that were most relevant --- triton-docker | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/triton-docker b/triton-docker index 6523e5f..1278c27 100755 --- a/triton-docker +++ b/triton-docker @@ -74,20 +74,14 @@ function currentProfile () { # Extra env vars function extraEnvVars () { - # Get the user's UUID and current data center name - local triton_account="$(triton account get)" - export TRITON_ACCOUNT_UUID="$(echo "$triton_account" | awk -F": " '/id:/{print $2}')" - export TRITON_DC="$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}')" + # If the CNS env vars are already set, don't bother continuing + if [ -n "$TRITON_CNS_SUFFIX_PUBLIC" ] && [ -n "$TRITON_CNS_SUFFIX_PRIVATE" ] + then + return + fi - # Set the CNS base for public and private names - if [ ! -n "$TRITON_CNS_SUFFIX_PUBLIC" ] - then - export TRITON_CNS_SUFFIX_PUBLIC="${TRITON_ACCOUNT}.${TRITON_DC}.triton.zone" - fi - if [ ! -n "$TRITON_CNS_SUFFIX_PRIVATE" ] - then - export TRITON_CNS_SUFFIX_PRIVATE="${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com" - fi + # Get and the user's account information for parsing later + local triton_account="$(triton account get)" # Check if CNS is enabled, require it local triton_cns_enabled="$(echo "$triton_account" | awk -F": " '/cns/{print $2}')" @@ -103,6 +97,18 @@ function extraEnvVars () { echo exit 1 fi + + # Get the user's UUID + local triton_account_uuid="$(echo "$triton_account" | awk -F": " '/id:/{print $2}')" + + # Get current data center name + # Note: this makes assumptions that work in our public cloud, but might not work elsewhere + # Further note: set TRITON_CNS_SUFFIX_PUBLIC and TRITON_CNS_SUFFIX_PRIVATE to work around this + local triton_dc="$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}')" + + # Set the CNS base for public and private names + export TRITON_CNS_SUFFIX_PUBLIC="${triton_account_uuid}.${triton_dc}.triton.zone" + export TRITON_CNS_SUFFIX_PRIVATE="${triton_account_uuid}.${triton_dc}.cns.joyent.com" } # Run all checks From 9ee8085ad76e336521dccdb270fc58b6c91aab38 Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 13:25:04 -0700 Subject: [PATCH 07/12] be clear that this only works on TPC Rename env vars set -o pipefail --- README.md | 20 ++++++++++++++++++++ triton-docker | 34 +++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7b76619..2039907 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,26 @@ More about: - [Docker Compose on Triton](https://www.joyent.com/blog/using-docker-compose) - [Optimizing your Docker operations for Triton](https://www.joyent.com/blog/optimizing-docker-on-triton) +### Triton Container Name Service helpers + +This will also set some helpful environment variables for using [Triton Container Name Service (CNS)](https://docs.joyent.com/public-cloud/network/cns): + +- `TRITON_CNS_SEARCH_DOMAIN_PUBLIC` +- `TRITON_CNS_SEARCH_DOMAIN_PRIVATE` + +Those vars will be automatically set with values appropriate for use in Triton Public Cloud: + +``` +TRITON_CNS_SEARCH_DOMAIN_PRIVATE=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3.cns.joyent.com +TRITON_CNS_SEARCH_DOMAIN_PUBLIC=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3.triton.zone +``` + +#### Notes and cautions + +- The mechanism that sets these environment vars only works for Triton Public Cloud. To use Triton Docker CLI with private cloud implementations of Triton, please set the `TRITON_CNS_SEARCH_DOMAIN_PUBLIC` and `TRITON_CNS_SEARCH_DOMAIN_PRIVATE` vars manually +- These environment variables will be removed following the completion of CNS-164 and [DOCKER-898](https://smartos.org/bugview/DOCKER-898), which will automatically set the DNS search domain to these values +- CNS-164 and [DOCKER-898](https://smartos.org/bugview/DOCKER-898) will also work on private cloud implementations of Triton, solving the problem for everybody + ### Components In addition to the shell script in this repo, this script will install: diff --git a/triton-docker b/triton-docker index 1278c27..cf58c4e 100755 --- a/triton-docker +++ b/triton-docker @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -e -o pipefail triton_docker_version=1.12.6 triton_compose_version=1.9.0 @@ -71,21 +71,29 @@ function currentProfile () { echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source})" } -# Extra env vars -function extraEnvVars () { +# Set env vars to make using CNS easier +function CnsEnvVars () { # If the CNS env vars are already set, don't bother continuing - if [ -n "$TRITON_CNS_SUFFIX_PUBLIC" ] && [ -n "$TRITON_CNS_SUFFIX_PRIVATE" ] + if [ -n "$TRITON_CNS_SEARCH_DOMAIN_PUBLIC" ] && [ -n "$TRITON_CNS_SEARCH_DOMAIN_PRIVATE" ] then return fi - # Get and the user's account information for parsing later + # Get and the user's account information and CloudAPI URL for parsing later local triton_account="$(triton account get)" + local triton_url="$(triton profile get | awk -F"/" '/url:/{print $3}')" + + # Do not continue if the target is not a Triton Public Cloud data center + if [ ! "api.joyent.com" == "$(echo "${triton_url}" | awk -F'.' '{print $2 "." $3 "." $4}')" ] + then + return + fi # Check if CNS is enabled, require it - local triton_cns_enabled="$(echo "$triton_account" | awk -F": " '/cns/{print $2}')" - if [ ! "true" == "$triton_cns_enabled" ]; then + local triton_cns_enabled="$(echo "${triton_account}" | awk -F": " '/cns/{print $2}')" + if [ ! "true" == "$triton_cns_enabled" ] + then echo tput rev # reverse tput bold # bold @@ -99,16 +107,16 @@ function extraEnvVars () { fi # Get the user's UUID - local triton_account_uuid="$(echo "$triton_account" | awk -F": " '/id:/{print $2}')" + local triton_account_uuid="$(echo "${triton_account}" | awk -F": " '/id:/{print $2}')" # Get current data center name # Note: this makes assumptions that work in our public cloud, but might not work elsewhere # Further note: set TRITON_CNS_SUFFIX_PUBLIC and TRITON_CNS_SUFFIX_PRIVATE to work around this - local triton_dc="$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}')" + local triton_dc="$(echo "${triton_url}" | awk -F'.' '{print $1}')" # Set the CNS base for public and private names - export TRITON_CNS_SUFFIX_PUBLIC="${triton_account_uuid}.${triton_dc}.triton.zone" - export TRITON_CNS_SUFFIX_PRIVATE="${triton_account_uuid}.${triton_dc}.cns.joyent.com" + export TRITON_CNS_SEARCH_DOMAIN_PUBLIC="${triton_account_uuid}.${triton_dc}.triton.zone" + export TRITON_CNS_SEARCH_DOMAIN_PRIVATE="${triton_account_uuid}.${triton_dc}.cns.joyent.com" } # Run all checks @@ -129,14 +137,14 @@ case "$(basename $0)" in triton-docker) checkAll && eval "$(triton env)" && - extraEnvVars && + CnsEnvVars && exec /usr/local/bin/triton-docker-helper $@ ;; triton-compose) checkAll && eval "$(triton env)" && export COMPOSE_HTTP_TIMEOUT=750 && - extraEnvVars && + CnsEnvVars && exec /usr/local/bin/triton-compose-helper $@ ;; triton-docker-install) From 7ff1b5ba1400a8ef6ace731f53666e3e27e6c92c Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 13:31:37 -0700 Subject: [PATCH 08/12] clarify what the notes and cautions are about --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2039907..b867b72 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ TRITON_CNS_SEARCH_DOMAIN_PRIVATE=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3. TRITON_CNS_SEARCH_DOMAIN_PUBLIC=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3.triton.zone ``` -#### Notes and cautions +#### Notes and cautions about CNS env vars - The mechanism that sets these environment vars only works for Triton Public Cloud. To use Triton Docker CLI with private cloud implementations of Triton, please set the `TRITON_CNS_SEARCH_DOMAIN_PUBLIC` and `TRITON_CNS_SEARCH_DOMAIN_PRIVATE` vars manually - These environment variables will be removed following the completion of CNS-164 and [DOCKER-898](https://smartos.org/bugview/DOCKER-898), which will automatically set the DNS search domain to these values From 0921d23decfc8e16676200db59a2a60c34721b2a Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 14:01:54 -0700 Subject: [PATCH 09/12] add cns-164 links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b867b72..b090a18 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,8 @@ TRITON_CNS_SEARCH_DOMAIN_PUBLIC=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3.t #### Notes and cautions about CNS env vars - The mechanism that sets these environment vars only works for Triton Public Cloud. To use Triton Docker CLI with private cloud implementations of Triton, please set the `TRITON_CNS_SEARCH_DOMAIN_PUBLIC` and `TRITON_CNS_SEARCH_DOMAIN_PRIVATE` vars manually -- These environment variables will be removed following the completion of CNS-164 and [DOCKER-898](https://smartos.org/bugview/DOCKER-898), which will automatically set the DNS search domain to these values -- CNS-164 and [DOCKER-898](https://smartos.org/bugview/DOCKER-898) will also work on private cloud implementations of Triton, solving the problem for everybody +- These environment variables will be removed following the completion of [CNS-164](https://smartos.org/bugview/CNS-164) and [DOCKER-898](https://smartos.org/bugview/DOCKER-898), which will automatically set the DNS search domain to these values +- [CNS-164](https://smartos.org/bugview/CNS-164) and [DOCKER-898](https://smartos.org/bugview/DOCKER-898) will also work on private cloud implementations of Triton, solving the problem for everybody ### Components From dd886215e7d65f8c60a0f5a11dd60b751bdda55b Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 14:20:37 -0700 Subject: [PATCH 10/12] fix nits --- triton-docker | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/triton-docker b/triton-docker index cf58c4e..5123e75 100755 --- a/triton-docker +++ b/triton-docker @@ -72,7 +72,7 @@ function currentProfile () { } # Set env vars to make using CNS easier -function CnsEnvVars () { +function cnsEnvVars () { # If the CNS env vars are already set, don't bother continuing if [ -n "$TRITON_CNS_SEARCH_DOMAIN_PUBLIC" ] && [ -n "$TRITON_CNS_SEARCH_DOMAIN_PRIVATE" ] @@ -85,7 +85,7 @@ function CnsEnvVars () { local triton_url="$(triton profile get | awk -F"/" '/url:/{print $3}')" # Do not continue if the target is not a Triton Public Cloud data center - if [ ! "api.joyent.com" == "$(echo "${triton_url}" | awk -F'.' '{print $2 "." $3 "." $4}')" ] + if [ ! ".api.joyent.com" == "${triton_url: -15}" ] then return fi @@ -137,14 +137,14 @@ case "$(basename $0)" in triton-docker) checkAll && eval "$(triton env)" && - CnsEnvVars && + cnsEnvVars && exec /usr/local/bin/triton-docker-helper $@ ;; triton-compose) checkAll && eval "$(triton env)" && export COMPOSE_HTTP_TIMEOUT=750 && - CnsEnvVars && + cnsEnvVars && exec /usr/local/bin/triton-compose-helper $@ ;; triton-docker-install) From f320fb47998f5ac79b11fcfe9b400d2f9b020220 Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 14:42:16 -0700 Subject: [PATCH 11/12] don't exit if CNS is disabled --- triton-docker | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/triton-docker b/triton-docker index 5123e75..d5df59e 100755 --- a/triton-docker +++ b/triton-docker @@ -68,7 +68,24 @@ function currentProfile () { local profile_source='default; use `triton profile set ` to change' fi - echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source})" + # Get and the user's account information and CloudAPI URL for parsing later + local triton_account="$(triton account get)" + + echo "Executing in '$(echo "${triton_account}" | awk 'NR == 1 {print $2}')' (${profile_source})" + + # Check if CNS is enabled, require it + if [ ! "true" == "$(echo "${triton_account}" | awk -F": " '/cns/{print $2}')" ] + then + echo + tput rev # reverse + tput bold # bold + echo 'Error! Triton CNS is not enabled.' + tput sgr0 # clear + echo + echo 'Please run the following to activate:' + echo ' triton account update triton_cns_enabled=true' + echo + fi } # Set env vars to make using CNS easier @@ -90,22 +107,6 @@ function cnsEnvVars () { return fi - # Check if CNS is enabled, require it - local triton_cns_enabled="$(echo "${triton_account}" | awk -F": " '/cns/{print $2}')" - if [ ! "true" == "$triton_cns_enabled" ] - then - echo - tput rev # reverse - tput bold # bold - echo 'Error! Triton CNS is required and not enabled.' - tput sgr0 # clear - echo - echo 'Please run:' - echo ' triton account update triton_cns_enabled=true' - echo - exit 1 - fi - # Get the user's UUID local triton_account_uuid="$(echo "${triton_account}" | awk -F": " '/id:/{print $2}')" @@ -115,6 +116,7 @@ function cnsEnvVars () { local triton_dc="$(echo "${triton_url}" | awk -F'.' '{print $1}')" # Set the CNS base for public and private names + # Note, this also makes assumptions that only work in our public cloud export TRITON_CNS_SEARCH_DOMAIN_PUBLIC="${triton_account_uuid}.${triton_dc}.triton.zone" export TRITON_CNS_SEARCH_DOMAIN_PRIVATE="${triton_account_uuid}.${triton_dc}.cns.joyent.com" } From f265bb9b5801f1d4c4da8a4cff2000b3a9fd9695 Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Sat, 3 Jun 2017 08:58:09 -0700 Subject: [PATCH 12/12] nits --- triton-docker | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/triton-docker b/triton-docker index d5df59e..9fd8f94 100755 --- a/triton-docker +++ b/triton-docker @@ -74,12 +74,12 @@ function currentProfile () { echo "Executing in '$(echo "${triton_account}" | awk 'NR == 1 {print $2}')' (${profile_source})" # Check if CNS is enabled, require it - if [ ! "true" == "$(echo "${triton_account}" | awk -F": " '/cns/{print $2}')" ] + if [ ! "true" == "$(echo "${triton_account}" | awk -F": " '/^triton_cns_enabled:/{print $2}')" ] then echo tput rev # reverse tput bold # bold - echo 'Error! Triton CNS is not enabled.' + echo 'Warning! Triton CNS is not enabled.' tput sgr0 # clear echo echo 'Please run the following to activate:' @@ -108,7 +108,7 @@ function cnsEnvVars () { fi # Get the user's UUID - local triton_account_uuid="$(echo "${triton_account}" | awk -F": " '/id:/{print $2}')" + local triton_account_uuid="$(echo "${triton_account}" | awk -F": " '/^id:/{print $2}')" # Get current data center name # Note: this makes assumptions that work in our public cloud, but might not work elsewhere