Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced grammar doesn't work with multi-platform (ST124) charms #2068

Open
carlcsaposs-canonical opened this issue Jan 8, 2025 · 3 comments
Labels
Bug Something isn't working

Comments

@carlcsaposs-canonical
Copy link
Contributor

carlcsaposs-canonical commented Jan 8, 2025

Bug Description

Advanced grammar doesn't work with charms using ST124 syntax (https://docs.google.com/document/d/1QVHxZumruKVZ3yJ2C74qWhvs-ye5I9S6avMBDHs2YcQ/edit?pli=1&tab=t.0#heading=h.sn552414niwh)

To Reproduce

git clone https://github.com/canonical/mysql-router-operator/
cd mysql-router-operator
git checkout 4fde81baf3fcf710caa77ae7afcc0e5d51c855af
sudo snap install charmcraft --classic --channel latest/edge
charmcraft pack -v --platform [email protected]:amd64

Expected behavior

rustup is installed from snap on 22.04 base

Actual behavior

charmcraft attempts to install rustup with apt and fails

Starting charmcraft, version 3.2.2.post138+g33519b4a
Logging execution to '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20250108-115236.624501.log'
Launching managed ubuntu 22.04 instance...
Creating new instance from remote
Creating new base instance from remote 
Creating new instance from base instance 
Starting instance 
Starting charmcraft, version 3.2.2.post138+g33519b4a
Logging execution to '/tmp/charmcraft.log'
Initialising lifecycle
Installing build-packages
Cannot find package listed in 'build-packages': rustup
Failed to execute charmcraft in instance.
Full execution log: '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20250108-115236.624501.log'

Environment

Ubuntu 22.04

$ snap list
Name              Version                  Rev    Tracking            Publisher          Notes
charmcraft        3.2.2.post138+g33519b4a  5709   latest/edge         canonical✓         classic
core18            20240920                 2846   latest/stable       canonical✓         base
core20            20240911                 2434   latest/stable       canonical✓         base
core22            20241119                 1722   latest/stable       canonical✓         base
core24            20240920                 609    latest/stable       canonical✓         base
juju              3.6.1                    29241  3/stable            canonical✓         -
lxd               5.0.4-497fe1e            31333  5.0/stable/…        canonical✓         -
microk8s          v1.29.11                 7435   1.29-strict/stable  canonical✓         -
snapcraft         8.5.1                    13181  latest/stable       canonical✓         classic
snapd             2.66.1                   23258  latest/stable       canonical✓         snapd

charmcraft.yaml

# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

type: charm
platforms:
  [email protected]:amd64:
  [email protected]:amd64:
  [email protected]:arm64:
  [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`
      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 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-snaps:
      - on [email protected]:
          - rustup
      - on [email protected]:
          - rustup
    build-packages:
      - libffi-dev
      - libssl-dev
      - pkg-config
      - on [email protected]: []
      - on [email protected]: []
      - else:
          - rustup
    override-build: |
      rustup --version
      rustup default stable
      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: .
    build-packages:
      - git
    override-build: |
      # Workaround to add unique identifier (git hash) to charm version while specification
      # DA053 - Charm versioning
      # (https://docs.google.com/document/d/1Jv1jhWLl8ejK3iJn7Q3VbCIM9GIhp8926bgXpdtx-Sg/edit?pli=1)
      # is pending review.
      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
    prime:
      - LICENSE
      - charm_version
      - workload_version
      - templates

Relevant log output

charmcraft-20250108-115236.624501.log

@carlcsaposs-canonical carlcsaposs-canonical added the Bug Something isn't working label Jan 8, 2025
@carlcsaposs-canonical
Copy link
Contributor Author

I also tried

    build-packages:
      - on [email protected]:
          - libffi-dev
          - libssl-dev
          - pkg-config
      - on [email protected]:
          - libffi-dev
          - libssl-dev
          - pkg-config
      - else:
          - libffi-dev
          - libssl-dev
          - pkg-config
          - rustup

and

    build-packages:
      - on [email protected]:amd64:
          - libffi-dev
          - libssl-dev
          - pkg-config
      - on [email protected]:amd64:
          - libffi-dev
          - libssl-dev
          - pkg-config
      - else:
          - libffi-dev
          - libssl-dev
          - pkg-config
          - rustup

and

    build-packages:
      - libffi-dev
      - libssl-dev
      - pkg-config
      - on [email protected]:amd64: []
      - on [email protected]:amd64: []
      - else:
          - rustup

but got the same results

@mr-cal
Copy link
Contributor

mr-cal commented Jan 8, 2025

This is expected as it's not implemented yet. Charmcraft doesn't officially support advanced grammar and craft-grammar doesn't support using the platform in grammar statements.

We have tasks outlined but I don't think we have an ETA.

@carlcsaposs-canonical
Copy link
Contributor Author

thank you for the information!

carlcsaposs-canonical added a commit to canonical/mysql-router-operator that referenced this issue Jan 8, 2025
carlcsaposs-canonical added a commit to canonical/mysql-router-operator that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants