Skip to content

Commit b01869a

Browse files
committed
start
0 parents  commit b01869a

File tree

10 files changed

+254
-0
lines changed

10 files changed

+254
-0
lines changed

consul/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM progrium/busybox
2+
MAINTAINER Jeff Lindsay <[email protected]>
3+
4+
ADD https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip /tmp/consul.zip
5+
RUN cd /bin && unzip /tmp/consul.zip && chmod +x /bin/consul && rm /tmp/consul.zip
6+
7+
ADD https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip /tmp/webui.zip
8+
RUN mkdir /ui && cd /tmp && unzip /tmp/webui.zip -d /ui && rm /tmp/webui.zip
9+
10+
ADD https://get.docker.io/builds/Linux/x86_64/docker-1.2.0 /bin/docker
11+
RUN chmod +x /bin/docker
12+
13+
RUN opkg-install curl bash
14+
15+
ADD ./config /config/
16+
ONBUILD ADD ./config /config/
17+
18+
ADD ./start /bin/start
19+
ADD ./check-http /bin/check-http
20+
ADD ./check-cmd /bin/check-cmd
21+
22+
EXPOSE 8300 8301 8301/udp 8302 8302/udp 8400 8500 53/udp
23+
VOLUME ["/data"]
24+
25+
ENV SHELL /bin/bash
26+
27+
ENTRYPOINT ["/bin/start"]
28+
CMD []

consul/check-cmd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
main() {
4+
local container_id="$1"; shift
5+
local port="$1"; shift
6+
local cmd="$@"
7+
8+
local image="$(docker inspect -f "{{.Config.Image}}" $container_id)"
9+
local ip="$(docker inspect -f "{{.NetworkSettings.IPAddress}}" $container_id)"
10+
docker run --rm --net container:$container_id -e "SERVICE_ADDR=$ip:$port" $image "$cmd"
11+
}
12+
13+
main $@

consul/check-http

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
readonly IMAGE="progrium/consul"
4+
5+
main() {
6+
local container_id="$1"; shift
7+
local port="$1"; shift
8+
local path="$1"; shift
9+
local opts="$@"
10+
11+
local ip="$(docker inspect -f "{{.NetworkSettings.IPAddress}}" $container_id)"
12+
local curl_cmd="curl \
13+
--silent \
14+
--show-error \
15+
--fail \
16+
--dump-header /dev/stderr \
17+
--retry 2 \
18+
$opts \
19+
http://$ip:$port$path > /dev/null"
20+
docker run --rm --net container:$container_id --entrypoint "/bin/bash" $IMAGE -c "$curl_cmd"
21+
}
22+
23+
main $@

consul/config/consul.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"data_dir": "/data",
3+
"ui_dir": "/ui",
4+
"client_addr": "0.0.0.0",
5+
"ports": {
6+
"dns": 53
7+
},
8+
"recursor": "8.8.8.8"
9+
}

consul/start

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
readonly IMAGE="progrium/consul"
4+
readonly EXPECT="${EXPECT:-3}"
5+
6+
cmd-run() {
7+
local ip_def="$1"; shift
8+
local args="$@"
9+
10+
declare external_ip join_ip bridge_ip run_mode client_flag server_flag
11+
12+
IFS=':' read external_ip join_ip client_flag <<< "${ip_def//::/:}"
13+
14+
if [[ -z "$join_ip" ]]; then
15+
run_mode="-bootstrap-expect $EXPECT"
16+
else
17+
run_mode="-join $join_ip"
18+
fi
19+
20+
if [[ -z "$client_flag" ]]; then
21+
server_flag="-server"
22+
fi
23+
24+
bridge_ip="$(ip ro | awk '/^default/{print $3}')"
25+
cat <<EOF
26+
eval docker run --name consul -h \$HOSTNAME \
27+
-p $external_ip:8300:8300 \
28+
-p $external_ip:8301:8301 \
29+
-p $external_ip:8301:8301/udp \
30+
-p $external_ip:8302:8302 \
31+
-p $external_ip:8302:8302/udp \
32+
-p $external_ip:8400:8400 \
33+
-p $external_ip:8500:8500 \
34+
-p $bridge_ip:53:53/udp \
35+
$args \
36+
$IMAGE $server_flag -advertise $external_ip $run_mode
37+
EOF
38+
}
39+
40+
main() {
41+
set -eo pipefail
42+
case "$1" in
43+
cmd:run) shift; cmd-run $@;;
44+
*) exec /bin/consul agent -config-dir=/config $@;;
45+
esac
46+
}
47+
48+
main "$@"

docker-compose.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: '2'
2+
services:
3+
consul:
4+
image: shcoder/consul
5+
container_name: consul
6+
restart: always
7+
ports:
8+
- 8400:8400
9+
- 8500:8500
10+
- 53:53/udp
11+
entrypoint:
12+
- /bin/start
13+
- -bootstrap
14+
- -server
15+
- -client 0.0.0.0
16+
17+
registrator:
18+
image: gliderlabs/registrator
19+
container_name: registrator
20+
restart: always
21+
volumes:
22+
- /var/run/docker.sock:/tmp/docker.sock
23+
entrypoint:
24+
- /bin/registrator
25+
- -internal
26+
- consul://consul:8500
27+
links:
28+
- consul
29+
30+
proxy:
31+
image: shcoder/nginx-proxy-consul-template
32+
container_name: nginx_proxy
33+
ports:
34+
- 80:80
35+
volumes:
36+
- ${PWD}/templates:/templates
37+
links:
38+
- consul
39+
- registrator
40+
environment:
41+
- CONSUL_URL=consul:8500
42+
- SERVICE_80_NAME=nginx_proxy
43+
44+
networks:
45+
default:
46+
external:
47+
name: app

nginx-proxy/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Version: 0.0.1
2+
FROM alpine:edge
3+
4+
MAINTAINER Alex Vikarchuk <[email protected]>
5+
6+
ENV CONSUL_URL consul:8500
7+
8+
RUN apk add --update unzip nginx bash && \
9+
rm -rf /var/cache/apk/* && \
10+
chown -R nginx:www-data /var/lib/nginx
11+
12+
COPY nginx.conf /etc/nginx/nginx.conf
13+
14+
COPY start.sh /bin/start.sh
15+
16+
VOLUME /etc/nginx/conf.d/
17+
18+
VOLUME /templates
19+
20+
COPY ./templates/service.ctmpl /templates/service.ctmpl
21+
22+
ADD https://releases.hashicorp.com/consul-template/0.14.0/consul-template_0.14.0_linux_amd64.zip /usr/bin/
23+
RUN unzip -uo /usr/bin/consul-template_0.14.0_linux_amd64.zip -d /usr/local/bin
24+
25+
EXPOSE 80 443
26+
ENTRYPOINT ["/bin/start.sh"]

nginx-proxy/nginx.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
worker_processes 1;
2+
#load_module modules/ngx_http_image_filter_module.so;
3+
4+
error_log /var/log/nginx/error.log warn;
5+
pid /var/run/nginx.pid;
6+
7+
events {
8+
worker_connections 1024;
9+
}
10+
11+
http {
12+
include /etc/nginx/mime.types;
13+
default_type application/octet-stream;
14+
15+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
16+
'$status $body_bytes_sent "$http_referer" '
17+
'"$http_user_agent" "$http_x_forwarded_for"';
18+
19+
access_log /var/log/nginx/access.log main;
20+
21+
sendfile off;
22+
#tcp_nopush on;
23+
24+
keepalive_timeout 65;
25+
26+
#gzip on;
27+
28+
include /etc/nginx/conf.d/*.conf;
29+
}

nginx-proxy/start.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
nginx
3+
consul-template -consul=$CONSUL_URL -template="/templates/service.ctmpl:/etc/nginx/conf.d/service.conf:nginx -s reload"

nginx-proxy/templates/service.ctmpl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{range services}}
2+
{{if in .Tags "entrypoint"}}
3+
server {
4+
listen 80;
5+
server_name {{.Name}}.dev;
6+
7+
location / {
8+
proxy_set_header X-Real-IP $remote_addr;
9+
proxy_set_header HOST $http_host;
10+
proxy_set_header X-NginX-Proxy true;
11+
12+
{{range service .Name "any"}}
13+
proxy_pass http://{{.Address}};
14+
{{end}}
15+
proxy_redirect off;
16+
}
17+
gzip on;
18+
gzip_disable "msie6";
19+
20+
gzip_vary on;
21+
gzip_proxied any;
22+
gzip_comp_level 6;
23+
gzip_buffers 16 8k;
24+
gzip_http_version 1.1;
25+
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
26+
}
27+
{{end}}
28+
{{end}}

0 commit comments

Comments
 (0)