Skip to content

Commit

Permalink
fix(provider): forward proxy variables to core24 build environments
Browse files Browse the repository at this point in the history
Forward `http_proxy`, `https_proxy`, and `no_proxy` to core24 build
environments.

Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal authored and lengau committed Aug 15, 2024
1 parent 07795c0 commit 28da125
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
10 changes: 10 additions & 0 deletions snapcraft/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ def __str__(self) -> str:

CURRENT_BASES = frozenset(BASES - ESM_BASES - LEGACY_BASES)
"""Bases handled by the current snapcraft codebase."""


SNAPCRAFT_ENVIRONMENT_VARIABLES = frozenset(
{
"SNAPCRAFT_BUILD_INFO",
"SNAPCRAFT_IMAGE_INFO",
"SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS",
}
)
"""Snapcraft-specific environment variables."""
17 changes: 7 additions & 10 deletions snapcraft/services/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@
from craft_application import ProviderService
from overrides import overrides

from snapcraft.const import SNAPCRAFT_ENVIRONMENT_VARIABLES


class Provider(ProviderService):
"""Snapcraft specialization of the Lifecycle Service."""

@overrides
def setup(self) -> None:
if build_info := os.getenv("SNAPCRAFT_BUILD_INFO"):
self.environment["SNAPCRAFT_BUILD_INFO"] = build_info
if image_info := os.getenv("SNAPCRAFT_IMAGE_INFO"):
self.environment["SNAPCRAFT_IMAGE_INFO"] = image_info
if experimental_extensions := os.getenv(
"SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS"
):
self.environment["SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS"] = (
experimental_extensions
)
"""Add snapcraft environment variables to the build environment."""
super().setup()
for variable in SNAPCRAFT_ENVIRONMENT_VARIABLES:
if variable in os.environ:
self.environment[variable] = os.environ[variable]
22 changes: 13 additions & 9 deletions tests/unit/services/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@

"""Tests for the Snapcraft provider service."""

from craft_application.services.provider import DEFAULT_FORWARD_ENVIRONMENT_VARIABLES

from snapcraft.const import SNAPCRAFT_ENVIRONMENT_VARIABLES


def test_provider(provider_service, monkeypatch):
monkeypatch.setenv("SNAPCRAFT_BUILD_INFO", "foo")
monkeypatch.setenv("SNAPCRAFT_IMAGE_INFO", "bar")
monkeypatch.setenv("SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS", "baz")
provider_service.setup()
assert provider_service.environment["SNAPCRAFT_BUILD_INFO"] == "foo"
assert provider_service.environment["SNAPCRAFT_IMAGE_INFO"] == "bar"
assert (
provider_service.environment["SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS"]
== "baz"
variables = SNAPCRAFT_ENVIRONMENT_VARIABLES | set(
DEFAULT_FORWARD_ENVIRONMENT_VARIABLES
)
for variable in variables:
monkeypatch.setenv(variable, f"{variable}-test-value")

provider_service.setup()

for variable in variables:
assert provider_service.environment[variable] == f"{variable}-test-value"

0 comments on commit 28da125

Please sign in to comment.