|
12 | 12 |
|
13 | 13 | DEFAULT_CONTAINER_TMPFS_SIZE_MB = 6000
|
14 | 14 |
|
| 15 | +CONTAINER_PROXY_MODE = os.environ.get( |
| 16 | + "CF_FEEDSTOCK_OPS_CONTAINER_PROXY_MODE", "false" |
| 17 | +).lower() in ("yes", "true", "t", "1") |
| 18 | +""" |
| 19 | +Whether to use a proxy that is locally configured for all requests inside the container. |
| 20 | +Set the environment variable `CF_FEEDSTOCK_OPS_CONTAINER_PROXY_MODE` to 'true' to enable this feature. |
| 21 | +""" |
| 22 | + |
| 23 | +PROXY_IN_CONTAINER = os.environ.get( |
| 24 | + "CF_FEEDSTOCK_OPS_PROXY_IN_CONTAINER", "http://host.docker.internal:8080" |
| 25 | +) |
| 26 | +""" |
| 27 | +The hostname of the proxy to use in the container. |
| 28 | +The default value of 'http://host.docker.internal:8080' is the default value for Docker Desktop on Windows and macOS. |
| 29 | +It also works for OrbStack. |
| 30 | +
|
| 31 | +For podman, use http://host.containers.internal:8080. |
| 32 | +For GitHub Actions, use http://172.17.0.1:8080, see https://stackoverflow.com/a/65505308 |
| 33 | +""" |
| 34 | + |
15 | 35 |
|
16 | 36 | def get_default_container_name():
|
17 | 37 | """Get the default container name for feedstock ops.
|
@@ -97,6 +117,28 @@ def get_default_log_level_args(logger):
|
97 | 117 | ]
|
98 | 118 |
|
99 | 119 |
|
| 120 | +def _get_proxy_mode_container_args(): |
| 121 | + if not CONTAINER_PROXY_MODE: |
| 122 | + return [] |
| 123 | + assert os.environ["SSL_CERT_FILE"] == os.environ["REQUESTS_CA_BUNDLE"] |
| 124 | + return [ |
| 125 | + "-e", |
| 126 | + f"http_proxy={PROXY_IN_CONTAINER}", |
| 127 | + "-e", |
| 128 | + f"https_proxy={PROXY_IN_CONTAINER}", |
| 129 | + "-e", |
| 130 | + f"no_proxy={os.environ.get('no_proxy', '')}", |
| 131 | + "-e", |
| 132 | + "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt", |
| 133 | + "-e", |
| 134 | + "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt", |
| 135 | + "--network", |
| 136 | + "host", |
| 137 | + "-v", |
| 138 | + f"{os.environ['SSL_CERT_FILE']}:/etc/ssl/certs/ca-certificates.crt:ro", |
| 139 | + ] |
| 140 | + |
| 141 | + |
100 | 142 | def run_container_operation(
|
101 | 143 | args: Iterable[str],
|
102 | 144 | json_loads: Callable = json.loads,
|
@@ -146,6 +188,7 @@ def run_container_operation(
|
146 | 188 | cmd = [
|
147 | 189 | *get_default_container_run_args(tmpfs_size_mb=tmpfs_size_mb),
|
148 | 190 | *mnt_args,
|
| 191 | + *_get_proxy_mode_container_args(), |
149 | 192 | *extra_container_args,
|
150 | 193 | get_default_container_name(),
|
151 | 194 | *args,
|
|
0 commit comments