Compare commits

..

No commits in common. "master" and "fix-18-triton-docker-profile" have entirely different histories.

3 changed files with 184 additions and 173 deletions

View File

@ -1,45 +1,47 @@
# Spearhead Docker CLI helper
# Triton Docker CLI helper
This script will install compatible Docker versions for use with the Spearhead Cloud.
This script installs known good, tested versions of the Docker (now Moby) and Docker Compose CLI tools for use with Triton.
Your existing Docker will not be affected and you can conveniently switch between your own Docker and the Spearhead Cloud docker tools.
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.
### Compatibility and requirements
This is designed and tested for Linux and MacOS X.
This code requires [Spearhead Cloud CLI tool](https://code.spearhead.cloud/Spearhead/node-spearhead) and [a Spearhead Cloud account](https://docs.spearhead.cloud/start/).
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).
### Installation
In a terminal window, run the following command:
```bash
sudo bash -c 'curl -o /usr/local/bin/spearhead-docker https://code.spearhead.cloud/Spearhead/spearhead-docker-cli/raw/branch/master/spearhead-docker && chmod +x /usr/local/bin/spearhead-docker && ln -Fs /usr/local/bin/spearhead-docker /usr/local/bin/spearhead-compose && ln -Fs /usr/local/bin/spearhead-docker /usr/local/bin/spearheadn-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 `spearhead-docker` shell script from this repo, and link it as `spearhead-compose` and `spearhead-docker-install`.
That command will copy the `triton-docker` shell script from this repo, and link it as `triton-compose` and `triton-docker-install`.
To complete the installation, run `sudo spearhead-docker-install` to install the platform-specific versions of the Docker (now Moby) and Docker Compose CLI tools. These versions will not replace any existing Docker or Docker Compose versions you may have installed.
To complete the installation, run `sudo triton-docker-install` to install the platform-specific versions of the Docker (now Moby) and Docker Compose CLI tools. These versions will not replace any existing Docker or Docker Compose versions you may have installed.
### Usage
Once installed, use `spearhead-docker` and `spearhead-compose` in place of `docker` and `docker-compose` when interacting with the Spearhead Cloud.
Once installed, use `triton-docker` and `triton-compose` in place of `docker` and `docker-compose` when interacting with the Triton Elastic Docker Host.
Start a Docker container running Nginx container on Spearhead Cloud:
Start a Docker container running Nginx container on Triton:
```bash
$ spearhead-docker run -d -p 80 --name webserver nginx
Executing in 'ro-1' (default; use `spearhead profile set <profile name>` to change) at 05:02:41 AM
x5gso83h9365831psn43h7qwuc3115f9fitff59b2151694a963043sue94k2f73
$ triton-docker run -d -p 80 --name webserver nginx
Executing in 'us-sw-1' (default; use `triton profile set <profile name>` to change) at 03:11:11 PM
d5cae48b0072610ecc67f6aecb3115f9fadff59b2151694a963084dad40e5d85
$
```
Start [all the containers to run WordPress](https://github.com/autopilotpattern/wordpress) via Docker Compose on Spearhead Cloud:
Start [all the containers to run WordPress](https://github.com/autopilotpattern/wordpress) via Docker Compose on Triton:
```bash
$ spearhead-compose up -d
Executing in 'ro-1' (default; use `spearhead profile set <profile name>` to change) at 03:15:56 PM
$ triton-compose up -d
Executing in 'us-sw-1' (default; use `triton profile set <profile name>` to change) at 03:15:56 PM
Creating wp_wordpress_1
Creating wp_nginx_1
Creating wp_nfs_1
@ -60,19 +62,25 @@ More about:
This will also set some helpful environment variables for using [Triton Container Name Service (CNS)](https://docs.joyent.com/public-cloud/network/cns):
- `SC_CNS_SEARCH_DOMAIN_PUBLIC`
- `SC_CNS_SEARCH_DOMAIN_PRIVATE`
- `TRITON_CNS_SEARCH_DOMAIN_PUBLIC`
- `TRITON_CNS_SEARCH_DOMAIN_PRIVATE`
Those vars will be automatically set with values appropriate for use in Spearhead Public Cloud:
Those vars will be automatically set with values appropriate for use in Triton Public Cloud:
```
SC_CNS_SEARCH_DOMAIN_PRIVATE=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3.cns.spearhead.cloud
SC_CNS_SEARCH_DOMAIN_PUBLIC=a42e7881-89d2-459e-bc0b-e9af0bca409a.us-east-3.spearhead.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 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](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
In addition to the shell script in this repo, this script will install:
- [Moby 1.12.6](https://github.com/moby/moby/releases/tag/v1.12.6)
- [Docker (now Moby) 1.12.6](https://github.com/moby/moby/releases/tag/v1.12.6)
- [Docker Compose 1.9.0](https://github.com/docker/compose/releases/tag/1.9.0)

View File

@ -1,152 +0,0 @@
#!/bin/bash
set -e -o pipefail
triton_docker_version=1.12.6
triton_compose_version=1.9.0
# Check if triton is installed and executable
function checkTritonInstalled () {
command -v spearhead >/dev/null 2>&1 || { echo >&2 "Spearhead CLI tools do not appear to be installed. Please install before continuing."; exit 1; }
}
# Check if curl is installed and executable
function checkCurlInstalled () {
command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required to complete this installation. Please install before continuing."; exit 1; }
}
# Check if the Docker binary (named spearhead-docker-helper)
# and Docker Compose (named spearhead-compose-helper) are installed and executable
function checkDockerInstalled () {
if
[ ! -f /usr/local/bin/spearhead-docker-helper ] ||
[ ! -x /usr/local/bin/spearhead-docker-helper ] ||
[ "${triton_docker_version}," != "$(/usr/local/bin/spearhead-docker-helper -v | awk '{print $3}')" ] ||
[ ! -f /usr/local/bin/spearhead-compose-helper ] ||
[ ! -x /usr/local/bin/spearhead-compose-helper ] ||
[ "${triton_compose_version}," != "$(/usr/local/bin/spearhead-compose-helper -v | awk '{print $3}')" ]
then
echo 'Additional or updated components are required.'
echo 'Please run `sudo spearhead-docker-install` to continue.'
echo
exit 1
fi
}
# Install architecture-specific Docker and Docker Compose binaries
function install () {
echo "Spearhead Cloud needs to install additional components for Docker and Docker Compose interactions."
echo "This installation will only happen once."
# Check if curl is installed and executable
checkCurlInstalled
# Install the specific version of Docker for Triton
rm -Rf /tmp/spearhead-docker /usr/local/bin/spearhead-docker-helper
mkdir -p /tmp/spearhead-docker
curl https://get.docker.com/builds/"$(uname -a | awk '{ print $1 }')"/x86_64/docker-${triton_docker_version}.tgz | tar zxvf - -C /tmp/spearhead-docker
mv /tmp/spearhead-docker/docker/docker /usr/local/bin/spearhead-docker-helper
rm -Rf /tmp/spearhead-docker
chmod +x /usr/local/bin/spearhead-docker-helper
echo "The spearhead-docker-helper is now installed."
echo
# Install the specific version of Docker Compose for Triton
curl -Lo /usr/local/bin/spearhead-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/spearhead-compose-helper
echo "The spearhead-compose-helper is now installed."
echo
}
# Emit the current Triton profile and time
function currentProfile () {
if [ -n "$SC_PROFILE" ]
then
local profile_source='via env var; use `eval "$(spearhead env <profile name>)"` to change'
else
local profile_source='default; use `spearhead profile set <profile name>` to change'
fi
# Get and the user's account information and CloudAPI URL for parsing later
local triton_account="$(spearhead account get)"
echo "Executing in '$(spearhead profile get | awk 'NR == 1 {print $2}')' (${profile_source})"
# Check if CNS is enabled, require it
if [ ! "true" == "$(echo "${triton_account}" | awk -F": " '/^triton_cns_enabled:/{print $2}')" ]
then
echo
tput rev # reverse
tput bold # bold
echo 'Warning! Triton CNS is not enabled.'
tput sgr0 # clear
echo
echo 'Please run the following to activate:'
echo ' spearhead account update triton_cns_enabled=true'
echo
fi
}
# Set env vars to make using CNS easier
function cnsEnvVars () {
# If the CNS env vars are already set, don't bother continuing
if [ -n "$SC_CNS_SEARCH_DOMAIN_PUBLIC" ] && [ -n "$SC_CNS_SEARCH_DOMAIN_PRIVATE" ]
then
return
fi
# Get and the user's account information and CloudAPI URL for parsing later
local triton_account="$(spearhead account get)"
local triton_url="$(spearhead profile get | awk -F"/" '/url:/{print $3}')"
#Do not continue if the target is not a Spearhead Cloud data center
if [ ! ".api.joyent.com" == "${triton_url: -15}" ] || [ ! ".api.spearhead.cloud" == "${triton_url: -15}" ]
then
return
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="$(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 SC_CNS_SEARCH_DOMAIN_PUBLIC="${triton_account_uuid}.${triton_dc}.spearhead.cloud"
export SC_CNS_SEARCH_DOMAIN_PRIVATE="${triton_account_uuid}.${triton_dc}.cns.spearhead.cloud"
}
function checkAll () {
checkTritonInstalled &&
checkDockerInstalled
}
if [ "profile" == "$1" ]
then
currentProfile
exit 1
fi
case "$(basename $0)" in
spearhead-docker)
checkAll &&
eval "$(spearhead env)" &&
cnsEnvVars &&
exec /usr/local/bin/spearhead-docker-helper $@
;;
spearhead-compose)
checkAll &&
eval "$(spearhead env)" &&
export COMPOSE_HTTP_TIMEOUT=750 &&
cnsEnvVars &&
exec /usr/local/bin/spearhead-compose-helper $@
;;
spearhead-docker-install)
install
;;
esac

155
triton-docker Executable file
View File

@ -0,0 +1,155 @@
#!/bin/bash
set -e -o pipefail
triton_docker_version=1.12.6
triton_compose_version=1.9.0
# Check if triton is installed and executable
function checkTritonInstalled () {
command -v triton >/dev/null 2>&1 || { echo >&2 "Triton CLI tools do not appear to be installed. Please install before continuing."; exit 1; }
}
# Check if curl is installed and executable
function checkCurlInstalled () {
command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required to complete this installation. Please install before continuing."; exit 1; }
}
# Check if the Docker binary (named triton-docker-helper)
# and Docker Compose (named triton-compose-helper) are installed and executable
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}')" ] ||
[ ! -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}')" ]
then
echo 'Additional or updated components are required.'
echo 'Please run `sudo triton-docker-install` to continue.'
echo
exit 1
fi
}
# Install architecture-specific Docker and Docker Compose binaries
function install () {
echo "Triton needs to install additional components for Docker and Docker Compose interactions."
echo "This installation will only happen once."
# Check if curl is installed and executable
checkCurlInstalled
# 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
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
echo "The triton-docker-helper is now installed."
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
chmod +x /usr/local/bin/triton-compose-helper
echo "The triton-compose-helper is now installed."
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 <profile name>)"` to change'
else
local profile_source='default; use `triton profile set <profile name>` to change'
fi
# Get and the user's account information and CloudAPI URL for parsing later
local triton_account="$(triton account get)"
echo "Executing in '$(triton profile get | awk 'NR == 1 {print $2}')' (${profile_source})"
# Check if CNS is enabled, require it
if [ ! "true" == "$(echo "${triton_account}" | awk -F": " '/^triton_cns_enabled:/{print $2}')" ]
then
echo
tput rev # reverse
tput bold # bold
echo 'Warning! 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
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" ]
then
return
fi
# 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" == "${triton_url: -15}" ]
then
return
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="$(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"
}
# Run all checks
function checkAll () {
checkTritonInstalled &&
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 &&
eval "$(triton env)" &&
cnsEnvVars &&
exec /usr/local/bin/triton-docker-helper $@
;;
triton-compose)
checkAll &&
eval "$(triton env)" &&
export COMPOSE_HTTP_TIMEOUT=750 &&
cnsEnvVars &&
exec /usr/local/bin/triton-compose-helper $@
;;
triton-docker-install)
install
;;
esac