Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building inside podman containers #2659

Merged
merged 5 commits into from Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion snapcraft/cli/env.py
Expand Up @@ -45,7 +45,7 @@ def __init__(self, *, force_provider: str = None) -> None:
"""
if force_provider:
build_provider = force_provider
elif common.is_docker_instance():
elif common.is_process_container():
build_provider = "host"
else:
build_provider = os.environ.get("SNAPCRAFT_BUILD_ENVIRONMENT", "multipass")
Expand Down
7 changes: 5 additions & 2 deletions snapcraft/internal/common.py
Expand Up @@ -42,7 +42,9 @@
_keyringsdir = _DEFAULT_KEYRINGSDIR
_DEFAULT_LEGACY_SNAPCRAFT_DIR = os.path.join(sys.prefix, "legacy_snapcraft")
_legacy_snapcraft_dir = _DEFAULT_LEGACY_SNAPCRAFT_DIR

_DOCKERENV_FILE = "/.dockerenv"
_PODMAN_FILE = "/run/.containerenv"

MAX_CHARACTERS_WRAP = 120

Expand Down Expand Up @@ -124,8 +126,9 @@ def is_snap() -> bool:
return is_snap


def is_docker_instance() -> bool:
return os.path.exists(_DOCKERENV_FILE)
def is_process_container() -> bool:
logger.debug("snapcraft is running in a docker or podman (OCI) container")
return any([os.path.exists(p) for p in (_DOCKERENV_FILE, _PODMAN_FILE)])


def set_plugindir(plugindir):
Expand Down
4 changes: 2 additions & 2 deletions snapcraft/internal/lifecycle/_runner.py
Expand Up @@ -65,12 +65,12 @@ def execute(
"The repo backend is not returning the list of installed packages"
)

if common.is_docker_instance():
if common.is_process_container():
installed_snaps = [] # type: List[str]
logger.warning(
(
"The following snaps are required but not installed as snapcraft "
"is running inside docker: {}.\n"
"is running inside docker or podman container: {}.\n"
"Please ensure the environment is properly setup before continuing.\n"
"Ignore this message if the appropriate measures have already been taken".format(
", ".join(project_config.build_snaps)
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/internal/project_loader/_config.py
Expand Up @@ -226,7 +226,7 @@ def __init__(self, project: project.Project) -> None:
# If the base is already installed by other means, skip its installation.
# But, we should always add it when in a docker environment so
# the creator of said docker image is aware that it is required.
if common.is_docker_instance() or not repo.snaps.SnapPackage.is_snap_installed(
if common.is_process_container() or not repo.snaps.SnapPackage.is_snap_installed(
project.info.base
):
self.build_snaps.add(project.info.base)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lifecycle/test_snap_installation.py
Expand Up @@ -41,7 +41,7 @@ def test_part_with_build_snaps(self, mock_install_build_snaps):

mock_install_build_snaps.assert_called_once_with({"snap1", "snap2"})

@mock.patch("snapcraft.internal.common.is_docker_instance", return_value=True)
@mock.patch("snapcraft.internal.common.is_process_container", return_value=True)
@mock.patch("snapcraft.repo.snaps.install_snaps")
def test_part_with_build_snaps_on_docker(
self, mock_install_build_snaps, mock_docker_instance
Expand All @@ -65,6 +65,6 @@ def test_part_with_build_snaps_on_docker(
self.fake_logger.output,
Contains(
"The following snaps are required but not installed as snapcraft "
"is running inside docker: "
"is running inside docker or podman container: "
),
)
4 changes: 2 additions & 2 deletions tests/unit/test_file_utils.py
Expand Up @@ -374,7 +374,7 @@ def test_get_tool_from_docker_snap_path(self):
self._patch(snap_root)

with mock.patch(
"snapcraft.internal.common.is_docker_instance", return_value=True
"snapcraft.internal.common.is_process_container", return_value=True
):
self.assertThat(
file_utils.get_tool_path("tool-command"),
Expand All @@ -394,7 +394,7 @@ def test_get_tool_from_docker_deb_path(self):
self.addCleanup(patcher.stop)

with mock.patch(
"snapcraft.internal.common.is_docker_instance", return_value=True
"snapcraft.internal.common.is_process_container", return_value=True
):
self.assertThat(
file_utils.get_tool_path("tool-command"),
Expand Down