Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ name: Integration tests
on:
pull_request:
schedule:
- cron: "0 15 * * SAT"
- cron: "0 15 * * SAT"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number ||
github.ref }}
cancel-in-progress: true

jobs:
integration-tests:
uses:
canonical/operator-workflows/.github/workflows/integration_test.yaml@main
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@test/get-workflow-version-action
secrets: inherit
with:
juju-channel: 3.6/stable
Expand All @@ -28,5 +27,5 @@ jobs:
allure-report:
if: ${{ !cancelled() && github.event_name == 'schedule' }}
needs:
- integration-tests
- integration-tests
uses: canonical/operator-workflows/.github/workflows/allure_report.yaml@main
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

<!-- vale Canonical.007-Headings-sentence-case = NO -->

## [#213 Fix proxy setup]
* Fix proxy setup for image-relation joined hook.

## [#219 Use Juju secrets](https://github.com/canonical/github-runner-image-builder-operator/pull/219) (2026-04-17)
* Add new `openstack-password-secret` configuration option to securely store OpenStack passwords using Juju secrets.
* Deprecated `openstack-password` configuration option (still supported for backward compatibility).
Expand Down
12 changes: 6 additions & 6 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _on_upgrade_charm(self, _: ops.UpgradeCharmEvent) -> None:
def _on_config_changed(self, _: ops.ConfigChangedEvent) -> None:
"""Handle charm configuration change events."""
builder_config_state = state.BuilderConfig.from_charm(charm=self)
self._setup_proxy_environment(builder_config_state.proxy)
self.setup_proxy_environment(builder_config_state.proxy)
if not self._is_any_image_relation_ready(cloud_config=builder_config_state.cloud_config):
return
# The following lines should be covered by integration tests.
Expand All @@ -119,7 +119,7 @@ def _on_config_changed(self, _: ops.ConfigChangedEvent) -> None:
def _on_image_relation_changed(self, evt: ops.RelationChangedEvent) -> None:
"""Handle charm image relation changed event."""
builder_config_state = state.BuilderConfig.from_charm(charm=self)
self._setup_proxy_environment(builder_config_state.proxy)
self.setup_proxy_environment(builder_config_state.proxy)
if not evt.unit:
logger.info("No unit in image relation changed event. Skipping image building.")
return
Expand Down Expand Up @@ -158,7 +158,7 @@ def _on_image_relation_changed(self, evt: ops.RelationChangedEvent) -> None:
def _on_run(self, _: RunEvent) -> None:
"""Handle the run event."""
builder_config_state = state.BuilderConfig.from_charm(charm=self)
self._setup_proxy_environment(builder_config_state.proxy)
self.setup_proxy_environment(builder_config_state.proxy)
if not self._is_any_image_relation_ready(cloud_config=builder_config_state.cloud_config):
return
# The following line should be covered by the integration test.
Expand All @@ -172,14 +172,14 @@ def _on_run_action(self, event: ops.ActionEvent) -> None:
event: The run action event.
"""
builder_config_state = state.BuilderConfig.from_charm(charm=self)
self._setup_proxy_environment(builder_config_state.proxy)
self.setup_proxy_environment(builder_config_state.proxy)
if not self._is_any_image_relation_ready(cloud_config=builder_config_state.cloud_config):
event.fail("Image relation not yet ready.")
return
# The following line should be covered by the integration test.
self._run() # pragma: nocover

def _setup_proxy_environment(self, proxy_config: state.ProxyConfig | None) -> None:
def setup_proxy_environment(self, proxy_config: state.ProxyConfig | None) -> None:
"""Set up proxy environment variables.

Args:
Expand All @@ -197,7 +197,7 @@ def _setup_builder(self) -> None:
"""Set up the builder application."""
builder_config_state = state.BuilderConfig.from_charm(charm=self)

self._setup_proxy_environment(builder_config_state.proxy)
self.setup_proxy_environment(builder_config_state.proxy)

builder.initialize(
app_init_config=builder.ApplicationInitializationConfig(
Expand Down
8 changes: 6 additions & 2 deletions src/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import json
import logging
from collections import defaultdict
from typing import Mapping, TypedDict, cast
from typing import TYPE_CHECKING, Mapping, TypedDict, cast

import ops

import builder
import charm_utils
import state

if TYPE_CHECKING:
from charm import GithubRunnerImageBuilderCharm

logger = logging.getLogger(__name__)


Expand All @@ -34,7 +37,7 @@ class ImageRelationData(TypedDict, total=False):
class Observer(ops.Object):
"""The image relation observer."""

def __init__(self, charm: ops.CharmBase):
def __init__(self, charm: "GithubRunnerImageBuilderCharm"):
"""Initialize the observer and register event handlers.

Args:
Expand All @@ -55,6 +58,7 @@ def _on_image_relation_joined(self, event: ops.RelationJoinedEvent) -> None:
event: The event emitted when a relation is joined.
"""
build_config = state.BuilderConfig.from_charm(charm=self.charm)
self.charm.setup_proxy_environment(build_config.proxy)
proxy = state.ProxyConfig.from_env()
if not build_config.cloud_config.upload_cloud_ids:
self.model.unit.status = ops.BlockedStatus(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_setup_proxy_environment_with_proxy_config(
no_proxy="localhost,127.0.0.1",
)

charm._setup_proxy_environment(proxy_config)
charm.setup_proxy_environment(proxy_config)

assert os.environ["http_proxy"] == "http://proxy.example.com:8080"
assert os.environ["https_proxy"] == "https://proxy.example.com:8443"
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def test__on_image_relation_joined(
act: when _on_image_relation_joined hook is fired.
assert: update_relation_data is called.
"""
monkeypatch.setattr(state.BuilderConfig, "from_charm", MagicMock())
mock_build_config = MagicMock()
mock_build_config.proxy = None
monkeypatch.setattr(
state.BuilderConfig, "from_charm", MagicMock(return_value=mock_build_config)
)
monkeypatch.setattr(state.CloudsAuthConfig, "from_unit_relation_data", MagicMock())
monkeypatch.setattr(builder, "install_clouds_yaml", MagicMock())
monkeypatch.setattr(builder, "get_latest_images", MagicMock(return_value="test-id"))
Expand Down
Loading