-
Notifications
You must be signed in to change notification settings - Fork 32
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
Merged
tjcelaya
merged 34 commits into
autopilotpattern:master
from
tjcelaya:enhancement/47-retry-join-wan-in-config-file
Jan 5, 2018
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
ea04c0f
Resolve #23 by adding CONSUL_DATACENTER_NAME env
tjcelaya cc21275
Mention the environment variable in the README
tjcelaya 189414c
Resolves #47 by adding CONSUL_RETRY_JOIN_WAN
tjcelaya 23c8c60
Remove debugging output
tjcelaya abad90e
Fix the environment value now that we've collected the error message
tjcelaya b15de52
Environment variable documentation and moving examples.
tjcelaya ee400d6
Triton datacenter autodetection
tjcelaya 5c4c2d4
README update for envs
tjcelaya 33ceafc
Merge updates to #46
tjcelaya 32ed8fc
more things
tjcelaya 5bec8ff
it was bind_addr all along
tjcelaya 25de3dd
Always set the alternate addresses for now, might move all of these b…
tjcelaya 0c3db58
Fix the CONSUL_BIND_ADDR check
tjcelaya b44294b
Add self-anti-affinity
tjcelaya 3ebb138
Fix silly config error
tjcelaya 24ae977
Move env vars section
tjcelaya 2f2893d
Resolve merge conflicts
tjcelaya ac0d6e2
Split up triton from multi-dc triton examples
tjcelaya a84a860
Remove fake multi-dc docker-compose example
tjcelaya 667f0e2
Fix test Dockerfile paths
tjcelaya 5ab7825
Fix multi-dc clean target
tjcelaya efb1e9b
Fix template name
tjcelaya ff95e50
Try a new multi-dc layout
tjcelaya db96dd7
Separate the triton and triton-multi-dc setup scripts
tjcelaya eb360fc
make the check function easier to use
tjcelaya 3c6f336
Fix account id query command
tjcelaya 8b27a61
Path and script name change in README
tjcelaya 06bc9ea
Clarify README
tjcelaya 6759213
Fix duplicate env vars from merge conflict resolution
tjcelaya 9ea5646
Fix usage output description
tjcelaya ecc75ed
Fix description again
tjcelaya 658d4e7
Remove the build key from examples/compose/docker-compose.yml
tjcelaya 4cf52d9
Revert ./setup.sh change
tjcelaya dc5018f
Typo
tjcelaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| _env | ||
| _env* | ||
| examples/triton-multi-dc/docker-compose-*.yml |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
examples/triton-multi-dc/docker-compose-multi-dc.yml.template
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| #!/bin/bash | ||
| set -e -o pipefail | ||
|
|
||
| help() { | ||
| echo | ||
| echo 'Usage ./setup-multi-datacenter.sh <triton-profile1> [<triton-profile2> [...]]' | ||
| echo | ||
| echo 'Generates one _env file and docker-compose.yml file per triton profile, each of which' | ||
| echo 'is presumably associated with a different datacenter.' | ||
| } | ||
|
|
||
| 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[@]}" |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thoughts on moving
setup.shintoexamples/triton? It doesn't seem like a requirement forexamples/composeorexamples/multi-dc.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.
The multi-dc example's setup script calls
setup.shonce per datacenter so there is a dependency between the two. Nothing preventing us from referencing it as../triton/setup.shbut it would lead to some confusion.If the multi-dc example were named triton-multi-dc, or lived in
examples/triton/multi-dcit might make the script dependency more obvious. Thoughts?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.
Since this isn't a code library you can copy the
check()function into your own shell script. Your script is superseding that setup anyway so owning it might help extend things later, like automatic setup across multiple profiles instead of leaving that up to the end user (removing those extraexportsteps over each DC). The latter isn't something we need to be concerned with ATM though.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.
checkwas copied into./setup-multi-dc.shand renamed togenerate_env