Skip to content

Commit

Permalink
Add runtime command (podman/docker...) environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Levy authored and eranco74 committed Aug 25, 2021
1 parent 2fb4761 commit 0f19846
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,7 @@ you can override the workspace directory by specifying it in the configuration f
````
workdir: $PWD
````

### Skipper environment variables
Skipper sets environemnt variables to inform the user about the underline system:
CONTAINER_RUNTIME_COMMAND - The container conmmand used to run the skipper container. podman/docker
1 change: 1 addition & 0 deletions skipper/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _run_nested(fqdn_image, environment, command, interactive, name, net, publis
cmd += ['-e', 'SKIPPER_USERNAME=%(user)s' % dict(user=user)]
cmd += ['-e', 'SKIPPER_UID=%(user_id)s' % dict(user_id=user_id)]
cmd += ['-e', 'HOME=%(homedir)s' % dict(homedir=homedir)]
cmd += ['-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command())]

if utils.get_runtime_command() == "docker":
try:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_run_simple_command_nested_network_exist(self, resource_filename_mock, c
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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)),
Expand Down Expand Up @@ -131,6 +132,7 @@ def test_run_simple_command_nested_network_not_exist(self, resource_filename_moc
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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)),
Expand Down Expand Up @@ -176,6 +178,7 @@ def test_run_simple_command_nested_with_env(self, resource_filename_mock, check_
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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)),
Expand Down Expand Up @@ -228,6 +231,7 @@ def test_run_simple_command_nested_with_env_file(
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-e', 'SKIPPER_DOCKER_GID=978',
'-v', get_volume_mapping('%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(
homedir=HOME_DIR)),
Expand Down Expand Up @@ -284,6 +288,7 @@ def test_run_simple_command_nested_with_multiple_env_files(
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-e', 'SKIPPER_DOCKER_GID=978',
'-v', '%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(
homedir=HOME_DIR),
Expand Down Expand Up @@ -335,6 +340,7 @@ def test_run_simple_command_nested_interactive(self, resource_filename_mock,
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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)),
Expand Down Expand Up @@ -378,6 +384,7 @@ def test_run_complex_command_nested(self, resource_filename_mock, check_output_m
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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)),
Expand Down Expand Up @@ -425,6 +432,7 @@ def test_run_complex_command_nested_with_env(self, resource_filename_mock, check
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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)),
Expand Down Expand Up @@ -478,6 +486,7 @@ def test_run_complex_command_nested_with_special_case_verification(self, resourc
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-e', 'SKIPPER_DOCKER_GID=978',
'-v', '%(homedir)s/.netrc:%(homedir)s/.netrc:ro' % dict(homedir=HOME_DIR),
'-v', '%(homedir)s/.gitconfig:%(homedir)s/.gitconfig:ro' % dict(homedir=HOME_DIR),
Expand Down
4 changes: 4 additions & 0 deletions tests/test_runner_podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_run_simple_command_nested_network_exist(self, resource_filename_mock, c
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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:%(homedir)s/.docker/config.json:ro' % dict(homedir=HOME_DIR)),
Expand Down Expand Up @@ -108,6 +109,7 @@ def test_run_simple_command_nested_network_not_exist(self, resource_filename_moc
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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:%(homedir)s/.docker/config.json:ro' % dict(homedir=HOME_DIR)),
Expand Down Expand Up @@ -147,6 +149,7 @@ def test_run_complex_command_nested(self, resource_filename_mock, check_output_m
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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:%(homedir)s/.docker/config.json:ro' % dict(homedir=HOME_DIR)),
Expand Down Expand Up @@ -188,6 +191,7 @@ def test_run_complex_command_nested_with_env(self, resource_filename_mock, check
'-e', 'SKIPPER_USERNAME=testuser',
'-e', 'SKIPPER_UID=%(user_uid)s' % dict(user_uid=USER_ID),
'-e', 'HOME=%(homedir)s' % dict(homedir=HOME_DIR),
'-e', 'CONTAINER_RUNTIME_COMMAND=%(runtime_command)s' % dict(runtime_command=utils.get_runtime_command()),
'-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:%(homedir)s/.docker/config.json:ro' % dict(homedir=HOME_DIR)),
Expand Down

0 comments on commit 0f19846

Please sign in to comment.