From 9ee8085ad76e336521dccdb270fc58b6c91aab38 Mon Sep 17 00:00:00 2001 From: Casey Bisson Date: Fri, 2 Jun 2017 13:25:04 -0700 Subject: [PATCH] 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)