From 0f1984622c7364756d6815c920d23dadea9d000d Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Mon, 23 Aug 2021 13:39:54 +0300 Subject: [PATCH] Add runtime command (podman/docker...) environment variable --- README.md | 4 ++++ skipper/runner.py | 1 + tests/test_runner.py | 9 +++++++++ tests/test_runner_podman.py | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index a991766..5d15f44 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/skipper/runner.py b/skipper/runner.py index 9bf1e8a..e44a126 100644 --- a/skipper/runner.py +++ b/skipper/runner.py @@ -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: diff --git a/tests/test_runner.py b/tests/test_runner.py index 617609f..2d3cd6b 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -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)), @@ -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)), @@ -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)), @@ -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)), @@ -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), @@ -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)), @@ -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)), @@ -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)), @@ -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), diff --git a/tests/test_runner_podman.py b/tests/test_runner_podman.py index bd612d8..5b3ebd8 100644 --- a/tests/test_runner_podman.py +++ b/tests/test_runner_podman.py @@ -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)), @@ -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)), @@ -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)), @@ -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)),