Skip to content

Commit a1bc7cf

Browse files
committed
Merge pull request #7 from ava-dylang/client-version-mismatch
User declared client version & exit on mismatch.
2 parents b660f21 + 5053ced commit a1bc7cf

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

dockerrotate/main.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
from dateutil import parser
99
from docker import Client
1010
from docker.errors import APIError
11+
from docker.errors import NotFound
1112
from docker.utils import kwargs_from_env
1213

1314

15+
UNIX_SOC_ARGS = {"base_url": 'unix://var/run/docker.sock'}
16+
1417
TEN_SECONDS = timedelta(seconds=10)
1518

1619

@@ -58,6 +61,11 @@ def parse_args():
5861
action="store_true",
5962
help="Do not remove anything",
6063
)
64+
parser.add_argument(
65+
"--client-version",
66+
default=None,
67+
help="Specify client version to use.",
68+
)
6169
return parser.parse_args()
6270

6371

@@ -69,10 +77,20 @@ def make_client(args):
6977
variables (e.g. DOCKER_HOST). This is much simpler than trying to pass
7078
all the possible certificate options through argparse.
7179
"""
72-
if args.use_env:
73-
return Client(**kwargs_from_env(assert_hostname=False))
74-
else:
75-
return Client(base_url='unix://var/run/docker.sock')
80+
kwargs = kwargs_from_env(assert_hostname=False) if args.use_env else UNIX_SOC_ARGS
81+
82+
if args.client_version is not None:
83+
kwargs["version"] = args.client_version
84+
85+
client = Client(**kwargs)
86+
87+
# Verify client can talk to server.
88+
try:
89+
client.version()
90+
except NotFound as error:
91+
raise SystemExit(error) # noqa
92+
93+
return client
7694

7795

7896
def normalize_tag_name(tag):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'nose>=1.3.7',
1818
],
1919
install_requires=[
20-
'docker-py>=0.5.3',
20+
'docker-py>=1.6.0',
2121
'python-dateutil>=2.4.0',
2222
],
2323
tests_require=[

0 commit comments

Comments
 (0)