Skip to content

Commit

Permalink
connectable and lookup package
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Jun 29, 2015
1 parent d990aab commit 9baa115
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 556 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
.git
1 change: 0 additions & 1 deletion .gitignore
@@ -1,2 +1 @@
ambassadord
release
20 changes: 10 additions & 10 deletions Dockerfile
@@ -1,10 +1,10 @@
FROM ubuntu:trusty

RUN apt-get update && apt-get install -y iptables socat

ADD ./stage/ambassadord /bin/ambassadord
ADD ./stage/start /start

EXPOSE 10000

ENTRYPOINT ["/start"]
FROM alpine:3.2
ENTRYPOINT ["/bin/connectable"]
COPY . /go/src/github.com/progrium/connectable
RUN apk add --update go git mercurial iptables \
&& cd /go/src/github.com/progrium/connectable \
&& export GOPATH=/go \
&& go get \
&& go build -ldflags "-X main.Version $(cat VERSION)" -o /bin/connectable \
&& apk del go git mercurial \
&& rm -rf /go /var/cache/apk/*
9 changes: 9 additions & 0 deletions Dockerfile.dev
@@ -0,0 +1,9 @@
FROM gliderlabs/alpine:3.2
ENV GOPATH /go
RUN apk-install go git mercurial iptables
COPY . /go/src/github.com/progrium/connectable
WORKDIR /go/src/github.com/progrium/connectable
RUN go get
CMD go get \
&& go build -ldflags "-X main.Version dev" -o /bin/connectable \
&& exec /bin/connectable
22 changes: 18 additions & 4 deletions LICENSE
@@ -1,7 +1,21 @@
Copyright (C) 2014 Jeff Lindsay
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Copyright (c) 2015 Glider Labs

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 10 additions & 20 deletions Makefile
@@ -1,21 +1,11 @@
NAME=ambassadord
HARDWARE=$(shell uname -m)
VERSION=0.0.1
NAME=connectable
REPO=progrium
VERSION=$(shell cat VERSION)

build:
go build -o stage/ambassadord
docker build -t ambassadord .

release:
rm -rf release
mkdir release
GOOS=linux go build -o release/$(NAME)
cd release && tar -zcf $(NAME)_$(VERSION)_linux_$(HARDWARE).tgz $(NAME)
GOOS=darwin go build -o release/$(NAME)
cd release && tar -zcf $(NAME)_$(VERSION)_darwin_$(HARDWARE).tgz $(NAME)
rm release/$(NAME)
echo "$(VERSION)" > release/version
echo "progrium/$(NAME)" > release/repo
gh-release

.PHONY: build
dev:
@docker history $(NAME):dev &> /dev/null \
|| docker build -f Dockerfile.dev -t $(NAME):dev .
@docker run --rm --name $(NAME)-dev \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(PWD):/go/src/github.com/$(REPO)/$(NAME) \
$(NAME):dev
49 changes: 13 additions & 36 deletions README.md
@@ -1,7 +1,7 @@
# Connectable (previously ambassadord)
# Connectable

A smart Docker proxy that lets your containers connect to other containers via service
discovery without being service discovery aware.
discovery *without being service discovery aware*.

## Getting Connectable

Expand All @@ -16,56 +16,33 @@ Basic overview is:
1. Run a service registry like Consul, perhaps with Registrator
1. Start a Connectable container on each host
1. Expose Connectable to your containers, using links or Resolvable (experimental)
1. Run containers with environment variables defining what they need to connect to
1. Have software in those containers connect to backing services via Connectable
1. Run containers with labels defining what they need to connect to with what ports
1. Have software in those containers connect via those ports on localhost

#### Starting Connectable

Once you have a service registry set up, you point Connectable to it when you launch it.
You also need to mount the Docker socket. Here is an example using the local Consul agent, assuming you're running Resolvable:

$ docker run -d --name connectable \
-v /var/run/docker.sock:/var/run/docker.sock \
progrium/connectable:latest \
consul://consul.docker:8500

Connectable supports other registries and is extendable via modules.

If you're running Consul with DNS available to your containers using the `-dns` flag or using Resolvable, you don't have to specify any registry. Connectable will do SRV lookups via DNS by default:

$ docker run -d --name connectable \
-v /var/run/docker.sock:/var/run/docker.sock \
progrium/connectable:latest

#### Start containers that use Connectable
With Resolvable running, it will have access to Consul DNS. It will be able to resolve any connections using DNS names.

First, you need to expose the running Connectable container to new containers. Normally this is done using links. Links are unnecessary if you're running Resolvable. However, in this example we'll use links.
#### Start containers that use Connectable

The only other step you need to do is specify the name of the service(s) you want to connect to using environment variables. You also specify a port you'll use when connecting to Connectable. For example:
All you have to do is specify a port to use and what you'd like to connect to as a label. For example:

CONNECT_6000=redis.service.consul
connect[6000]=redis.service.consul

With this environment variable set, you can connect to Connectable on 6000 and it will take you to the Redis service found via Consul DNS. You can also specify multiple services:
With this label set, you can connect to Redis on localhost:6000. You can also specify multiple services:

$ docker run -d --name myservice \
-e CONNECT_6000=redis.service.consul \
-e CONNECT_3306=master.mysql.service.consul \
--link connectable:connectable \
-l connect[6000]=redis.service.consul \
-l connect[3306]=master.mysql.service.consul \
example/myservice

Now in your service container, you can connect to `connectable:6000` to get to Redis and `connectable:3306` to get to your MySQL master. If you were using Resolvable, you could drop the link and use `connectable.docker` instead of `connectable` when connecting.

## Configuring Connectable

Connectable just needs to know what service registry to use and how to use it. It's easiest when you have DNS discovery available and you don't need to specify a registry. But, for example, if you were using etcd, you'd need to specify a URI with the etcd address and the prefix used for your services:

$ docker run -d --name connectable \
-v /var/run/docker.sock:/var/run/docker.sock \
progrium/connectable:latest \
etcd://etcd.docker:4001/path/to/services

Different registry modules have different options that can be passed in the URI. For example, there is a `consulkv` module to use the KV store instead of Consul's service discovery API.

## Load Balancing

Connectable acts as a load balancer across instance of services it finds. It shuffles them randomly on new connections. Although this seems less predictable, it ensures even balancing cluster-wide.
Expand Down Expand Up @@ -121,8 +98,8 @@ https://github.com/docker/docker/issues/7467

## Sponsor and Thanks

The original ambassadord proof of concept was made possible thanks to [DigitalOcean](http://digitalocean.com). Also thanks to [Jérôme Petazzoni](https://github.com/jpetazzo) for helping with the bits that make this magical.
Connectable is sponsored by [Weave](http://weave.works). The original ambassadord proof of concept was made possible thanks to [DigitalOcean](http://digitalocean.com). Also thanks to [Jérôme Petazzoni](https://github.com/jpetazzo) for helping with the iptables bits that make this magical.

## License

BSD
MIT
3 changes: 2 additions & 1 deletion SPONSORS
@@ -1 +1,2 @@
DigitalOcean http://digitalocean.com
DigitalOcean http://digitalocean.com
Weave http://weave.works
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
0.1.0
84 changes: 0 additions & 84 deletions ambassadord.go

This file was deleted.

0 comments on commit 9baa115

Please sign in to comment.