Skip to content

Commit

Permalink
Migrate to charmcraft 3 poetry plugin (#529)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
carlcsaposs-canonical authored Jan 14, 2025
1 parent fc51448 commit 71dfaa0
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 96 deletions.
28 changes: 9 additions & 19 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
lint:
name: Lint
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v24.0.6
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v26.0.0

unit-test:
name: Unit test charm
Expand Down Expand Up @@ -136,33 +136,23 @@ jobs:
path:
- .
- ./tests/integration/relations/opensearch_provider/application-charm/
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v24.0.6
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v26.0.0
with:
cache: false # TODO: will change to `true` before merge
charmcraft-snap-channel: latest/beta/data-platform # TODO: remove after charmcraft 3.3 stable release
path-to-charm-directory: ${{ matrix.path }}
cache: false

integration-test:
strategy:
fail-fast: false
matrix:
juju:
# This runs on all runs
- agent: 3.5.3 # renovate: juju-agent-pin-minor
allure_report: true
# This runs only on scheduled runs, DPW 21 specifics (scheduled + 3.6/X)
- snap_channel: 3.6/beta
allure_report: false
name: Integration test charm | ${{ matrix.juju.agent || matrix.juju.snap_channel }}
name: Integration test charm
needs:
- lint
- unit-test
- build
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v24.0.6
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v26.0.0
with:
juju-agent-version: ${{ matrix.juju.agent }}
juju-snap-channel: ${{ matrix.juju.snap_channel }}
_beta_allure_report: ${{ matrix.juju.allure_report }}
artifact-prefix: packed-charm-cache-false
juju-agent-version: 3.6.1 # renovate: juju-agent-pin-minor
_beta_allure_report: true
artifact-prefix: packed-charm-cache-false # TODO: revert cache
cloud: lxd
secrets:
# GitHub appears to redact each line of a multi-line secret
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
charmcraft-snap-channel: latest/beta/data-platform # TODO: remove after charmcraft 3.3 stable release

release:
name: Release charm
needs:
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v24.0.6
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v26.0.0
with:
charmcraft-snap-channel: latest/beta/data-platform # TODO: remove after charmcraft 3.3 stable release
channel: 2/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
sync-docs:
name: Sync docs from Discourse
uses: canonical/data-platform-workflows/.github/workflows/sync_docs.yaml@v24.0.6
uses: canonical/data-platform-workflows/.github/workflows/sync_docs.yaml@v26.0.0
with:
reviewers: a-velasco
permissions:
Expand Down
123 changes: 78 additions & 45 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,84 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

type: charm
# Use upcoming ST124 syntax
# To pack this charm, a temporary compatibility wrapper https://github.com/canonical/charmcraftst124
# is required until ST124 support is added to charmcraft
# (ST124 syntax is needed to enable multi-base charms with Ubuntu 24.04. We use ST124 syntax across
# all of our charms [even those that aren't multi base] for consistency and to simplify CI/CD
# maintenance & tooling)
# platforms:
# [email protected]:amd64:
# # TODO: enable after charmcraft 3 migration
# [email protected]:amd64:
bases:
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"

platforms:
[email protected]:amd64:
# Files implicitly created by charmcraft without a part:
# - dispatch (https://github.com/canonical/charmcraft/pull/1898)
# - manifest.yaml
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L259)
# Files implicitly copied/"primed" by charmcraft without a part:
# - actions.yaml, config.yaml, metadata.yaml
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L290-L293
# https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L156-L157)
parts:
# "poetry-deps" part name is a magic constant
# https://github.com/canonical/craft-parts/pull/901
poetry-deps:
plugin: nil
build-packages:
- curl
override-build: |
# Use environment variable instead of `--break-system-packages` to avoid failing on older
# versions of pip that do not recognize `--break-system-packages`
# `--user` needed (in addition to `--break-system-packages`) for Ubuntu >=24.04
PIP_BREAK_SYSTEM_PACKAGES=true python3 -m pip install --user --upgrade pip==24.3.1 # renovate: charmcraft-pip-latest
# Use uv to install poetry so that a newer version of Python can be installed if needed by poetry
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
# poetry 2.0.0 requires Python >=3.9
if ! "$HOME/.local/bin/uv" python find '>=3.9'
then
# Use first Python version that is >=3.9 and available in an Ubuntu LTS
# (to reduce the number of Python versions we use)
"$HOME/.local/bin/uv" python install 3.10.12 # renovate: charmcraft-python-ubuntu-22.04
fi
"$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
ln -sf "$HOME/.local/bin/poetry" /usr/local/bin/poetry
# "charm-poetry" part name is arbitrary; use for consistency
# Avoid using "charm" part name since that has special meaning to charmcraft
charm-poetry:
# By default, the `poetry` plugin creates/primes these directories:
# - lib, src
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L76-L78)
# - venv
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L95
# https://github.com/canonical/craft-parts/blob/afb0d652eb330b6aaad4f40fbd6e5357d358de47/craft_parts/plugins/base.py#L270)
plugin: poetry
source: .
after:
- poetry-deps
poetry-export-extra-args: ['--only', 'main,charm-libs']
build-packages:
- libffi-dev # Needed to build Python dependencies with Rust from source
- libssl-dev # Needed to build Python dependencies with Rust from source
- pkg-config # Needed to build Python dependencies with Rust from source
override-build: |
# Workaround for https://github.com/canonical/charmcraft/issues/2068
# rustup used to install rustc and cargo, which are needed to build Python dependencies with Rust from source
if [[ "$CRAFT_PLATFORM" == [email protected]:* || "$CRAFT_PLATFORM" == [email protected]:* ]]
then
snap install rustup --classic
else
apt-get install rustup -y
fi
# If Ubuntu version < 24.04, rustup was installed from snap instead of from the Ubuntu
# archive—which means the rustup version could be updated at any time. Print rustup version
# to build log to make changes to the snap's rustup version easier to track
rustup --version
# rpds-py (Python package) >=0.19.0 requires rustc >=1.76, which is not available in the
# Ubuntu 22.04 archive. Install rustc and cargo using rustup instead of the Ubuntu archive
rustup set profile minimal
rustup default 1.83.0 # renovate: charmcraft-rust-latest
craftctl default
# Include requirements.txt in *.charm artifact for easier debugging
cp requirements.txt "$CRAFT_PART_INSTALL/requirements.txt"
# "files" part name is arbitrary; use for consistency
files:
plugin: dump
source: .
Expand All @@ -34,32 +92,7 @@ parts:
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}")'
craftctl default
stage:
# Exclude requirements.txt file during staging
# Workaround for https://github.com/canonical/charmcraft/issues/1389 on charmcraft 2
- -requirements.txt
prime:
- LICENSE
- charm_version
- workload_version
charm:
build-snaps:
- rustup
build-packages:
- libffi-dev
- libssl-dev
- pkg-config
override-build: |
rustup default stable
# Convert subset of poetry.lock to requirements.txt
curl -sSL https://install.python-poetry.org | python3 -
/root/.local/bin/poetry self add poetry-plugin-export
/root/.local/bin/poetry export --only main,charm-libs --output requirements.txt
craftctl default
stage:
# Exclude charm_version file during staging
- -charm_version
charm-strict-dependencies: true
charm-requirements: [requirements.txt]
charm-entrypoint: src/charm.py
27 changes: 16 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ responses = "^0.25.3"
[tool.poetry.group.integration.dependencies]
boto3 = "^1.34.135"
pytest = "^8.2.2"
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-asyncio = "^0.21.2"
pytest-operator = "^0.35.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-microceph = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/microceph"}
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-microceph = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/microceph"}
juju = "==3.6.0"
ops = "^2.15"
tenacity = "^8.4.2"
Expand All @@ -82,7 +82,7 @@ urllib3 = "^2.2.2"
protobuf = "^5.27.2"
opensearch-py = "^2.6.0"
allure-pytest = "^2.13.5"
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v24.0.6", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v26.0.0", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}

[tool.coverage.run]
branch = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

type: charm
# platforms:
# [email protected]:amd64:
bases:
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"

platforms:
[email protected]:amd64:
parts:
my-charm:
source: .
charm:
plugin: charm

0 comments on commit 71dfaa0

Please sign in to comment.