Repository: Stratoscale/skipper

Issue:
Fix buildx for linux hosts

Discussion:

Patch:
diff --git a/skipper/runner.py b/skipper/runner.py
index 5cd63bc..029054e 100644
--- a/skipper/runner.py
+++ b/skipper/runner.py
@@ -147,9 +147,10 @@ def handle_volumes_bind_mount(docker_cmd, homedir, volumes, workspace):
                     f'{homedir}/.gitconfig:{homedir}/.gitconfig:ro'])
 
     # required for docker credentials
-    docker_config_folder = f'{homedir}/.docker/config.json'
-    if not any(f'{docker_config_folder}:' in volume for volume in volumes):
-        _add_path_if_exists(docker_config_folder, f'{DOCKER_CONFIG}/config.json', 'rw', volumes)
+    suffix = get_docker_config_volume_suffix()
+    docker_config_volume = f'{homedir}{suffix}'
+    if not any(f'{docker_config_volume}:' in volume for volume in volumes):
+        _add_path_if_exists(docker_config_volume, f'{DOCKER_CONFIG}{suffix}', 'rw', volumes)
 
     # required for docker certificates
     _add_path_if_exists('/etc/docker', '/etc/docker', 'ro', volumes)
@@ -251,3 +252,10 @@ def _network_exists(net):
     cmd = ['network', 'ls', "-f", f"NAME={net}"]
     result = utils.run_container_command(cmd)
     return net in result
+
+
+def get_docker_config_volume_suffix():
+    if sys.platform == "darwin":
+        return '/config.json'
+
+    return ''


Test patch:
diff --git a/tests/test_runner.py b/tests/test_runner.py
index 969f00a..5f83fcc 100644
--- a/tests/test_runner.py
+++ b/tests/test_runner.py
@@ -33,6 +33,13 @@ def get_volume_mapping(volume_mapping):
     return volume_mapping
 
 
+def get_docker_config_volume():
+    suffix = runner.get_docker_config_volume_suffix()
+    return get_volume_mapping(
+        f'{HOME_DIR}{suffix}:{DOCKER_CONFIG}{suffix}:rw'
+    )
+
+
 @mock.patch('skipper.runner._network_exists', mock.MagicMock(autospec=True, return_value=True))
 class TestRunner(unittest.TestCase):
 
@@ -96,8 +103,7 @@ class TestRunner(unittest.TestCase):
             '-e', 'SKIPPER_DOCKER_GID=978',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -145,8 +151,7 @@ class TestRunner(unittest.TestCase):
             '-e', 'SKIPPER_DOCKER_GID=978',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -195,8 +200,7 @@ class TestRunner(unittest.TestCase):
             '-e', 'SKIPPER_DOCKER_GID=978',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -254,8 +258,7 @@ class TestRunner(unittest.TestCase):
                 homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(
                 homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -314,8 +317,7 @@ class TestRunner(unittest.TestCase):
                 homedir=HOME_DIR),
             '-v', '%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(
                 homedir=HOME_DIR),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', '/etc/docker:/etc/docker:ro',
             '-v', '%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR),
             '-v', '/var/run/docker.sock:/var/run/docker.sock:rw',
@@ -366,8 +368,7 @@ class TestRunner(unittest.TestCase):
             '-e', 'SKIPPER_DOCKER_GID=978',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -414,8 +415,7 @@ class TestRunner(unittest.TestCase):
             '-e', 'SKIPPER_DOCKER_GID=978',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -466,8 +466,7 @@ class TestRunner(unittest.TestCase):
             '-e', 'SKIPPER_DOCKER_GID=978',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
diff --git a/tests/test_runner_podman.py b/tests/test_runner_podman.py
index 0105936..8432cb1 100644
--- a/tests/test_runner_podman.py
+++ b/tests/test_runner_podman.py
@@ -4,8 +4,7 @@ import mock
 from skipper import utils
 from skipper import runner
 from skipper.runner import get_default_net
-from skipper.utils import PODMAN, DOCKER_CONFIG
-from tests.test_runner import get_volume_mapping
+from tests.test_runner import get_volume_mapping, get_docker_config_volume
 
 USER_ID = 1000
 GROUP_ID = 2000
@@ -86,8 +85,7 @@ class TestRunnerPodman(unittest.TestCase):
             '--group-add', 'keep-groups',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -129,8 +127,7 @@ class TestRunnerPodman(unittest.TestCase):
             '--group-add', 'keep-groups',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -172,8 +169,7 @@ class TestRunnerPodman(unittest.TestCase):
             '--group-add', 'keep-groups',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -219,8 +215,7 @@ class TestRunnerPodman(unittest.TestCase):
             '--group-add', 'keep-groups',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -264,8 +259,7 @@ class TestRunnerPodman(unittest.TestCase):
             '--group-add', 'keep-groups',
             '-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
             '-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
-            '-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
-                homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
+            '-v', get_docker_config_volume(),
             '-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
             '-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
             '-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),