Skip to content

Commit

Permalink
Merge pull request #3 from tgross/bootstrap-with-containerbuddy
Browse files Browse the repository at this point in the history
Bootstrap with Containerbuddy
  • Loading branch information
tgross committed Nov 24, 2015
2 parents 1d70dc4 + 3d643e3 commit 543b558
Show file tree
Hide file tree
Showing 17 changed files with 648 additions and 393 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
14 changes: 10 additions & 4 deletions Dockerfile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ MAINTAINER Casey Bisson <[email protected]>
# Note: glibc is required because the Consul binary we're using is built against it
RUN apk --update \
add \
jq \
curl \
bash \
ca-certificates && \
Expand All @@ -29,10 +28,20 @@ RUN mkdir /ui && \
mv dist/* . && \
rm -rf dist

# get Containerbuddy release
RUN export CB=containerbuddy-0.0.1-alpha &&\
mkdir -p /opt/containerbuddy && \
curl -Lo /tmp/${CB}.tar.gz \
https://github.com/joyent/containerbuddy/releases/download/0.0.1-alpha/${CB}.tar.gz && \
tar xzf /tmp/${CB}.tar.gz -C /tmp && \
mv /tmp/build/containerbuddy /opt/containerbuddy/
COPY containerbuddy.json /etc/

# Consul config
COPY ./config /config/
ONBUILD ADD ./config /config/

# copy bootstrap scripts
COPY ./bin/* /bin/

EXPOSE 8300 8301 8301/udp 8302 8302/udp 8400 8500 53 53/udp
Expand All @@ -43,6 +52,3 @@ VOLUME ["/data"]

ENV GOMAXPROCS 2
ENV SHELL /bin/bash

ENTRYPOINT ["/bin/triton-start"]
CMD []
Empty file modified LICENSE
100755 → 100644
Empty file.
13 changes: 5 additions & 8 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ Detailed example to come....

## How it works

This demo actually sets up two independent Consul services:
This demo first starts up a bootstrap node that starts the raft but expects 2 additional nodes before the raft is healthy. Once this node is up and its IP address is obtained, the rest of the nodes are started and joined to the bootstrap IP address (the value is passed in the `BOOTSTRAP_HOST` environment variable).

1. A single-node instance used only for bootstrapping the raft
1. A three-node instance that other applications can point to
If a raft instance fails, the data is preserved among the other instances and the overall availability of the service is preserved because any single instance can authoritatively answer for all instances. Applications that depend on the Consul service should re-try failed requests until they get a response.

A running raft has no dependency on the bootstrap instance. New raft instances do need to connect to the bootstrap instance to find the raft, creating a failure gap that is discussed below. If a raft instance fails, the data is preserved among the other instances and the overall availability of the service is preserved because any single instance can authoritatively answer for all instances. Applications that depend on the Consul service should re-try failed requests until they get a response.
Any new raft instances need to be started with a bootstrap IP address, but after the initial cluster is created, the `BOOTSTRAP_HOST` IP address can be any host currently in the raft. This means there is no dependency on the first node after the cluster has been formed.

Each raft instance will constantly re-register with the bootstrap instance. If the boostrap instance or its data is lost, a new bootstrap instance can be started and all existing raft instances will re-register with it. In a scenario where the bootstrap instance is unavailable, it will be impossible to start raft instances until the bootstrap instance has been restarted and at least one existing raft member has reregistered.

## Triston-specific availability advantages
## Triton-specific availability advantages

Some details about how Docker containers work on Triton have specific bearing on the durability and availability of this service:

Expand All @@ -45,4 +42,4 @@ Some details about how Docker containers work on Triton have specific bearing on

# Credit where it's due

This project builds on the fine examples set by [Jeff Lindsay](https://github.com/progrium)'s ([Glider Labs](https://github.com/gliderlabs)) [Consul in Docker](https://github.com/gliderlabs/docker-consul/tree/legacy) work. It also, obviously, wouldn't be possible without the outstanding work of the [Hashicorp team](https://hashicorp.com) that made [consul.io](https://www.consul.io).
This project builds on the fine examples set by [Jeff Lindsay](https://github.com/progrium)'s ([Glider Labs](https://github.com/gliderlabs)) [Consul in Docker](https://github.com/gliderlabs/docker-consul/tree/legacy) work. It also, obviously, wouldn't be possible without the outstanding work of the [Hashicorp team](https://hashicorp.com) that made [consul.io](https://www.consul.io).
18 changes: 0 additions & 18 deletions bin/consul-health

This file was deleted.

25 changes: 25 additions & 0 deletions bin/consul-heartbeat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# 1. check if member of a raft
# 2a. yes? --> execute health check
# 2b. no? --> check if BOOTSTRAP_HOST is set?
# 3a. no? --> join self
# 3b. yes? --> join raft

log() {
echo " $(date -u '+%Y-%m-%d %H:%M:%S') containerbuddy: $@"
}

if [ $(consul info | awk '/num_peers/{print $3}') == 0 ]; then
log "No peers in raft"
if [ -n "${BOOTSTRAP_HOST}" ]; then
log "Joining raft at ${BOOTSTRAP_HOST}"
consul join ${BOOTSTRAP_HOST}
else
log "Bootstrapping raft with self"
consul join $(ip addr show eth0 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
fi
else
consul info &> /dev/null
exit $?
fi
225 changes: 0 additions & 225 deletions bin/triton-bootstrap

This file was deleted.

60 changes: 0 additions & 60 deletions bin/triton-start

This file was deleted.

Empty file modified config/consul.json
100755 → 100644
Empty file.
Loading

0 comments on commit 543b558

Please sign in to comment.