From 9a85df20649d0d627f8e3e7ae97092cc88ae10db Mon Sep 17 00:00:00 2001 From: root Date: Sat, 21 Oct 2017 14:23:40 -0200 Subject: [PATCH 1/3] update to alpine 3.6 and consul to 1.0 --- 1.0/consul-agent/Dockerfile | 6 +++++ 1.0/consul-agent/Makefile | 3 +++ 1.0/consul-agent/config/agent.json | 9 +++++++ 1.0/consul-server/Dockerfile | 3 +++ 1.0/consul-server/Makefile | 3 +++ 1.0/consul-server/config/server.json | 6 +++++ 1.0/consul/Dockerfile | 15 +++++++++++ 1.0/consul/Makefile | 3 +++ 1.0/consul/update_version.sh | 40 ++++++++++++++++++++++++++++ Makefile | 2 +- 10 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 1.0/consul-agent/Dockerfile create mode 100644 1.0/consul-agent/Makefile create mode 100644 1.0/consul-agent/config/agent.json create mode 100644 1.0/consul-server/Dockerfile create mode 100644 1.0/consul-server/Makefile create mode 100644 1.0/consul-server/config/server.json create mode 100644 1.0/consul/Dockerfile create mode 100644 1.0/consul/Makefile create mode 100755 1.0/consul/update_version.sh diff --git a/1.0/consul-agent/Dockerfile b/1.0/consul-agent/Dockerfile new file mode 100644 index 0000000..dc89dcb --- /dev/null +++ b/1.0/consul-agent/Dockerfile @@ -0,0 +1,6 @@ +FROM gliderlabs/consul:1.0 +ADD ./config /config/ +EXPOSE 8300 8301 8301/udp 8302 8302/udp 8400 8500 8600 8600/udp +ENV DNS_RESOLVES consul +ENV DNS_PORT 8600 +ENTRYPOINT ["/bin/consul", "agent", "-config-dir=/config"] diff --git a/1.0/consul-agent/Makefile b/1.0/consul-agent/Makefile new file mode 100644 index 0000000..ceaa6fd --- /dev/null +++ b/1.0/consul-agent/Makefile @@ -0,0 +1,3 @@ + +build: + docker build -t gliderlabs/consul-agent:$(VERSION) . diff --git a/1.0/consul-agent/config/agent.json b/1.0/consul-agent/config/agent.json new file mode 100644 index 0000000..529b602 --- /dev/null +++ b/1.0/consul-agent/config/agent.json @@ -0,0 +1,9 @@ +{ + "client_addr": "0.0.0.0", + "data_dir": "/data", + "leave_on_terminate": true, + "dns_config": { + "allow_stale": true, + "max_stale": "1s" + } +} diff --git a/1.0/consul-server/Dockerfile b/1.0/consul-server/Dockerfile new file mode 100644 index 0000000..55dd3de --- /dev/null +++ b/1.0/consul-server/Dockerfile @@ -0,0 +1,3 @@ +FROM gliderlabs/consul-agent:1.0 +ADD ./config /config/ +ENTRYPOINT ["/bin/consul", "agent", "-server", "-config-dir=/config"] diff --git a/1.0/consul-server/Makefile b/1.0/consul-server/Makefile new file mode 100644 index 0000000..b853017 --- /dev/null +++ b/1.0/consul-server/Makefile @@ -0,0 +1,3 @@ + +build: + docker build -t gliderlabs/consul-server:$(VERSION) . diff --git a/1.0/consul-server/config/server.json b/1.0/consul-server/config/server.json new file mode 100644 index 0000000..9132902 --- /dev/null +++ b/1.0/consul-server/config/server.json @@ -0,0 +1,6 @@ +{ + "ui": true, + "dns_config": { + "allow_stale": false + } +} diff --git a/1.0/consul/Dockerfile b/1.0/consul/Dockerfile new file mode 100644 index 0000000..5fc48f6 --- /dev/null +++ b/1.0/consul/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.6 + +ENV CONSUL_VERSION 1.0.0 +ENV CONSUL_SHA256 585782e1fb25a2096e1776e2da206866b1d9e1f10b71317e682e03125f22f479 + +RUN apk --no-cache add curl ca-certificates \ + && curl -sSL https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip -o /tmp/consul.zip \ + && echo "${CONSUL_SHA256} /tmp/consul.zip" > /tmp/consul.sha256 \ + && sha256sum -c /tmp/consul.sha256 \ + && cd /bin \ + && unzip /tmp/consul.zip \ + && chmod +x /bin/consul \ + && rm /tmp/consul.zip + +ENTRYPOINT ["/bin/consul"] diff --git a/1.0/consul/Makefile b/1.0/consul/Makefile new file mode 100644 index 0000000..33d1bdd --- /dev/null +++ b/1.0/consul/Makefile @@ -0,0 +1,3 @@ + +build: + docker build -t gliderlabs/consul:$(VERSION) . diff --git a/1.0/consul/update_version.sh b/1.0/consul/update_version.sh new file mode 100755 index 0000000..cdd8b6b --- /dev/null +++ b/1.0/consul/update_version.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -eo pipefail +[[ "$TRACE" ]] && set -x || : + +debug() { + [[ "$DEBUG" ]] && echo "-----> $*" 1>&2 +} + +consul_version() { + sed -n "s/ENV CONSUL_VERSION //p" Dockerfile +} + +next_version() { + debug "new version will be calculated ..." + local oldVersion=$(consul_version) + debug "oldVersion: $oldVersion" + echo ${oldVersion%.*}.$((${oldVersion##*.} + 1)) +} + +update_dockerfile() { + declare ver=${1:? required} + + local sha=$(curl -Ls https://releases.hashicorp.com/consul/${ver}/consul_${ver}_SHA256SUMS | sed -n "s/ .*linux_amd64.*//p") + debug "sha=$sha" + + sed -i "s/\(ENV CONSUL_VERSION\) .*/\1 $newVersion/;s/\(ENV CONSUL_SHA256\) .*/\1 $sha/" Dockerfile +} + +main() { + declare desc="Updates Dockerfile url/sha for the provided version, or calculates next patch version if called without params" + declare newVersion=${1:-$(next_version)} + + debug "newVersion=$newVersion" + update_dockerfile $newVersion + git diff + echo "=====> Now you can run: git commit -am 'Upgrade Consul to $newVersion'" +} + +[[ "$0" == "$BASH_SOURCE" ]] && main "$@" || : diff --git a/Makefile b/Makefile index 3be5b1b..92084e6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.7 +VERSION=1.0 build: VERSION=$(VERSION) make -C $(VERSION)/consul From bf887c4deb097b4591ca281c444d16e86cbfa696 Mon Sep 17 00:00:00 2001 From: Willian Vieira Cardoso Date: Mon, 23 Oct 2017 00:29:55 -0200 Subject: [PATCH 2/3] first commit and first laboratory. The ideia is simulate one environment of service discovery with consul --- laboratory/README.md | 1 + laboratory/consul/README.md | 0 laboratory/consul/exec.sh | 20 ++++++++++++++++++++ laboratory/consul/node1.json | 23 +++++++++++++++++++++++ laboratory/consul/node2.json | 23 +++++++++++++++++++++++ laboratory/consul/node3.json | 23 +++++++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 laboratory/README.md create mode 100644 laboratory/consul/README.md create mode 100755 laboratory/consul/exec.sh create mode 100644 laboratory/consul/node1.json create mode 100644 laboratory/consul/node2.json create mode 100644 laboratory/consul/node3.json diff --git a/laboratory/README.md b/laboratory/README.md new file mode 100644 index 0000000..80f568a --- /dev/null +++ b/laboratory/README.md @@ -0,0 +1 @@ +# laboratory diff --git a/laboratory/consul/README.md b/laboratory/consul/README.md new file mode 100644 index 0000000..e69de29 diff --git a/laboratory/consul/exec.sh b/laboratory/consul/exec.sh new file mode 100755 index 0000000..e79c655 --- /dev/null +++ b/laboratory/consul/exec.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +consul='consul' + +### CONSUL SERVER MODE +docker run -d -p 8500:8500 --name $consul -h $consul progrium/consul -server -bootstrap + +### GET IP CONSUL SERVER +JOIN_IP="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' $consul)" + +### SIMULATE ONE CONSUL AGENT MODE +docker run -d --name node1 -h node1 -v $PWD/node1.json:/config/consul.json progrium/consul -join $JOIN_IP +docker run -d --name node2 -h node1 -v $PWD/node2.json:/config/consul.json progrium/consul -join $JOIN_IP +docker run -d --name node3 -h node1 -v $PWD/node3.json:/config/consul.json progrium/consul -join $JOIN_IP + +### SIMULATE ONE SERVICE +docker run -d --name apache1 nimmis/alpine-apache +docker run -d --name apache2 nimmis/alpine-apache +docker run -d --name apache3 nimmis/alpine-apache + diff --git a/laboratory/consul/node1.json b/laboratory/consul/node1.json new file mode 100644 index 0000000..b1aaeea --- /dev/null +++ b/laboratory/consul/node1.json @@ -0,0 +1,23 @@ +{ + "data_dir": "/data", + "ui_dir": "/ui", + "client_addr": "0.0.0.0", + "ports": { + "dns": 53 + }, + "recursor": "8.8.8.8", + "disable_update_check": true, + + "service": { + "name": "pro_88888_apache", + "port": 80, + "tags": [ + "apache", + "demonstration" + ], + "check": { + "script": "curl 172.17.0.4:80 > /dev/null 2>&1", + "interval": "10s" + } + } +} diff --git a/laboratory/consul/node2.json b/laboratory/consul/node2.json new file mode 100644 index 0000000..07a2446 --- /dev/null +++ b/laboratory/consul/node2.json @@ -0,0 +1,23 @@ +{ + "data_dir": "/data", + "ui_dir": "/ui", + "client_addr": "0.0.0.0", + "ports": { + "dns": 53 + }, + "recursor": "8.8.8.8", + "disable_update_check": true, + + "service": { + "name": "pro_88888_apache", + "port": 80, + "tags": [ + "apache", + "demonstration" + ], + "check": { + "script": "curl 172.17.0.5:80 > /dev/null 2>&1", + "interval": "10s" + } + } +} diff --git a/laboratory/consul/node3.json b/laboratory/consul/node3.json new file mode 100644 index 0000000..8294ca8 --- /dev/null +++ b/laboratory/consul/node3.json @@ -0,0 +1,23 @@ +{ + "data_dir": "/data", + "ui_dir": "/ui", + "client_addr": "0.0.0.0", + "ports": { + "dns": 53 + }, + "recursor": "8.8.8.8", + "disable_update_check": true, + + "service": { + "name": "pro_88888_apache", + "port": 80, + "tags": [ + "apache", + "demonstration" + ], + "check": { + "script": "curl 172.17.0.6:80 > /dev/null 2>&1", + "interval": "10s" + } + } +} From 9c7ff45d7045542ffea0f112116d4bb1da3c21c6 Mon Sep 17 00:00:00 2001 From: Willian Vieira Cardoso Date: Mon, 23 Oct 2017 01:21:42 -0200 Subject: [PATCH 3/3] last version of simulate environment consul --- laboratory/consul/exec.sh | 14 +++++--------- laboratory/consul/node1.json | 1 + laboratory/consul/node2.json | 2 +- laboratory/consul/node3.json | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/laboratory/consul/exec.sh b/laboratory/consul/exec.sh index e79c655..96d76fb 100755 --- a/laboratory/consul/exec.sh +++ b/laboratory/consul/exec.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x consul='consul' @@ -9,12 +9,8 @@ docker run -d -p 8500:8500 --name $consul -h $consul progrium/consul -server -bo JOIN_IP="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' $consul)" ### SIMULATE ONE CONSUL AGENT MODE -docker run -d --name node1 -h node1 -v $PWD/node1.json:/config/consul.json progrium/consul -join $JOIN_IP -docker run -d --name node2 -h node1 -v $PWD/node2.json:/config/consul.json progrium/consul -join $JOIN_IP -docker run -d --name node3 -h node1 -v $PWD/node3.json:/config/consul.json progrium/consul -join $JOIN_IP - -### SIMULATE ONE SERVICE -docker run -d --name apache1 nimmis/alpine-apache -docker run -d --name apache2 nimmis/alpine-apache -docker run -d --name apache3 nimmis/alpine-apache +for i in $(seq 1 3); do + docker run -d --name node${i} -h node${i} -v $PWD/node${i}.json:/config/consul.json progrium/consul -join $JOIN_IP + docker run -d --name apache${i} nimmis/alpine-apache +done diff --git a/laboratory/consul/node1.json b/laboratory/consul/node1.json index b1aaeea..0791308 100644 --- a/laboratory/consul/node1.json +++ b/laboratory/consul/node1.json @@ -1,4 +1,5 @@ { + "leave_on_terminate": true, "data_dir": "/data", "ui_dir": "/ui", "client_addr": "0.0.0.0", diff --git a/laboratory/consul/node2.json b/laboratory/consul/node2.json index 07a2446..8294ca8 100644 --- a/laboratory/consul/node2.json +++ b/laboratory/consul/node2.json @@ -16,7 +16,7 @@ "demonstration" ], "check": { - "script": "curl 172.17.0.5:80 > /dev/null 2>&1", + "script": "curl 172.17.0.6:80 > /dev/null 2>&1", "interval": "10s" } } diff --git a/laboratory/consul/node3.json b/laboratory/consul/node3.json index 8294ca8..27c781b 100644 --- a/laboratory/consul/node3.json +++ b/laboratory/consul/node3.json @@ -16,7 +16,7 @@ "demonstration" ], "check": { - "script": "curl 172.17.0.6:80 > /dev/null 2>&1", + "script": "curl 172.17.0.8:80 > /dev/null 2>&1", "interval": "10s" } }