Skip to content

Commit

Permalink
fix(flask): use rustup snap (#1744)
Browse files Browse the repository at this point in the history
A new update to a flask dependency requires a more recent version of
rustc than is available in the jammy repos.
This works around that by using the same rustup snap as the craft-parts
rust plugin

Fixes #1743

Spread test failure is fixed in
#1749
  • Loading branch information
lengau authored Jul 22, 2024
1 parent 8023ec9 commit 3b05ba5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
14 changes: 7 additions & 7 deletions charmcraft/extensions/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ def _get_root_snippet(self) -> dict[str, Any]:
"grafana-dashboard": {"interface": "grafana_dashboard"},
},
"config": {"options": {**self._WEBSERVER_OPTIONS, **self.options}},
"parts": {"charm": {"plugin": "charm", "source": "."}},
"parts": {
"charm": {
"plugin": "charm",
"source": ".",
"build-snaps": ["rustup"], # Needed to build pydantic.
}
},
}

@override
Expand Down Expand Up @@ -225,12 +231,6 @@ def is_experimental(base: tuple[str, ...] | None) -> bool: # noqa: ARG004
"""Check if the extension is in an experimental state."""
return False

@override
def get_parts_snippet(self) -> dict[str, Any]:
"""Return the parts to add to parts."""
# rust is needed to build pydantic-core, a dependency of flask.
return {"flask-framework/rust-deps": {"plugin": "nil", "build-packages": ["cargo"]}}


class DjangoFramework(_GunicornBase):
"""Extension for 12-factor Django applications."""
Expand Down
11 changes: 7 additions & 4 deletions tests/extensions/test_gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def flask_input_yaml_fixture():
"options": {**FlaskFramework.options, **FlaskFramework._WEBSERVER_OPTIONS}
},
"parts": {
"charm": {"plugin": "charm", "source": "."},
"flask-framework/rust-deps": {"plugin": "nil", "build-packages": ["cargo"]},
"charm": {"plugin": "charm", "source": ".", "build-snaps": ["rustup"]},
},
"peers": {"secret-storage": {"interface": "secret-storage"}},
"provides": {
Expand Down Expand Up @@ -121,7 +120,7 @@ def flask_input_yaml_fixture():
"config": {
"options": {**DjangoFramework.options, **DjangoFramework._WEBSERVER_OPTIONS}
},
"parts": {"charm": {"plugin": "charm", "source": "."}},
"parts": {"charm": {"plugin": "charm", "source": ".", "build-snaps": ["rustup"]}},
"peers": {"secret-storage": {"interface": "secret-storage"}},
"provides": {
"metrics-endpoint": {"interface": "prometheus_scrape"},
Expand Down Expand Up @@ -255,4 +254,8 @@ def test_handle_charm_part(flask_input_yaml, tmp_path):
apply_extensions(tmp_path, flask_input_yaml)
del flask_input_yaml["parts"]
applied = apply_extensions(tmp_path, flask_input_yaml)
assert applied["parts"]["charm"] == {"plugin": "charm", "source": "."}
assert applied["parts"]["charm"] == {
"plugin": "charm",
"source": ".",
"build-snaps": ["rustup"],
}
8 changes: 5 additions & 3 deletions tests/spread/commands/init-flask-framework/task.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
summary: test charmcraft init with flask-framework profile
priority: 500 # This builds pydantic, so do it early
kill-timeout: 75m # Because it builds pydantic, it takes a long time.
systems:
# We only need to run this test once, and it takes a long time.
- ubuntu-22.04-64

execute: |
unset CHARMCRAFT_STORE_API_URL
unset CHARMCRAFT_UPLOAD_URL
unset CHARMCRAFT_REGISTRY_URL
mkdir -p test-init
cd test-init
charmcraft init --profile flask-framework
Expand Down

0 comments on commit 3b05ba5

Please sign in to comment.