1
- # Copyright 2024 Canonical Ltd.
1
+ # Copyright 2022 Canonical Ltd.
2
2
# See LICENSE file for licensing details.
3
3
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)
9
15
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
10
82
files :
11
83
plugin : dump
12
84
source : .
@@ -18,30 +90,10 @@ parts:
18
90
# (https://docs.google.com/document/d/1Jv1jhWLl8ejK3iJn7Q3VbCIM9GIhp8926bgXpdtx-Sg/edit?pli=1)
19
91
# is pending review.
20
92
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
+
21
94
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
26
95
prime :
96
+ - LICENSE
27
97
- charm_version
28
98
- 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
0 commit comments