From 3e7e6e76563afbbd244803769be4e3e84f4d8a81 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Mon, 27 Jan 2014 15:29:58 +0000 Subject: [PATCH] Add link alias without project name REDIS_1_PORT_6379_TCP_ADDR instead of FIGTEST_REDIS_1_PORT_6379_TCP_ADDR. Ref #37 --- README.md | 16 ++++++++-------- fig/container.py | 4 ++++ fig/service.py | 5 +++-- tests/service_test.py | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e9056583..b2df3502 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ from redis import Redis import os app = Flask(__name__) redis = Redis( - host=os.environ.get('FIGTEST_REDIS_1_PORT_6379_TCP_ADDR'), - port=int(os.environ.get('FIGTEST_REDIS_1_PORT_6379_TCP_PORT')) + host=os.environ.get('REDIS_1_PORT_6379_TCP_ADDR'), + port=int(os.environ.get('REDIS_1_PORT_6379_TCP_PORT')) ) @app.route('/') @@ -266,22 +266,22 @@ If there are existing containers for a service, `fig up` will stop and recreate Fig uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container. name\_PORT
-Full URL, e.g. `MYAPP_DB_1_PORT=tcp://172.17.0.5:5432` +Full URL, e.g. `DB_1_PORT=tcp://172.17.0.5:5432` name\_PORT\_num\_protocol
-Full URL, e.g. `MYAPP_DB_1_PORT_5432_TCP=tcp://172.17.0.5:5432` +Full URL, e.g. `DB_1_PORT_5432_TCP=tcp://172.17.0.5:5432` name\_PORT\_num\_protocol\_ADDR
-Container's IP address, e.g. `MYAPP_DB_1_PORT_5432_TCP_ADDR=172.17.0.5` +Container's IP address, e.g. `DB_1_PORT_5432_TCP_ADDR=172.17.0.5` name\_PORT\_num\_protocol\_PORT
-Exposed port number, e.g. `MYAPP_DB_1_PORT_5432_TCP_PORT=5432` +Exposed port number, e.g. `DB_1_PORT_5432_TCP_PORT=5432` name\_PORT\_num\_protocol\_PROTO
-Protocol (tcp or udp), e.g. `MYAPP_DB_1_PORT_5432_TCP_PROTO=tcp` +Protocol (tcp or udp), e.g. `DB_1_PORT_5432_TCP_PROTO=tcp` name\_NAME
-Fully qualified container name, e.g. `MYAPP_DB_1_NAME=/myapp_web_1/myapp_db_1` +Fully qualified container name, e.g. `DB_1_NAME=/myapp_web_1/myapp_db_1` [Docker links]: http://docs.docker.io/en/latest/use/port_redirection/#linking-a-container diff --git a/fig/container.py b/fig/container.py index 76f2d29e..c9417d0f 100644 --- a/fig/container.py +++ b/fig/container.py @@ -50,6 +50,10 @@ class Container(object): def name(self): return self.dictionary['Name'][1:] + @property + def name_without_project(self): + return '_'.join(self.dictionary['Name'].split('_')[1:]) + @property def number(self): try: diff --git a/fig/service.py b/fig/service.py index aaaa97ab..2e7a89d0 100644 --- a/fig/service.py +++ b/fig/service.py @@ -207,10 +207,11 @@ class Service(object): return max(numbers) + 1 def _get_links(self): - links = {} + links = [] for service in self.links: for container in service.containers(): - links[container.name] = container.name + links.append((container.name, container.name)) + links.append((container.name, container.name_without_project)) return links def _get_container_options(self, override_options, one_off=False): diff --git a/tests/service_test.py b/tests/service_test.py index ca9a0021..1357b761 100644 --- a/tests/service_test.py +++ b/tests/service_test.py @@ -154,6 +154,7 @@ class ServiceTest(DockerClientTestCase): db.start_container() web.start_container() self.assertIn('figtest_db_1', web.containers()[0].links()) + self.assertIn('db_1', web.containers()[0].links()) db.stop(timeout=1) web.stop(timeout=1)