Skip to content

Commit 42d65cd

Browse files
Migrate to charmcraft 3 poetry plugin (#375)
data-platform-workflows and charmcraftcache are migrating from charmcraft 2 to 3 to enable 24.04 based charms & to enable use of the poetry plugin, which fixes several longstanding issues with charmcraft (e.g. canonical/charmcraft#1077)
1 parent f6562a9 commit 42d65cd

File tree

7 files changed

+120
-80
lines changed

7 files changed

+120
-80
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
jobs:
1717
lint:
1818
name: Lint
19-
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v24.0.6
19+
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v26.0.0
2020

2121
lib-check:
2222
name: Check libraries
@@ -54,40 +54,31 @@ jobs:
5454

5555
build:
5656
name: Build charm | ${{ matrix.path }}
57-
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v24.0.6
57+
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v26.0.0
5858
strategy:
5959
matrix:
6060
path:
6161
- .
6262
- tests/integration/ha_tests/application_charm
6363
- tests/integration/relation_tests/application-charm
6464
with:
65+
cache: true
66+
charmcraft-snap-channel: latest/beta/data-platform # TODO: remove after charmcraft 3.3 stable release
6567
path-to-charm-directory: ${{ matrix.path }}
6668

6769
integration-test:
68-
strategy:
69-
fail-fast: false
70-
matrix:
71-
juju:
72-
# This runs on all runs
73-
- agent: 3.5.3 # renovate: juju-agent-pin-minor
74-
allure_report: true
75-
# This runs only on scheduled runs, DPW 21 specifics (scheduled + 3.6/X)
76-
- snap_channel: 3.6/stable
77-
allure_report: false
78-
name: Integration test charm | ${{ matrix.juju.agent || matrix.juju.snap_channel }}
70+
name: Integration test charm
7971
needs:
8072
- lint
8173
- unit-test
8274
- build
83-
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v24.0.6
75+
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v26.0.0
8476
with:
85-
artifact-prefix: packed-charm-cache-false # TODO revert to "packed-charm-cache-true" when cache re-enabled
77+
artifact-prefix: packed-charm-cache-true
8678
cloud: microk8s
87-
microk8s-snap-channel: 1.29-strict/stable
88-
juju-agent-version: ${{ matrix.juju.agent }}
89-
juju-snap-channel: ${{ matrix.juju.snap_channel }}
90-
_beta_allure_report: ${{ matrix.juju.allure_report }}
79+
microk8s-snap-channel: 1.29-strict/stable # renovate: latest microk8s
80+
juju-agent-version: 3.6.1 # renovate: juju-agent-pin-minor
81+
_beta_allure_report: true
9182
permissions:
9283
contents: write # Needed for Allure Report beta
9384
secrets:

.github/workflows/release.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ jobs:
3535

3636
build:
3737
name: Build charm
38-
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v24.0.6
38+
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v26.0.0
3939
with:
40-
artifact-prefix: temp-release-packed-charm # TODO: remove after caching re-enabled on PR
40+
charmcraft-snap-channel: latest/beta/data-platform # TODO: remove after charmcraft 3.3 stable release
4141

4242
release:
4343
name: Release charm
4444
needs:
4545
- ci-tests
4646
- build
47-
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v24.0.6
47+
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v26.0.0
4848
with:
49+
charmcraft-snap-channel: latest/beta/data-platform # TODO: remove after charmcraft 3.3 stable release
4950
channel: 6/edge
5051
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
5152
secrets:

charmcraft.yaml

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,84 @@
1-
# Copyright 2024 Canonical Ltd.
1+
# Copyright 2022 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

4-
type: "charm"
5-
bases:
6-
- name: ubuntu
7-
channel: "22.04"
8-
architectures: [amd64]
4+
type: charm
5+
platforms:
6+
7+
# Files implicitly created by charmcraft without a part:
8+
# - dispatch (https://github.com/canonical/charmcraft/pull/1898)
9+
# - manifest.yaml
10+
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L259)
11+
# Files implicitly copied/"primed" by charmcraft without a part:
12+
# - actions.yaml, config.yaml, metadata.yaml
13+
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L290-L293
14+
# https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L156-L157)
915
parts:
16+
# "poetry-deps" part name is a magic constant
17+
# https://github.com/canonical/craft-parts/pull/901
18+
poetry-deps:
19+
plugin: nil
20+
build-packages:
21+
- curl
22+
override-build: |
23+
# Use environment variable instead of `--break-system-packages` to avoid failing on older
24+
# versions of pip that do not recognize `--break-system-packages`
25+
# `--user` needed (in addition to `--break-system-packages`) for Ubuntu >=24.04
26+
PIP_BREAK_SYSTEM_PACKAGES=true python3 -m pip install --user --upgrade pip==24.3.1 # renovate: charmcraft-pip-latest
27+
28+
# Use uv to install poetry so that a newer version of Python can be installed if needed by poetry
29+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.5.15/uv-installer.sh | sh # renovate: charmcraft-uv-latest
30+
# poetry 2.0.0 requires Python >=3.9
31+
if ! "$HOME/.local/bin/uv" python find '>=3.9'
32+
then
33+
# Use first Python version that is >=3.9 and available in an Ubuntu LTS
34+
# (to reduce the number of Python versions we use)
35+
"$HOME/.local/bin/uv" python install 3.10.12 # renovate: charmcraft-python-ubuntu-22.04
36+
fi
37+
"$HOME/.local/bin/uv" tool install --no-python-downloads --python '>=3.9' poetry==2.0.0 --with poetry-plugin-export==1.8.0 # renovate: charmcraft-poetry-latest
38+
39+
ln -sf "$HOME/.local/bin/poetry" /usr/local/bin/poetry
40+
# "charm-poetry" part name is arbitrary; use for consistency
41+
# Avoid using "charm" part name since that has special meaning to charmcraft
42+
charm-poetry:
43+
# By default, the `poetry` plugin creates/primes these directories:
44+
# - lib, src
45+
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L76-L78)
46+
# - venv
47+
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L95
48+
# https://github.com/canonical/craft-parts/blob/afb0d652eb330b6aaad4f40fbd6e5357d358de47/craft_parts/plugins/base.py#L270)
49+
plugin: poetry
50+
source: .
51+
after:
52+
- poetry-deps
53+
poetry-export-extra-args: ['--only', 'main,charm-libs']
54+
build-packages:
55+
- libffi-dev # Needed to build Python dependencies with Rust from source
56+
- libssl-dev # Needed to build Python dependencies with Rust from source
57+
- pkg-config # Needed to build Python dependencies with Rust from source
58+
override-build: |
59+
# Workaround for https://github.com/canonical/charmcraft/issues/2068
60+
# rustup used to install rustc and cargo, which are needed to build Python dependencies with Rust from source
61+
if [[ "$CRAFT_PLATFORM" == [email protected]:* || "$CRAFT_PLATFORM" == [email protected]:* ]]
62+
then
63+
snap install rustup --classic
64+
else
65+
apt-get install rustup -y
66+
fi
67+
68+
# If Ubuntu version < 24.04, rustup was installed from snap instead of from the Ubuntu
69+
# archive—which means the rustup version could be updated at any time. Print rustup version
70+
# to build log to make changes to the snap's rustup version easier to track
71+
rustup --version
72+
73+
# rpds-py (Python package) >=0.19.0 requires rustc >=1.76, which is not available in the
74+
# Ubuntu 22.04 archive. Install rustc and cargo using rustup instead of the Ubuntu archive
75+
rustup set profile minimal
76+
rustup default 1.83.0 # renovate: charmcraft-rust-latest
77+
78+
craftctl default
79+
# Include requirements.txt in *.charm artifact for easier debugging
80+
cp requirements.txt "$CRAFT_PART_INSTALL/requirements.txt"
81+
# "files" part name is arbitrary; use for consistency
1082
files:
1183
plugin: dump
1284
source: .
@@ -18,30 +90,10 @@ parts:
1890
# (https://docs.google.com/document/d/1Jv1jhWLl8ejK3iJn7Q3VbCIM9GIhp8926bgXpdtx-Sg/edit?pli=1)
1991
# is pending review.
2092
python3 -c 'import pathlib; import shutil; import subprocess; git_hash=subprocess.run(["git", "describe", "--always", "--dirty"], capture_output=True, check=True, encoding="utf-8").stdout; file = pathlib.Path("charm_version"); shutil.copy(file, pathlib.Path("charm_version.backup")); version = file.read_text().strip(); file.write_text(f"{version}+{git_hash}")'
93+
2194
craftctl default
22-
stage:
23-
# Exclude requirements.txt file during staging
24-
# Workaround for https://github.com/canonical/charmcraft/issues/1389 on charmcraft 2
25-
- -requirements.txt
2695
prime:
96+
- LICENSE
2797
- charm_version
2898
- workload_version
29-
charm:
30-
build-snaps:
31-
- rustup
32-
build-packages:
33-
- libffi-dev
34-
- libssl-dev
35-
- pkg-config
36-
override-build: |
37-
rustup default stable
38-
# Convert subset of poetry.lock to requirements.txt
39-
curl -sSL https://install.python-poetry.org | python3 -
40-
/root/.local/bin/poetry self add poetry-plugin-export
41-
/root/.local/bin/poetry export --only main,charm-libs --output requirements.txt
42-
craftctl default
43-
stage:
44-
# Exclude charm_version file during staging
45-
- -charm_version
46-
charm-strict-dependencies: true
47-
charm-requirements: [requirements.txt]
99+
- templates

poetry.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ pytest = "^8.1.1"
7474
pytest-asyncio = "^0.21.1"
7575
pytest-mock = "^3.14.0"
7676
pytest-operator = "^0.36.0"
77-
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
78-
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
79-
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/github_secrets"}
80-
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}
77+
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
78+
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
79+
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
80+
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}
8181

8282
[build-system]
8383
build-backend = "poetry.core.masonry.api"
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
# Copyright 2024 Canonical Ltd.
1+
# Copyright 2022 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

44
type: charm
5-
bases:
6-
- build-on:
7-
- name: "ubuntu"
8-
channel: "22.04"
9-
run-on:
10-
- name: "ubuntu"
11-
channel: "22.04"
5+
platforms:
6+
7+
parts:
8+
charm:
9+
plugin: charm
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
# Copyright 2024 Canonical Ltd.
1+
# Copyright 2022 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

44
type: charm
5-
bases:
6-
- build-on:
7-
- name: "ubuntu"
8-
channel: "22.04"
9-
run-on:
10-
- name: "ubuntu"
11-
channel: "22.04"
5+
platforms:
6+
7+
parts:
8+
charm:
9+
plugin: charm

0 commit comments

Comments
 (0)