Compare commits

...

9 Commits
0.1.2 ... 0.1.3

Author SHA1 Message Date
Aanand Prasad
b43b007b92 Merge pull request #50 from orchardup/ship-0.1.3
Bump version to 0.1.3
2014-01-23 04:02:44 -08:00
Ben Firshman
33aada05a4 Bump version to 0.1.3 2014-01-23 11:58:48 +00:00
Ben Firshman
0bdd8637db Merge pull request #47 from orchardup/fix-split-buffer
Fig bug in split_buffer where input was being discarded
2014-01-22 10:05:43 -08:00
Aanand Prasad
e8472be6d5 Fig bug in split_buffer where input was being discarded
Also, write some tests for it.
2014-01-22 17:44:04 +00:00
Ben Firshman
84667636a2 Merge pull request #46 from orchardup/fix-port-syntax
Fix port syntax
2014-01-22 09:13:54 -08:00
Aanand Prasad
df9f66d437 Allow ports to be specified in '1234/tcp' format 2014-01-22 17:01:10 +00:00
Aanand Prasad
ae67d55bf2 Fix bug where too many '/tcp' suffixes were added to port config 2014-01-22 16:52:42 +00:00
Ben Firshman
18525554ed Add license to setup.py 2014-01-22 14:15:17 +00:00
Ben Firshman
64513e8d6f Verbose nosetests 2014-01-22 14:00:24 +00:00
9 changed files with 84 additions and 26 deletions

View File

@@ -1,6 +1,12 @@
Change log
==========
0.1.3 (2014-01-23)
------------------
- Fix ports sometimes being configured incorrectly. (#46)
- Fix log output sometimes not displaying. (#47)
0.1.2 (2014-01-22)
------------------

View File

@@ -1,4 +1,4 @@
from __future__ import unicode_literals
from .service import Service
__version__ = '0.1.2'
__version__ = '0.1.3'

View File

@@ -6,6 +6,7 @@ from itertools import cycle
from .multiplexer import Multiplexer
from . import colors
from .utils import split_buffer
class LogPrinter(object):
@@ -33,7 +34,7 @@ class LogPrinter(object):
prefix = color_fn(container.name + " | ")
# Attach to container before log printer starts running
line_generator = split_buffer(self._attach(container), '\n')
return (prefix + line for line in line_generator)
return (prefix + line.decode('utf-8') for line in line_generator)
def _attach(self, container):
params = {
@@ -44,21 +45,3 @@ class LogPrinter(object):
params.update(self.attach_params)
params = dict((name, 1 if value else 0) for (name, value) in list(params.items()))
return container.attach(**params)
def split_buffer(reader, separator):
"""
Given a generator which yields strings and a separator string,
joins all input, splits on the separator and yields each chunk.
Requires that each input string is decodable as UTF-8.
"""
buffered = ''
for data in reader:
lines = (buffered + data.decode('utf-8')).split(separator)
for line in lines[:-1]:
yield line + separator
if len(lines) > 1:
buffered = lines[-1]
if len(buffered) > 0:
yield buffered

View File

@@ -83,3 +83,28 @@ def mkdir(path, permissions=0o700):
def docker_url():
return os.environ.get('DOCKER_HOST')
def split_buffer(reader, separator):
"""
Given a generator which yields strings and a separator string,
joins all input, splits on the separator and yields each chunk.
Unlike string.split(), each chunk includes the trailing
separator, except for the last one if none was found on the end
of the input.
"""
buffered = str('')
separator = str(separator)
for data in reader:
buffered += data
while True:
index = buffered.find(separator)
if index == -1:
break
yield buffered[:index+1]
buffered = buffered[index+1:]
if len(buffered) > 0:
yield buffered

View File

@@ -172,9 +172,10 @@ class Service(object):
port = str(port)
if ':' in port:
external_port, internal_port = port.split(':', 1)
port_bindings[int(internal_port)] = int(external_port)
else:
port_bindings[int(port)] = None
external_port, internal_port = (None, port)
port_bindings[internal_port] = external_port
volume_bindings = {}
@@ -225,8 +226,8 @@ class Service(object):
port = str(port)
if ':' in port:
port = port.split(':')[-1]
if '/' not in port:
port = "%s/tcp" % port
if '/' in port:
port = tuple(port.split('/'))
ports.append(port)
container_options['ports'] = ports

View File

@@ -20,4 +20,4 @@ docker -d -H unix:///var/run/docker.sock 2>> /dev/null >> /dev/null &
sleep 2
# $init is set by sekexe
cd $(dirname $init)/.. && nosetests
cd $(dirname $init)/.. && nosetests -v

View File

@@ -35,6 +35,7 @@ setup(
url='https://github.com/orchardup/fig',
author='Orchard Laboratories Ltd.',
author_email='hello@orchardup.com',
license='BSD',
packages=find_packages(),
include_package_data=True,
test_suite='nose.collector',

View File

@@ -184,9 +184,14 @@ class ServiceTest(DockerClientTestCase):
def test_start_container_creates_ports(self):
service = self.create_service('web', ports=[8000])
container = service.start_container().inspect()
self.assertIn('8000/tcp', container['HostConfig']['PortBindings'])
self.assertEqual(container['HostConfig']['PortBindings'].keys(), ['8000/tcp'])
self.assertNotEqual(container['HostConfig']['PortBindings']['8000/tcp'][0]['HostPort'], '8000')
def test_start_container_creates_port_with_explicit_protocol(self):
service = self.create_service('web', ports=['8000/udp'])
container = service.start_container().inspect()
self.assertEqual(container['HostConfig']['PortBindings'].keys(), ['8000/udp'])
def test_start_container_creates_fixed_external_ports(self):
service = self.create_service('web', ports=['8000:8000'])
container = service.start_container().inspect()

View File

@@ -0,0 +1,37 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from fig.cli.utils import split_buffer
from . import unittest
class SplitBufferTest(unittest.TestCase):
def test_single_line_chunks(self):
def reader():
yield "abc\n"
yield "def\n"
yield "ghi\n"
self.assertEqual(list(split_buffer(reader(), '\n')), ["abc\n", "def\n", "ghi\n"])
def test_no_end_separator(self):
def reader():
yield "abc\n"
yield "def\n"
yield "ghi"
self.assertEqual(list(split_buffer(reader(), '\n')), ["abc\n", "def\n", "ghi"])
def test_multiple_line_chunk(self):
def reader():
yield "abc\ndef\nghi"
self.assertEqual(list(split_buffer(reader(), '\n')), ["abc\n", "def\n", "ghi"])
def test_chunked_line(self):
def reader():
yield "a"
yield "b"
yield "c"
yield "\n"
yield "d"
self.assertEqual(list(split_buffer(reader(), '\n')), ["abc\n", "d"])