From fab8c8ba1c579c02b9c3af4cf4a730d3b9974ec0 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 6 Mar 2018 01:18:58 -0500 Subject: [PATCH 1/5] Print usage when argv empty --- docker_custodian/docker_autostop.py | 4 ++++ docker_custodian/docker_gc.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docker_custodian/docker_autostop.py b/docker_custodian/docker_autostop.py index 021f60e..780ff40 100644 --- a/docker_custodian/docker_autostop.py +++ b/docker_custodian/docker_autostop.py @@ -95,6 +95,10 @@ def get_opts(args=None): ) opts = parser.parse_args(args=args) + if len(sys.argv) < 2: + parser.print_help() + exit(0) + if not opts.prefix: parser.error("Running with no --prefix will match nothing.") diff --git a/docker_custodian/docker_gc.py b/docker_custodian/docker_gc.py index db7aba9..40dae8d 100644 --- a/docker_custodian/docker_gc.py +++ b/docker_custodian/docker_gc.py @@ -269,6 +269,10 @@ def get_args(args=None): help="Path to a file which contains a list of images to exclude, one " "image tag per line.") + if len(sys.argv) < 2: + parser.print_help() + exit(0) + return parser.parse_args(args=args) From c904aa1d6160ee73ee076b70b60b3bb32ec3976e Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 6 Mar 2018 00:56:43 -0500 Subject: [PATCH 2/5] Update requirements.txt version and use docker instead of docker-py --- requirements.txt | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 35faae8..884a9e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,14 @@ -argparse==1.3.0 -backports.ssl-match-hostname==3.4.0.2 -docker-py==1.7.2 -future==0.14.3 -python-dateutil==2.4.0 -pytimeparse==1.1.2 -requests==2.7.0 -six==1.9.0 -websocket-client==0.32.0 +backports.ssl-match-hostname==3.5.0.1 +certifi==2018.1.18 +chardet==3.0.4 +docker==3.1.0 +docker-pycreds==0.2.2 +future==0.16.0 +idna==2.6 +ipaddress==1.0.19 +python-dateutil==2.6.1 +pytimeparse==1.1.7 +requests==2.18.4 +six==1.11.0 +urllib3==1.22 +websocket-client==0.47.0 From 814b64c11e6fb6fd84a6f269d99bcbfe4795a3b6 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 6 Mar 2018 09:42:10 -0500 Subject: [PATCH 3/5] Port from 'docker-py' library to renamed 'docker' library. Use docker.APIClient as object to interface with. --- docker_custodian/docker_autostop.py | 2 +- docker_custodian/docker_gc.py | 2 +- setup.py | 2 +- tests/conftest.py | 4 ++-- tests/docker_gc_test.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docker_custodian/docker_autostop.py b/docker_custodian/docker_autostop.py index 780ff40..788f1d6 100644 --- a/docker_custodian/docker_autostop.py +++ b/docker_custodian/docker_autostop.py @@ -66,7 +66,7 @@ def main(): stream=sys.stdout) opts = get_opts() - client = docker.Client(version='auto', timeout=opts.timeout) + client = docker.APIClient(version='auto', timeout=opts.timeout) matcher = build_container_matcher(opts.prefix) stop_containers(client, opts.max_run_time, matcher, opts.dry_run) diff --git a/docker_custodian/docker_gc.py b/docker_custodian/docker_gc.py index 40dae8d..6c7f685 100644 --- a/docker_custodian/docker_gc.py +++ b/docker_custodian/docker_gc.py @@ -220,7 +220,7 @@ def main(): stream=sys.stdout) args = get_args() - client = docker.Client(version='auto', timeout=args.timeout) + client = docker.APIClient(version='auto', timeout=args.timeout) if args.max_container_age: cleanup_containers(client, args.max_container_age, args.dry_run) diff --git a/setup.py b/setup.py index 556e8aa..7873542 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( include_package_data=True, install_requires=[ 'python-dateutil', - 'docker-py >= 0.5', + 'docker', 'pytimeparse', ], license="Apache License 2.0", diff --git a/tests/conftest.py b/tests/conftest.py index 2fbc83c..b891cc2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,6 +48,6 @@ def later_time(): @pytest.fixture def mock_client(): - client = mock.create_autospec(docker.Client) - client._version = '1.17' + client = mock.create_autospec(docker.APIClient) + client._version = '1.21' return client diff --git a/tests/docker_gc_test.py b/tests/docker_gc_test.py index b980181..54cbe6f 100644 --- a/tests/docker_gc_test.py +++ b/tests/docker_gc_test.py @@ -466,7 +466,7 @@ def test_build_exclude_set_empty(): def test_main(mock_client): with mock.patch( - 'docker_custodian.docker_gc.docker.Client', + 'docker_custodian.docker_gc.docker.APIClient', return_value=mock_client): with mock.patch( From 8eb165385f7b1859386cf9ed2069dae40b4bf1c9 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 6 Mar 2018 13:02:38 -0500 Subject: [PATCH 4/5] Revert "Print usage when argv empty" This reverts commit fab8c8ba1c579c02b9c3af4cf4a730d3b9974ec0. --- docker_custodian/docker_autostop.py | 4 ---- docker_custodian/docker_gc.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/docker_custodian/docker_autostop.py b/docker_custodian/docker_autostop.py index 788f1d6..b5e847f 100644 --- a/docker_custodian/docker_autostop.py +++ b/docker_custodian/docker_autostop.py @@ -95,10 +95,6 @@ def get_opts(args=None): ) opts = parser.parse_args(args=args) - if len(sys.argv) < 2: - parser.print_help() - exit(0) - if not opts.prefix: parser.error("Running with no --prefix will match nothing.") diff --git a/docker_custodian/docker_gc.py b/docker_custodian/docker_gc.py index 6c7f685..4e57108 100644 --- a/docker_custodian/docker_gc.py +++ b/docker_custodian/docker_gc.py @@ -269,10 +269,6 @@ def get_args(args=None): help="Path to a file which contains a list of images to exclude, one " "image tag per line.") - if len(sys.argv) < 2: - parser.print_help() - exit(0) - return parser.parse_args(args=args) From fc72a150d809b634c711f1c3b1e252666016bf0f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 7 Mar 2018 08:42:04 -0500 Subject: [PATCH 5/5] Instantiate APIClient using defined envars e.g. DOCKER_HOST --- docker_custodian/docker_autostop.py | 5 ++++- docker_custodian/docker_gc.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docker_custodian/docker_autostop.py b/docker_custodian/docker_autostop.py index b5e847f..98d0df8 100644 --- a/docker_custodian/docker_autostop.py +++ b/docker_custodian/docker_autostop.py @@ -13,6 +13,7 @@ import docker.errors import requests.exceptions from docker_custodian.args import timedelta_type +from docker.utils import kwargs_from_env log = logging.getLogger(__name__) @@ -66,7 +67,9 @@ def main(): stream=sys.stdout) opts = get_opts() - client = docker.APIClient(version='auto', timeout=opts.timeout) + client = docker.APIClient(version='auto', + timeout=opts.timeout, + **kwargs_from_env()) matcher = build_container_matcher(opts.prefix) stop_containers(client, opts.max_run_time, matcher, opts.dry_run) diff --git a/docker_custodian/docker_gc.py b/docker_custodian/docker_gc.py index 4e57108..51d0881 100644 --- a/docker_custodian/docker_gc.py +++ b/docker_custodian/docker_gc.py @@ -14,6 +14,7 @@ import docker.errors import requests.exceptions from docker_custodian.args import timedelta_type +from docker.utils import kwargs_from_env log = logging.getLogger(__name__) @@ -220,7 +221,9 @@ def main(): stream=sys.stdout) args = get_args() - client = docker.APIClient(version='auto', timeout=args.timeout) + client = docker.APIClient(version='auto', + timeout=args.timeout, + **kwargs_from_env()) if args.max_container_age: cleanup_containers(client, args.max_container_age, args.dry_run)