Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli / main] Support allocating ports at via run command #251

Conversation

philipkimmey
Copy link

No description provided.

@philipkimmey
Copy link
Author

Sorry, needed to split this out of my master branch so I can push out a few additional changes.

See #250 for related discussion.

@philipkimmey
Copy link
Author

-P seems like a reasonable change to avoid confusion.

A -p would definitely be nice, but I'm not going to pursue that for now in this branch.

I'll add tests too, though I'm not actually able to get the test suite to pass - is there something more I need to do other than:

$ virtualenv venv
$ source venv/bin/active
$ pip install -r requirements.txt
$ pip install -r requirements-dev.txt
$ script/test

(I'll report back with test results when it finishes - it seems to take well over an hour to complete the test suite running the above set of commands.)

@philipkimmey
Copy link
Author

Here's my test run output for the commands above:

FFF....................EE.....................................
======================================================================
ERROR: test_start_container_creates_fixed_external_ports (tests.integration.service_test.ServiceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/philip/Projects/fig-src/tests/integration/service_test.py", line 224, in test_start_container_creates_fixed_external_ports
    container = service.start_container().inspect()
  File "/home/philip/Projects/fig-src/fig/service.py", line 238, in start_container
    privileged=privileged,
  File "/home/philip/Projects/fig-src/fig/container.py", line 111, in start
    return self.client.start(self.id, **options)
  File "/home/philip/Projects/fig-src/fig/packages/docker/client.py", line 731, in start
    self._raise_for_status(res)
  File "/home/philip/Projects/fig-src/fig/packages/docker/client.py", line 81, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
APIError: 500 Server Error: Internal Server Error ("Cannot start container 970f6a4fa9fa4f4a9be31d6e773a7d5886c917a84ac15208f0d6f22ee64614dd: listen tcp 0.0.0.0:8000: bind: address already in use")
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/121c8ad707a81a026df54ad6514a1c1901e91bbc6d06267bd3a954c5d97c34b9/kill HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "DELETE /run/docker.sock/v1.9/containers/121c8ad707a81a026df54ad6514a1c1901e91bbc6d06267bd3a954c5d97c34b9?link=False&v=False HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/images/json?only_ids=0&all=0 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/create?name=figtest_web_1 HTTP/1.1" 201 90
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/970f6a4fa9fa4f4a9be31d6e773a7d5886c917a84ac15208f0d6f22ee64614dd/json HTTP/1.1" 200 1280
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/970f6a4fa9fa4f4a9be31d6e773a7d5886c917a84ac15208f0d6f22ee64614dd/start HTTP/1.1" 500 143
--------------------- >> end captured logging << ---------------------

======================================================================
ERROR: test_start_container_creates_fixed_external_ports_when_it_is_different_to_internal_port (tests.integration.service_test.ServiceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/philip/Projects/fig-src/tests/integration/service_test.py", line 230, in test_start_container_creates_fixed_external_ports_when_it_is_different_to_internal_port
    container = service.start_container().inspect()
  File "/home/philip/Projects/fig-src/fig/service.py", line 238, in start_container
    privileged=privileged,
  File "/home/philip/Projects/fig-src/fig/container.py", line 111, in start
    return self.client.start(self.id, **options)
  File "/home/philip/Projects/fig-src/fig/packages/docker/client.py", line 731, in start
    self._raise_for_status(res)
  File "/home/philip/Projects/fig-src/fig/packages/docker/client.py", line 81, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
APIError: 500 Server Error: Internal Server Error ("Cannot start container 69bc71317ccb8c1b40b54e7323386b9b07c556760a850c73b4f2408c22cc819b: listen tcp 0.0.0.0:8001: bind: address already in use")
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/970f6a4fa9fa4f4a9be31d6e773a7d5886c917a84ac15208f0d6f22ee64614dd/kill HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "DELETE /run/docker.sock/v1.9/containers/970f6a4fa9fa4f4a9be31d6e773a7d5886c917a84ac15208f0d6f22ee64614dd?link=False&v=False HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/images/json?only_ids=0&all=0 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/create?name=figtest_web_1 HTTP/1.1" 201 90
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/69bc71317ccb8c1b40b54e7323386b9b07c556760a850c73b4f2408c22cc819b/json HTTP/1.1" 200 1280
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/69bc71317ccb8c1b40b54e7323386b9b07c556760a850c73b4f2408c22cc819b/start HTTP/1.1" 500 143
--------------------- >> end captured logging << ---------------------

======================================================================
FAIL: test_ps (tests.integration.cli_test.CLITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/philip/Projects/fig-src/venv/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/philip/Projects/fig-src/tests/integration/cli_test.py", line 22, in test_ps
    self.assertIn('fig_simple_1', mock_stdout.getvalue())
AssertionError: u'fig_simple_1' not found in u'     Name            Command       State    Ports \n-------------------------------------------------\nfigsrc_simple_1   /bin/sleep 300   Exit 0         \n'
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/images/create?tag=latest&fromImage=ubuntu HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/images/json?only_ids=0&all=0 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/create?name=figsrc_simple_1 HTTP/1.1" 201 90
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/1a9eae18733d75c27ed20906462a51fc9b7685b94283c1b7b2dd5d228259ad41/json HTTP/1.1" 200 1271
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=0&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=0&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/1a9eae18733d75c27ed20906462a51fc9b7685b94283c1b7b2dd5d228259ad41/json HTTP/1.1" 200 1271
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/1a9eae18733d75c27ed20906462a51fc9b7685b94283c1b7b2dd5d228259ad41/json HTTP/1.1" 200 1271
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/1a9eae18733d75c27ed20906462a51fc9b7685b94283c1b7b2dd5d228259ad41/json HTTP/1.1" 200 1271
--------------------- >> end captured logging << ---------------------

======================================================================
FAIL: test_ps_alternate_figfile (tests.integration.cli_test.CLITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/philip/Projects/fig-src/venv/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/philip/Projects/fig-src/tests/integration/cli_test.py", line 44, in test_ps_alternate_figfile
    self.assertIn('fig_yetanother_1', output)
AssertionError: u'fig_yetanother_1' not found in u'       Name              Command       State   Ports \n----------------------------------------------------\nfigsrc_yetanother_1   /bin/sleep 300   Up            \n'
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/images/json?only_ids=0&all=0 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
fig.service: INFO: Creating figsrc_yetanother_1...
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/create?name=figsrc_yetanother_1 HTTP/1.1" 201 90
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/a778be0eba73114219a6a4d2818072ac878b87e73b9e5061c90809fa435db90e/json HTTP/1.1" 200 1275
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/a778be0eba73114219a6a4d2818072ac878b87e73b9e5061c90809fa435db90e/start HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=0&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/a778be0eba73114219a6a4d2818072ac878b87e73b9e5061c90809fa435db90e/json HTTP/1.1" 200 1624
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/a778be0eba73114219a6a4d2818072ac878b87e73b9e5061c90809fa435db90e/json HTTP/1.1" 200 1624
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/a778be0eba73114219a6a4d2818072ac878b87e73b9e5061c90809fa435db90e/json HTTP/1.1" 200 1624
--------------------- >> end captured logging << ---------------------

======================================================================
FAIL: test_ps_default_figfile (tests.integration.cli_test.CLITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/philip/Projects/fig-src/venv/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/philip/Projects/fig-src/tests/integration/cli_test.py", line 31, in test_ps_default_figfile
    self.assertIn('fig_simple_1', output)
AssertionError: u'fig_simple_1' not found in u'      Name            Command       State   Ports \n-------------------------------------------------\nfigsrc_simple_1    /bin/sleep 300   Up            \nfigsrc_another_1   /bin/sleep 300   Up            \n'
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/images/json?only_ids=0&all=0 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
fig.service: INFO: Creating figsrc_simple_1...
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/create?name=figsrc_simple_1 HTTP/1.1" 201 90
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/fec8f0926f78a027c1ddb7aafe7efb7946aa9428746c8014ce295975c19beaa4/json HTTP/1.1" 200 1271
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/fec8f0926f78a027c1ddb7aafe7efb7946aa9428746c8014ce295975c19beaa4/start HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
fig.service: INFO: Creating figsrc_another_1...
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/create?name=figsrc_another_1 HTTP/1.1" 201 90
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/5c6f768a68d071b527d92f8905c1f1cb4d7b63fc476a30e98bfe2d7810633f51/json HTTP/1.1" 200 1272
requests.packages.urllib3.connectionpool: DEBUG: "POST /run/docker.sock/v1.9/containers/5c6f768a68d071b527d92f8905c1f1cb4d7b63fc476a30e98bfe2d7810633f51/start HTTP/1.1" 204 0
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=1&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=0&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/json?all=0&limit=-1&trunc_cmd=1 HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/fec8f0926f78a027c1ddb7aafe7efb7946aa9428746c8014ce295975c19beaa4/json HTTP/1.1" 200 1620
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/fec8f0926f78a027c1ddb7aafe7efb7946aa9428746c8014ce295975c19beaa4/json HTTP/1.1" 200 1620
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/fec8f0926f78a027c1ddb7aafe7efb7946aa9428746c8014ce295975c19beaa4/json HTTP/1.1" 200 1620
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/5c6f768a68d071b527d92f8905c1f1cb4d7b63fc476a30e98bfe2d7810633f51/json HTTP/1.1" 200 1621
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/5c6f768a68d071b527d92f8905c1f1cb4d7b63fc476a30e98bfe2d7810633f51/json HTTP/1.1" 200 1621
requests.packages.urllib3.connectionpool: DEBUG: "GET /run/docker.sock/v1.9/containers/5c6f768a68d071b527d92f8905c1f1cb4d7b63fc476a30e98bfe2d7810633f51/json HTTP/1.1" 200 1621
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 62 tests in 101.249s

@aanand
Copy link

aanand commented Jun 11, 2014

Looks like port conflicts. Do you have anything else running, in Docker or otherwise?

@bfirsh
Copy link

bfirsh commented Jun 11, 2014

Thanks for this, Philip! This looks really great.

What version of Docker are you running? You need Docker 0.11 or 1.0.0.

@philipkimmey
Copy link
Author

Whoops, it was some other services eating ports combined with the test suite assuming the containing folder is named fig (I'd named it fig-src).

@bfirsh
Copy link

bfirsh commented Jun 12, 2014

D'oh. Sorry about that. #45's fault I guess.

@d11wtq
Copy link

d11wtq commented Jul 27, 2014

Hey @philipkimmey this looks awesome thanks, but we really need the tests before we can merge it. Are you still interested in adding the tests and getting this merged?

@bfirsh
Copy link

bfirsh commented Jul 28, 2014

Should be -P too.

@ctolsen
Copy link

ctolsen commented Sep 12, 2014

It's been a long while and this seems to have good support – any news on getting this in? Can I help somehow?

@bfirsh
Copy link

bfirsh commented Sep 12, 2014

Almost there! 3 things:

  1. -p needs to be renamed to something else because we want to use -p to allocate ports in the same way as docker run. I think I'd prefer a long option (e.g. --service-ports or something better) and transition to a short option if it turns out the option is used a lot.
  2. Docs
  3. Tests

@philipkimmey
Copy link
Author

Yeah I'm sorry guys, haven't had a chance to return to this one - I'll attempt to pick it back up this weekend though I'm not sure if I'll get to it realistically.

@bfirsh
Copy link

bfirsh commented Oct 28, 2014

Another thing worth thinking about is how this relates to the -P,--publish-all option in docker run. Is it confusing that the same option does two different things? Would we ever want both of these options?

@dnephin
Copy link

dnephin commented Dec 3, 2014

This looks to be about the same idea as #485 with just a different name for the flag. #485 also has tests so I'm inclined to favor that PR.

We should get one into the next release.

@philipkimmey
Copy link
Author

#485 looks more robust for sure - looking forward to that making it into master!

@pikeas
Copy link

pikeas commented Jan 6, 2015

This needs a mention on http://www.fig.sh/cli.html

@aanand
Copy link

aanand commented Jan 6, 2015

@pikeas #485 includes documentation updates; it just hasn't been released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants