Repository: exasol/integration-test-docker-environment (language: python)

Issue:
Make sure that all docker function calls use docker credentials if possible
# Background

- On certain CI systems, we ran into a lot of docker hub rate limit issues when not authenticated

# Acceptance Criteria

- All docker pull, build and push function calls use the docker credentials if possible
- We have checked no other calls need these


Discussion / hints:

Fix patch:
diff --git a/doc/changes/changes_0.8.0.md b/doc/changes/changes_0.8.0.md
index 8166842c3..ab5a0cfa1 100644
--- a/doc/changes/changes_0.8.0.md
+++ b/doc/changes/changes_0.8.0.md
@@ -32,6 +32,7 @@ If you need further versions, please open an issue.
  - #146: Port starter scripts from script-languages-container-tool to this project
  - #140: Create or inject SSL Certificates into the Docker-DB
  - #164: Remove test and support for Exasol DB 6.2.x
+ - #162: Make sure that all docker function calls use docker credentials if possible
 
 ## Refactoring:
 


Test patch:
diff --git a/exasol_integration_test_docker_environment/cli/commands/spawn_test_environment.py b/exasol_integration_test_docker_environment/cli/commands/spawn_test_environment.py
index c3ef6dcc0..926f9b255 100644
--- a/exasol_integration_test_docker_environment/cli/commands/spawn_test_environment.py
+++ b/exasol_integration_test_docker_environment/cli/commands/spawn_test_environment.py
@@ -4,12 +4,13 @@
 
 from exasol_integration_test_docker_environment.cli.cli import cli
 from exasol_integration_test_docker_environment.cli.common import add_options, set_build_config, run_task, \
-    generate_root_task
+    set_docker_repository_config, run_task, generate_root_task
 from exasol_integration_test_docker_environment.cli.options.system_options import system_options, \
     output_directory_option, tempory_base_directory_option
 from exasol_integration_test_docker_environment.cli.options.test_environment_options import docker_db_options
 from exasol_integration_test_docker_environment.lib.test_environment.spawn_test_environment_with_docker_db import \
     SpawnTestEnvironmentWithDockerDB
+from exasol_integration_test_docker_environment.cli.options.docker_repository_options import docker_repository_options
 
 
 @cli.command()
@@ -30,6 +31,7 @@
 @click.option('--docker-runtime', type=str, default=None, show_default=True,
               help="The docker runtime used to start all containers")
 @add_options(docker_db_options)
+@add_options(docker_repository_options)
 @add_options([output_directory_option])
 @add_options([tempory_base_directory_option])
 @add_options(system_options)
@@ -44,6 +46,14 @@ def spawn_test_environment(
         docker_runtime: str,
         docker_db_image_version: str,
         docker_db_image_name: str,
+        source_docker_repository_name: str,
+        source_docker_tag_prefix: str,
+        source_docker_username: str,
+        source_docker_password: str,
+        target_docker_repository_name: str,
+        target_docker_tag_prefix: str,
+        target_docker_username: str,
+        target_docker_password: str,
         output_directory: str,
         temporary_base_directory: str,
         workers: int,
@@ -69,6 +79,10 @@ def spawn_test_environment(
                      temporary_base_directory,
                      None,
                      None)
+    set_docker_repository_config(source_docker_password, source_docker_repository_name, source_docker_username,
+                                 source_docker_tag_prefix, "source")
+    set_docker_repository_config(target_docker_password, target_docker_repository_name, target_docker_username,
+                                 target_docker_tag_prefix, "target")
     task_creator = lambda: generate_root_task(task_class=SpawnTestEnvironmentWithDockerDB,
         environment_name=environment_name,
         database_port_forward=str(database_port_forward) if database_port_forward is not None else None,
diff --git a/exasol_integration_test_docker_environment/lib/docker/__init__.py b/exasol_integration_test_docker_environment/lib/docker/__init__.py
index e8f893978..68bdec4c7 100644
--- a/exasol_integration_test_docker_environment/lib/docker/__init__.py
+++ b/exasol_integration_test_docker_environment/lib/docker/__init__.py
@@ -1,5 +1,8 @@
 import docker
 
+from exasol_integration_test_docker_environment.lib.config.docker_config import source_docker_repository_config, \
+    target_docker_repository_config
+
 
 class ContextDockerClient(object):
     def __init__(self, **kwargs):
@@ -7,9 +10,17 @@ def __init__(self, **kwargs):
         self._client = None
 
     def __enter__(self):
+
         self._client = docker.from_env(**self.kwargs)
+        self.login(self._client, source_docker_repository_config())
+        self.login(self._client, target_docker_repository_config())
         return self._client
 
+    def login(self, client: docker.client.DockerClient, docker_repository_config):
+        if docker_repository_config.username is not None and \
+                docker_repository_config.password is not None:
+            client.login(username=docker_repository_config.username, password=docker_repository_config.password)
+
     def __exit__(self, type_, value, traceback):
         if self._client is not None:
             self._client.close()