-
Notifications
You must be signed in to change notification settings - Fork 31
Add CONSUL_RETRY_JOIN_WAN env #48
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
Changes from 28 commits
ea04c0f
cc21275
189414c
23c8c60
abad90e
b15de52
ee400d6
5c4c2d4
33ceafc
32ed8fc
5bec8ff
25de3dd
0c3db58
b44294b
3ebb138
24ae977
2f2893d
ac0d6e2
a84a860
667f0e2
5ab7825
efb1e9b
ff95e50
db96dd7
eb360fc
3c6f336
8b27a61
06bc9ea
6759213
9ea5646
ecc75ed
658d4e7
4cf52d9
dc5018f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| _env | ||
| _env* | ||
| examples/triton-multi-dc/docker-compose-*.yml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| version: '2.1' | ||
|
|
||
| services: | ||
|
|
||
| # Service definition for Consul cluster running in us-east-1. | ||
| # Cloned by ../../setup-multi-datacenter.sh once per profile | ||
| consul: | ||
| image: autopilotpattern/consul:${TAG:-latest} | ||
| labels: | ||
| - triton.cns.services=consul | ||
| - com.docker.swarm.affinities=["container!=~*consul*"] | ||
| restart: always | ||
| mem_limit: 128m | ||
| ports: | ||
| - 8300 # Server RPC port | ||
| - "8302/tcp" # Serf WAN port | ||
| - "8302/udp" # Serf WAN port | ||
| - 8500 | ||
| env_file: | ||
| - ENV_FILE_NAME | ||
| network_mode: bridge | ||
| command: > | ||
| /usr/local/bin/containerpilot |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| #!/bin/bash | ||
| set -e -o pipefail | ||
|
|
||
| help() { | ||
| echo | ||
| echo 'Usage ./setup-multi-datacenter.sh <triton-profile1> [<triton-profile2> [...]]' | ||
| echo | ||
| echo 'Invokes ./setup repeatedly to create one _env file per datacenter per triton profile,' | ||
| echo 'attempting to preserve the triton profile set before this script was invoked.' | ||
| echo | ||
| echo 'Warning: The current triton profile will be changed for each invocation of ./setup.sh,' | ||
| echo 'this may cause unexpected behavior if other commands that read the current triton profile' | ||
| echo 'are executed concurrently!' | ||
| } | ||
|
|
||
| if [ "$#" -lt 1 ]; then | ||
| help | ||
| exit 1 | ||
| fi | ||
|
|
||
| # --------------------------------------------------- | ||
| # Top-level commands | ||
|
|
||
| # | ||
| # Check for triton profile $1 and output _env file named $2 | ||
| # | ||
| generate_env() { | ||
| local triton_profile=$1 | ||
| local output_file=$2 | ||
|
|
||
| command -v docker >/dev/null 2>&1 || { | ||
| echo | ||
| tput rev # reverse | ||
| tput bold # bold | ||
| echo 'Docker is required, but does not appear to be installed.' | ||
| tput sgr0 # clear | ||
| echo 'See https://docs.joyent.com/public-cloud/api-access/docker' | ||
| exit 1 | ||
| } | ||
| command -v triton >/dev/null 2>&1 || { | ||
| echo | ||
| tput rev # reverse | ||
| tput bold # bold | ||
| echo 'Error! Joyent Triton CLI is required, but does not appear to be installed.' | ||
| tput sgr0 # clear | ||
| echo 'See https://www.joyent.com/blog/introducing-the-triton-command-line-tool' | ||
| exit 1 | ||
| } | ||
|
|
||
| # make sure Docker client is pointed to the same place as the Triton client | ||
| local docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}') | ||
| local docker_dc=$(echo $DOCKER_HOST | awk -F"/" '{print $3}' | awk -F'.' '{print $1}') | ||
|
|
||
| local triton_user=$(triton profile get $triton_profile | awk -F": " '/account:/{print $2}') | ||
| local triton_dc=$(triton profile get $triton_profile | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}') | ||
| local triton_account=$(TRITON_PROFILE=$triton_profile triton account get | awk -F": " '/id:/{print $2}') | ||
|
|
||
| if [ ! "$docker_user" = "$triton_user" ] || [ ! "$docker_dc" = "$triton_dc" ]; then | ||
| echo | ||
| tput rev # reverse | ||
| tput bold # bold | ||
| echo 'Error! The Triton CLI configuration does not match the Docker CLI configuration.' | ||
| tput sgr0 # clear | ||
| echo | ||
| echo "Docker user: ${docker_user}" | ||
| echo "Triton user: ${triton_user}" | ||
| echo "Docker data center: ${docker_dc}" | ||
| echo "Triton data center: ${triton_dc}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| local triton_cns_enabled=$(triton account get | 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 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # setup environment file | ||
| if [ ! -f "$output_file" ]; then | ||
| echo '# Consul bootstrap via Triton CNS' >> $output_file | ||
| echo CONSUL=consul.svc.${triton_account}.${triton_dc}.cns.joyent.com >> $output_file | ||
| echo >> $output_file | ||
| else | ||
| echo "Existing _env file found at $1, exiting" | ||
| exit | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| declare -a written | ||
| declare -a consul_hostnames | ||
|
|
||
| # check that we won't overwrite any _env files first | ||
| if [ -f "_env" ]; then | ||
| echo "Existing env file found, exiting: _env" | ||
| fi | ||
|
|
||
| # check the names of _env files we expect to generate | ||
| for profile in "$@" | ||
| do | ||
| if [ -f "_env-$profile" ]; then | ||
| echo "Existing env file found, exiting: _env-$profile" | ||
| exit 2 | ||
| fi | ||
|
|
||
| if [ -f "_env-$profile" ]; then | ||
| echo "Existing env file found, exiting: _env-$profile" | ||
| exit 3 | ||
| fi | ||
|
|
||
| if [ -f "docker-compose-$profile.yml" ]; then | ||
| echo "Existing docker-compose file found, exiting: docker-compose-$profile.yml" | ||
| exit 4 | ||
| fi | ||
| done | ||
|
|
||
| # check that the docker-compose.yml template is in the right place | ||
| if [ ! -f "docker-compose-multi-dc.yml.template" ]; then | ||
| echo "Multi-datacenter docker-compose.yml template is missing!" | ||
| exit 5 | ||
| fi | ||
|
|
||
| echo "profiles: $@" | ||
|
|
||
| # invoke ./setup.sh once per profile | ||
| for profile in "$@" | ||
| do | ||
| echo "Temporarily switching profile: $profile" | ||
| eval "$(TRITON_PROFILE=$profile triton env -d)" | ||
| generate_env $profile "_env-$profile" | ||
|
|
||
| unset CONSUL | ||
| source "_env-$profile" | ||
|
|
||
| consul_hostnames+=("\"${CONSUL//cns.joyent.com/triton.zone}\"") | ||
|
|
||
| cp docker-compose-multi-dc.yml.template \ | ||
| "docker-compose-$profile.yml" | ||
|
|
||
| sed -i '' "s/ENV_FILE_NAME/_env-$profile/" "docker-compose-$profile.yml" | ||
|
|
||
| written+=("_env-$profile") | ||
| done | ||
|
|
||
|
|
||
| # finalize _env and prepare docker-compose.yml files | ||
| for profile in "$@" | ||
| do | ||
| # add the CONSUL_RETRY_JOIN_WAN addresses to each _env | ||
| echo '# Consul multi-DC bootstrap via Triton CNS' >> _env-$profile | ||
| echo "CONSUL_RETRY_JOIN_WAN=$(IFS=,; echo "${consul_hostnames[*]}")" >> _env-$profile | ||
|
|
||
| cp docker-compose-multi-dc.yml.template \ | ||
| "docker-compose-$profile.yml" | ||
|
|
||
| sed -i '' "s/ENV_FILE_NAME/_env-$profile/" "docker-compose-$profile.yml" | ||
| done | ||
|
|
||
| echo "Wrote: ${written[@]}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,11 @@ check() { | |
| # make sure Docker client is pointed to the same place as the Triton client | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on moving
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The multi-dc example's setup script calls If the multi-dc example were named triton-multi-dc, or lived in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this isn't a code library you can copy the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| local docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}') | ||
| local docker_dc=$(echo $DOCKER_HOST | awk -F"/" '{print $3}' | awk -F'.' '{print $1}') | ||
| TRITON_USER=$(triton profile get | awk -F": " '/account:/{print $2}') | ||
| TRITON_DC=$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}') | ||
|
|
||
| TRITON_USER=$(triton profile get $TRITON_PROFILE | awk -F": " '/account:/{print $2}') | ||
| TRITON_DC=$(triton profile get $TRITON_PROFILE | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}') | ||
| TRITON_ACCOUNT=$(triton account get | awk -F": " '/id:/{print $2}') | ||
|
|
||
| if [ ! "$docker_user" = "$TRITON_USER" ] || [ ! "$docker_dc" = "$TRITON_DC" ]; then | ||
| echo | ||
| tput rev # reverse | ||
|
|
@@ -76,7 +78,7 @@ check() { | |
| echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com >> _env | ||
| echo >> _env | ||
| else | ||
| echo 'Existing _env file found, exiting' | ||
| echo 'Existing _env file found at _env, exiting' | ||
| exit | ||
| fi | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of both
buildandimage? This file was more helpful withoutimageand just building the container locally. I'm not sure what that is buying us.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using the docker-compose file to build the image as well. I'll remove it.