|
13 | 13 | _CONTAINER_HOME = "/home/user/mounted_home" |
14 | 14 |
|
15 | 15 | # CLI tools we can try to use to run our container, in decreasing order of preference |
16 | | -COMPATIBLE_CLI_TOOLS = ["podman", "docker"] |
| 16 | +if sys_utils.is_mac(): |
| 17 | + # Prefer Podman because Docker Desktop isn't always free |
| 18 | + COMPATIBLE_CLI_TOOLS = ["podman", "docker"] |
| 19 | +else: |
| 20 | + # On Linux, Docker Engine (free) can be obtained without Docker Desktop, and it works better |
| 21 | + COMPATIBLE_CLI_TOOLS = ["docker", "podman"] |
17 | 22 |
|
18 | 23 |
|
19 | 24 | def get_build_dir(build_dir=None, repo_root=None, version=None): |
@@ -81,6 +86,24 @@ def get_container_cli_tool(): |
81 | 86 | raise RuntimeError(f"No compatible container software found: {', '.join(COMPATIBLE_CLI_TOOLS)}") |
82 | 87 |
|
83 | 88 |
|
| 89 | +def get_mount_arg(container_mountpoint, container_cli_tool=None): |
| 90 | + """ |
| 91 | + Get the Podman/Docker mount argument depending on which we're using and whether we're on Mac |
| 92 | + """ |
| 93 | + if container_cli_tool is None: |
| 94 | + container_cli_tool = get_container_cli_tool() |
| 95 | + |
| 96 | + # This is preferred for performance reasons (at least on Mac) |
| 97 | + mount_option = "--mount" |
| 98 | + mount_arg = f"type=bind,source={container_mountpoint},target={_CONTAINER_HOME}" |
| 99 | + |
| 100 | + # This fallback is needed for Podman on Linux machines, |
| 101 | + if container_cli_tool == "podman" and not sys_utils.is_mac(): |
| 102 | + mount_option = "-v" |
| 103 | + mount_arg = f"{container_mountpoint}:{_CONTAINER_HOME}:U" |
| 104 | + return mount_option, mount_arg |
| 105 | + |
| 106 | + |
84 | 107 | def get_build_command( |
85 | 108 | *, |
86 | 109 | build_dir, |
@@ -157,15 +180,18 @@ def get_build_command( |
157 | 180 | if container_cli_tool is None: |
158 | 181 | container_cli_tool = get_container_cli_tool() |
159 | 182 |
|
| 183 | + # Get argument for mounting/binding |
| 184 | + mount_option, mount_arg = get_mount_arg(container_mountpoint, container_cli_tool) |
| 185 | + |
160 | 186 | container_command = [ |
161 | 187 | container_cli_tool, |
162 | 188 | "run", |
163 | 189 | "--name", |
164 | 190 | container_name, |
165 | 191 | "--user", |
166 | 192 | f"{uid}:{gid}", |
167 | | - "-v", |
168 | | - f"{container_mountpoint}:{_CONTAINER_HOME}:U", |
| 193 | + mount_option, |
| 194 | + mount_arg, |
169 | 195 | "--workdir", |
170 | 196 | container_workdir, |
171 | 197 | "-t", # "-t" is needed for colorful output |
|
0 commit comments