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

Charm dispatch fails with poetry plugin #1995

Closed
carlcsaposs-canonical opened this issue Nov 15, 2024 · 3 comments · Fixed by #1972 or #2017
Closed

Charm dispatch fails with poetry plugin #1995

carlcsaposs-canonical opened this issue Nov 15, 2024 · 3 comments · Fixed by #1972 or #2017
Assignees
Labels
Bug Something isn't working triaged

Comments

@carlcsaposs-canonical
Copy link
Contributor

carlcsaposs-canonical commented Nov 15, 2024

Bug Description

dispatch file generated by charmcraft with poetry plugin fails all juju events

ln: failed to create symbolic link '/var/lib/juju/agents/unit-mysql-router-k8s-0/charm/venv/bin/python': No such file or directory
./dispatch: 16: exec: /var/lib/juju/agents/unit-mysql-router-k8s-0/charm/venv/bin/python: not found

Discovered after working around #1994 by renaming kubernetes_charm.py to charm.py

To Reproduce

git clone https://github.com/canonical/mysql-router-k8s-operator
cd mysql-router-k8s-operator
git checkout a0c3fc45b3f1bd71529747103fc6e37403e658d9
charmcraft pack -v
juju deploy ./mysql-router-k8s_ubuntu-22.04-amd64.charm --resource mysql-router-image=ghcr.io/canonical/charmed-mysql@sha256:89b8305613f6ce94f78a7c9b4baedef78f2816fd6bc74c00f6607bc5e57bd8e6
juju status

juju status shows error

juju debug-hooks mysql-router-k8s/0

in other terminal, run juju resolve mysql-router-k8s/0

# ./dispatch 
ln: failed to create symbolic link '/var/lib/juju/agents/unit-mysql-router-k8s-0/charm/venv/bin/python': No such file or directory
./dispatch: 16: exec: /var/lib/juju/agents/unit-mysql-router-k8s-0/charm/venv/bin/python: not found

Environment

Ubuntu 22.04

$ snap list
Name              Version                 Rev    Tracking            Publisher          Notes
charmcraft        3.2.2.post75+gff00a899  5394   3.x/edge            canonical✓         classic,held
core18            20240920                2846   latest/stable       canonical✓         base
core20            20240911                2434   latest/stable       canonical✓         base
core22            20241001                1663   latest/stable       canonical✓         base
juju              3.5.4                   28520  3/stable            canonical✓         -
lxd               5.0.3-80aeff7           29351  5.0/stable/…        canonical✓         -
microk8s          v1.29.9                 7227   1.29-strict/stable  canonical✓         -
snapd             2.63                    21759  latest/stable       canonical✓         snapd

charmcraft.yaml

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

type: charm
bases:
  - name: ubuntu
    channel: "22.04"
    architectures: [amd64]
  - name: ubuntu
    channel: "22.04"
    architectures: [arm64]
parts:
  poetry-deps:
    plugin: nil
    build-packages:
      - curl
    override-build: |
      python3 -m pip install --upgrade pip==24.3.1
      curl -sSL https://install.python-poetry.org | python3 - --version 1.8.4
      ln -sf $HOME/.local/bin/poetry /usr/local/bin/poetry
  foo:
    plugin: poetry
    source: .
    after:
      - poetry-deps
    poetry-with:
      - charm-libs
    build-snaps:
      - rustup
    build-packages:
      - libffi-dev
      - libssl-dev
      - pkg-config
    override-build: |
      rustup default stable
      craftctl default

#
#  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
#    stage:
#      # Exclude requirements.txt file during staging
#      # Workaround for https://github.com/canonical/charmcraft/issues/1389 on charmcraft 2
#      - -requirements.txt
#    prime:
#      - charm_version
#      - workload_version
#      - scripts
#  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 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/kubernetes_charm.py

Relevant log output

charmcraft-20241115-112046.686344.log

@carlcsaposs-canonical carlcsaposs-canonical added the Bug Something isn't working label Nov 15, 2024
@lengau lengau added the triaged label Nov 18, 2024
@lengau lengau self-assigned this Nov 18, 2024
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3696.

This message was autogenerated

@lengau
Copy link
Collaborator

lengau commented Nov 18, 2024

Thanks! This is fixed in #1972

@carlcsaposs-canonical
Copy link
Contributor Author

This issue does not appear to be fixed

root@mysql-router-k8s-0:/var/lib/juju/agents/unit-mysql-router-k8s-0/charm# ./dispatch 
ln: failed to create symbolic link '/var/lib/juju/agents/unit-mysql-router-k8s-0/charm/venv/bin/python': No such file or directory
./dispatch: 18: exec: /var/lib/juju/agents/unit-mysql-router-k8s-0/charm/venv/bin/python: not found
root@mysql-router-k8s-0:/var/lib/juju/agents/unit-mysql-router-k8s-0/charm# cat dispatch 
#!/bin/sh
dispatch_path="$(dirname $(realpath $0))"
venv_bin_path="${dispatch_path}/venv/bin"
python_path="${venv_bin_path}/python"
if [ ! -e "${python_path}" ]; then
    mkdir -p "{venv_bin_path}"
    ln -s $(which python3) "${python_path}"
fi

# Add charm lib and source directories to PYTHONPATH so the charm can import
# libraries and its own modules as expected.
export PYTHONPATH="${dispatch_path}/lib:${dispatch_path}/src"

# Add the charm's lib and usr/lib directories to LD_LIBRARY_PATH, allowing
# staged packages to be discovered by the dynamic linker.
export LD_LIBRARY_PATH="${dispatch_path}/usr/lib:${dispatch_path}/lib:${dispatch_path}/usr/lib/$(uname -m)-linux-gnu"

exec "${python_path}" "${dispatch_path}/src/charm.py"

carlcsaposs-canonical added a commit to carlcsaposs-canonical/charmcraft that referenced this issue Dec 6, 2024
@lengau lengau reopened this Dec 10, 2024
lengau pushed a commit to carlcsaposs-canonical/charmcraft that referenced this issue Dec 10, 2024
@lengau lengau closed this as completed in 7f23872 Dec 10, 2024
lengau added a commit to tmihoc/charmcraft that referenced this issue Dec 19, 2024
lengau pushed a commit to tmihoc/charmcraft that referenced this issue Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working triaged
Projects
None yet
2 participants