Skip to content

Commit d79db52

Browse files
committed
Fix #184 allow buildx on linux hosts
1 parent 9e010ce commit d79db52

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

skipper/runner.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ def handle_volumes_bind_mount(docker_cmd, homedir, volumes, workspace):
147147
f'{homedir}/.gitconfig:{homedir}/.gitconfig:ro'])
148148

149149
# required for docker credentials
150-
docker_config_folder = f'{homedir}/.docker/config.json'
151-
if not any(f'{docker_config_folder}:' in volume for volume in volumes):
152-
_add_path_if_exists(docker_config_folder, f'{DOCKER_CONFIG}/config.json', 'rw', volumes)
150+
suffix = get_docker_config_volume_suffix()
151+
docker_config_volume = f'{homedir}{suffix}'
152+
if not any(f'{docker_config_volume}:' in volume for volume in volumes):
153+
_add_path_if_exists(docker_config_volume, f'{DOCKER_CONFIG}{suffix}', 'rw', volumes)
153154

154155
# required for docker certificates
155156
_add_path_if_exists('/etc/docker', '/etc/docker', 'ro', volumes)
@@ -251,3 +252,10 @@ def _network_exists(net):
251252
cmd = ['network', 'ls', "-f", f"NAME={net}"]
252253
result = utils.run_container_command(cmd)
253254
return net in result
255+
256+
257+
def get_docker_config_volume_suffix():
258+
if sys.platform == "darwin":
259+
return '/config.json'
260+
261+
return ''

tests/test_runner.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def get_volume_mapping(volume_mapping):
3333
return volume_mapping
3434

3535

36+
def get_docker_config_volume():
37+
suffix = runner.get_docker_config_volume_suffix()
38+
return get_volume_mapping(
39+
f'{HOME_DIR}{suffix}:{DOCKER_CONFIG}{suffix}:rw'
40+
)
41+
42+
3643
@mock.patch('skipper.runner._network_exists', mock.MagicMock(autospec=True, return_value=True))
3744
class TestRunner(unittest.TestCase):
3845

@@ -96,8 +103,7 @@ def test_run_simple_command_nested_network_exist(self, resource_filename_mock, c
96103
'-e', 'SKIPPER_DOCKER_GID=978',
97104
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
98105
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
99-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
100-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
106+
'-v', get_docker_config_volume(),
101107
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
102108
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
103109
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -145,8 +151,7 @@ def test_run_simple_command_nested_network_not_exist(self, resource_filename_moc
145151
'-e', 'SKIPPER_DOCKER_GID=978',
146152
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
147153
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
148-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
149-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
154+
'-v', get_docker_config_volume(),
150155
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
151156
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
152157
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -195,8 +200,7 @@ def test_run_simple_command_nested_with_env(self, resource_filename_mock, check_
195200
'-e', 'SKIPPER_DOCKER_GID=978',
196201
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
197202
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
198-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
199-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
203+
'-v', get_docker_config_volume(),
200204
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
201205
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
202206
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -254,8 +258,7 @@ def test_run_simple_command_nested_with_env_file(
254258
homedir=HOME_DIR)),
255259
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(
256260
homedir=HOME_DIR)),
257-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
258-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
261+
'-v', get_docker_config_volume(),
259262
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
260263
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
261264
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -314,8 +317,7 @@ def test_run_simple_command_nested_with_multiple_env_files(
314317
homedir=HOME_DIR),
315318
'-v', '%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(
316319
homedir=HOME_DIR),
317-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
318-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
320+
'-v', get_docker_config_volume(),
319321
'-v', '/etc/docker:/etc/docker:ro',
320322
'-v', '%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR),
321323
'-v', '/var/run/docker.sock:/var/run/docker.sock:rw',
@@ -366,8 +368,7 @@ def test_run_simple_command_nested_interactive(self, resource_filename_mock,
366368
'-e', 'SKIPPER_DOCKER_GID=978',
367369
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
368370
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
369-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
370-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
371+
'-v', get_docker_config_volume(),
371372
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
372373
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
373374
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -414,8 +415,7 @@ def test_run_complex_command_nested(self, resource_filename_mock, check_output_m
414415
'-e', 'SKIPPER_DOCKER_GID=978',
415416
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
416417
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
417-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
418-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
418+
'-v', get_docker_config_volume(),
419419
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
420420
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
421421
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),
@@ -466,8 +466,7 @@ def test_run_complex_command_nested_with_env(self, resource_filename_mock, check
466466
'-e', 'SKIPPER_DOCKER_GID=978',
467467
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
468468
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
469-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
470-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
469+
'-v', get_docker_config_volume(),
471470
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
472471
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
473472
'-v', get_volume_mapping('/var/run/docker.sock:/var/run/docker.sock:rw'),

tests/test_runner_podman.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from skipper import utils
55
from skipper import runner
66
from skipper.runner import get_default_net
7-
from skipper.utils import PODMAN, DOCKER_CONFIG
8-
from tests.test_runner import get_volume_mapping
7+
from tests.test_runner import get_volume_mapping, get_docker_config_volume
98

109
USER_ID = 1000
1110
GROUP_ID = 2000
@@ -86,8 +85,7 @@ def test_run_simple_command_nested_network_exist(self, resource_filename_mock, c
8685
'--group-add', 'keep-groups',
8786
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
8887
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
89-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
90-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
88+
'-v', get_docker_config_volume(),
9189
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
9290
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
9391
'-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -129,8 +127,7 @@ def test_run_simple_command_nested_network_not_exist(self, resource_filename_moc
129127
'--group-add', 'keep-groups',
130128
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
131129
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
132-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
133-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
130+
'-v', get_docker_config_volume(),
134131
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
135132
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
136133
'-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -172,8 +169,7 @@ def test_run_complex_command_nested(self, resource_filename_mock, check_output_m
172169
'--group-add', 'keep-groups',
173170
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
174171
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
175-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
176-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
172+
'-v', get_docker_config_volume(),
177173
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
178174
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
179175
'-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -219,8 +215,7 @@ def test_run_non_existent_unauthorized_volume(self, resource_filename_mock,
219215
'--group-add', 'keep-groups',
220216
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
221217
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
222-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
223-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
218+
'-v', get_docker_config_volume(),
224219
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
225220
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
226221
'-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),
@@ -264,8 +259,7 @@ def test_run_complex_command_nested_with_env(self, resource_filename_mock, check
264259
'--group-add', 'keep-groups',
265260
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR)),
266261
'-v', get_volume_mapping('%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR)),
267-
'-v', get_volume_mapping('%(homedir)s/.docker/config.json:%(docker_config)s/config.json:rw' % dict(
268-
homedir=HOME_DIR, docker_config=DOCKER_CONFIG)),
262+
'-v', get_docker_config_volume(),
269263
'-v', get_volume_mapping('/etc/docker:/etc/docker:ro'),
270264
'-v', get_volume_mapping('%(workdir)s:%(workdir)s:rw' % dict(workdir=WORKDIR)),
271265
'-v', get_volume_mapping('entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:rw'),

0 commit comments

Comments
 (0)