20754: Upgrade docker module for docker-cleaner 20754-docker-py-upgrade
authorBrett Smith <brett.smith@curii.com>
Fri, 4 Aug 2023 18:28:18 +0000 (14:28 -0400)
committerBrett Smith <brett.smith@curii.com>
Fri, 4 Aug 2023 18:28:18 +0000 (14:28 -0400)
The immediate motivation is dealing with the bug discussed in the
comments. Upgrading generally seems like a good idea since we've been
pinned at a specific version for so long.

Changing the Docker API version is required by the library: 1.21 is the
oldest version currently supported. Our Go stack is standardized on
1.35, so use that here too.

Arvados-DCO-1.1-Signed-off-by: Brett Smith <brett.smith@curii.com>

services/dockercleaner/arvados_docker/cleaner.py
services/dockercleaner/setup.py
services/dockercleaner/tests/test_cleaner.py

index 2a0e8b9108608df05dd3fe38e55f8311d82747f7..df624698ba4407f7a2a61aacd578eed5ca3c6cee 100755 (executable)
@@ -362,7 +362,7 @@ def main(arguments=sys.argv[1:]):
     config = load_config(arguments)
     configure_logging(config)
     try:
-        run(config, docker.Client(version='1.14'))
+        run(config, docker.APIClient(version='1.35'))
     except KeyboardInterrupt:
         sys.exit(1)
 
index e75afb57138b23c04a927c14d529f134d7946ef2..d5c572f2ed46885231bde9edbb31b980f0b7f5c2 100644 (file)
@@ -37,7 +37,16 @@ setup(name="arvados-docker-cleaner",
           ('share/doc/arvados-docker-cleaner', ['agpl-3.0.txt', 'arvados-docker-cleaner.service']),
       ],
       install_requires=[
-          'docker-py==1.7.2',
+          # The requirements for the docker library broke when requests started
+          # supporting urllib3 2.0.
+          # See <https://github.com/docker/docker-py/issues/3113>.
+          # Make sure we get a version with the bugfix, assuming Python is
+          # recent enough.
+          'docker>=6.1.0; python_version>"3.6"',
+          # If Python is too old, install the latest version we can and pin
+          # urllib3 ourselves.
+          'docker~=5.0; python_version<"3.7"',
+          'urllib3~=1.26; python_version<"3.7"',
           'setuptools',
       ],
       test_suite='tests',
index 961ec2ce4da1c580533712aaf8fb59d52d3f775f..cd03538fcd07f2181b44abef3ed91fb0bb64e8f1 100644 (file)
@@ -394,7 +394,7 @@ class RunTestCase(unittest.TestCase):
         self.assertEqual(event_kwargs[0]['until'], event_kwargs[1]['since'])
 
 
-@mock.patch('docker.Client', name='docker_client')
+@mock.patch('docker.APIClient', name='docker_client')
 @mock.patch('arvados_docker.cleaner.run', name='cleaner_run')
 class MainTestCase(unittest.TestCase):
 
@@ -404,11 +404,9 @@ class MainTestCase(unittest.TestCase):
             cf.flush()
             cleaner.main(['--config', cf.name])
         self.assertEqual(1, docker_client.call_count)
-        # 1.14 is the first version that's well defined, going back to
-        # Docker 1.2, and still supported up to at least Docker 1.9.
-        # See
-        # <https://docs.docker.com/engine/reference/api/docker_remote_api/>.
-        self.assertEqual('1.14',
+        # We are standardized on Docker API version 1.35.
+        # See DockerAPIVersion in lib/crunchrun/docker.go.
+        self.assertEqual('1.35',
                          docker_client.call_args[1].get('version'))
         self.assertEqual(1, run_mock.call_count)
         self.assertIs(run_mock.call_args[0][1], docker_client())