Charmcraft fails to pack within Github runner using `--destructive-mode`
Metadata
Current evaluation
Closed without a fix. Maintainer clarified destructive mode requires sudo or preinstalled dependencies by design. The LXD hang was attributed to the GitHub Actions workflow, not charmcraft, and advised filing separately if it persists.
Suggested action: —
No scores available.
Issue body
## Description
Charmcraft is failing to pack within a Github runner using `--destructive-mode`. The specific charm needs to install `apt` packages in the host system and it's failing because of permissions.
We thought that getting rid of the `--destructive-mode` would solve the permissions issue, but fails as well. The only solution that is working for us is running the `pack` command using `sudo` alongside `--destructive-mode`, not the best practice, but the only one that works for us.
After reading this [article](https://discourse.charmhub.io/t/building-your-charms-with-github-actions/4992) I've run manually all the commands by SSHing into the runner and I was able to pack it without `--destructive-mode` (with LXD). But whenever I do the same from the action (Javascript action with `exec` calls), it gets stuck and never comes back. Maybe that's related to running the command as another user using `sg` or running an `exec` call from Javascript.
## `Charmcraft.yaml`
```yaml
type: "charm"
bases:
- build-on:
- name: "ubuntu"
channel: "20.04"
run-on:
- name: "ubuntu"
channel: "20.04"
parts:
charm:
build-packages:
- git
- libffi-dev
- libssl-dev
- rustc
- cargo
charm-python-packages:
- setuptools
```
## References
- [Failed run using `--destructive-mode`](https://github.com/canonical/charmed-magma/runs/5567693459?check_suite_focus=true)
- [Successful run packing using `sudo` without `--destructive-mode`](https://github.com/sanchezfdezjavier/test-edge-release/runs/5553326624?check_suite_focus=true)
Here's the log of the issue:
```
2022-03-09 16:45:20.980 Starting charmcraft version 1.5.0+5.g0bf70b8
2022-03-09 16:45:20.980 Raw pre-parsed sysargs: args={'help': False, 'verbose': False, 'quiet': True, 'trace': False, 'project_dir': None} filtered=['pack', '--destructive-mode']
2022-03-09 16:45:20.980 General parsed sysargs: command='pack' args=['--destructive-mode']
2022-03-09 16:45:20.985 Command parsed sysargs: Namespace(bases_index=None, debug=False, destructive_mode=True, entrypoint=None, force=False, requirement=None, shell=False, shell_after=False)
2022-03-09 16:45:20.985 System details: OSPlatform(system='ubuntu', release='20.04', machine='x86_64'); Environment: None
2022-03-09 16:45:20.985 Packing the charm.
2022-03-09 16:45:20.985 Working arguments: {'from': PosixPath('/home/runner/work/charmed-magma/charmed-magma/orchestrator-bundle/orc8r-certifier-operator'), 'destructive_mode': True, 'entrypoint': None, 'requirement': [], 'bases_indices': None, 'force': False, 'debug': False, 'shell': False, 'shell_after': False}
2022-03-09 16:45:20.986 Parsing '/home/runner/work/charmed-magma/charmed-magma/orchestrator-bundle/orc8r-certifier-operator/metadata.yaml'
2022-03-09 16:45:20.998 Building for 'bases[0]' as host matches 'build-on[0]'.
2022-03-09 16:45:20.998 Building for 'bases[0][0]'.
2022-03-09 16:45:20.998 Building charm in '/home/runner/work/charmed-magma/charmed-magma/orchestrator-bundle/orc8r-certifier-operator/build'
2022-03-09 16:45:20.998 Parts definition: {'charm': {'build-packages': ['git', 'libffi-dev', 'libssl-dev', 'rustc', 'cargo'], 'charm-python-packages': ['setuptools'], 'plugin': 'charm', 'source': '/home/runner/work/charmed-magma/charmed-magma/orchestrator-bundle/orc8r-certifier-operator', 'charm-requirements': ['requirements.txt'], 'charm-entrypoint': 'src/charm.py', 'prime': ['src', 'venv', 'metadata.yaml', 'dispatch', 'hooks', 'config.yaml', 'lib', 'icon.svg', 'README.md']}}
2022-03-09 16:45:20.999 is_snap: True, SNAP_NAME set to charmcraft
2022-03-09 16:45:20.999 Setting target machine to x86_64
2022-03-09 16:45:21.001 ignore patterns: ['*.charm', 'build']
2022-03-09 16:45:21.001 part build packages: ['git', 'libffi-dev', 'libssl-dev', 'rustc', 'cargo']
2022-03-09 16:45:21.001 plugin build packages: {'python3-venv', 'python3-setuptools', 'python3-wheel', 'python3-dev', 'python3-pip'}
2022-03-09 16:45:21.001 clean charm:Step.PRIME
2022-03-09 16:45:21.001 clean charm:Step.STAGE
2022-03-09 16:45:21.001 clean charm:Step.BUILD
2022-03-09 16:45:21.002 Executing parts lifecycle in '/home/runner/work/charmed-magma/charmed-magma/orchestrator-bundle/orc8r-certifier-operator'
2022-03-09 16:45:21.002 process charm:Step.PULL
2022-03-09 16:45:21.002 add action charm:Step.PULL(ActionType.RUN)
2022-03-09 16:45:21.002 process charm:Step.OVERLAY
2022-03-09 16:45:21.006 add action charm:Step.OVERLAY(ActionType.RUN)
2022-03-09 16:45:21.006 process charm:Step.BUILD
2022-03-09 16:45:21.006 add action charm:Step.BUILD(ActionType.RUN)
2022-03-09 16:45:21.006 process charm:Step.STAGE
2022-03-09 16:45:21.007 add action charm:Step.STAGE(ActionType.RUN)
2022-03-09 16:45:21.007 process charm:Step.PRIME
2022-03-09 16:45:21.007 add action charm:Step.PRIME(ActionType.RUN)
2022-03-09 16:45:21.007 Parts actions: [Action(part_name='charm', step=Step.PULL, action_type=ActionType.RUN, reason=None), Action(part_name='charm', step=Step.OVERLAY, action_type=ActionType.RUN, reason=None), Action(part_name='charm', step=Step.BUILD, action_type=ActionType.RUN, reason=None), Action(part_name='charm', step=Step.STAGE, action_type=ActionType.RUN, reason=None), Action(part_name='charm', step=Step.PRIME, action_type=ActionType.RUN, reason=None)]
2022-03-09 16:45:21.007 Requested build-packages: ['cargo', 'git', 'libffi-dev', 'libssl-dev', 'python3-dev', 'python3-pip', 'python3-setuptools', 'python3-venv', 'python3-wheel', 'rustc']
2022-03-09 16:45:23.562 Marking python3-venv (and its dependencies) to be fetched
2022-03-09 16:45:23.562 package: python3-venv
2022-03-09 16:45:23.577 Marking python3-setuptools (and its dependencies) to be fetched
2022-03-09 16:45:23.577 package: python3-setuptools
2022-03-09 16:45:23.591 Marking python3-dev (and its dependencies) to be fetched
2022-03-09 16:45:23.591 package: python3-dev
2022-03-09 16:45:23.605 Marking python3-wheel (and its dependencies) to be fetched
2022-03-09 16:45:23.605 package: python3-wheel
2022-03-09 16:45:23.620 Marking rustc (and its dependencies) to be fetched
2022-03-09 16:45:23.620 package: rustc
2022-03-09 16:45:23.649 Marking libffi-dev (and its dependencies) to be fetched
2022-03-09 16:45:23.649 package: libffi-dev
2022-03-09 16:45:23.665 Marking libssl-dev (and its dependencies) to be fetched
2022-03-09 16:45:23.665 package: libssl-dev
2022-03-09 16:45:23.679 Marking cargo (and its dependencies) to be fetched
2022-03-09 16:45:23.679 package: cargo
2022-03-09 16:45:23.708 Marking python3-pip (and its dependencies) to be fetched
2022-03-09 16:45:23.708 package: python3-pip
2022-03-09 16:45:23.722 Marking git (and its dependencies) to be fetched
2022-03-09 16:45:23.722 package: git
2022-03-09 16:45:23.758 Installing packages: cargo=0.58.0-0ubuntu1~20.04.1 libstd-rust-1.57=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1 libstd-rust-dev=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1 rustc=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1
2022-03-09 16:45:23.818 :: E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
2022-03-09 16:45:23.818 :: E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
2022-03-09 16:45:23.819 Parts processing error: Cannot install all requested build packages: cargo=0.58.0-0ubuntu1~20.04.1, libstd-rust-1.57=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1, libstd-rust-dev=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1, rustc=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1
2022-03-09 16:45:23.823 Traceback (most recent call last):
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/packages/deb.py", line 469, in _install_packages
2022-03-09 16:45:23.823 process_run(apt_command + package_names, env=env, stdin=subprocess.DEVNULL)
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/packages/deb.py", line 604, in process_run
2022-03-09 16:45:23.823 os_utils.process_run(command, logger.debug, **kwargs)
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/utils/os_utils.py", line 360, in process_run
2022-03-09 16:45:23.823 raise subprocess.CalledProcessError(ret, command)
2022-03-09 16:45:23.823 subprocess.CalledProcessError: Command '['apt-get', '--no-install-recommends', '-y', '-oDpkg::Use-Pty=0', '--allow-downgrades', 'install', 'cargo=0.58.0-0ubuntu1~20.04.1', 'libstd-rust-1.57=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1', 'libstd-rust-dev=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1', 'rustc=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1']' returned non-zero exit status 100.
2022-03-09 16:45:23.823
2022-03-09 16:45:23.823 The above exception was the direct cause of the following exception:
2022-03-09 16:45:23.823 Traceback (most recent call last):
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/charmcraft/parts.py", line 319, in run
2022-03-09 16:45:23.823 with self._lcm.action_executor() as aex:
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/executor/executor.py", line 255, in __enter__
2022-03-09 16:45:23.823 self._executor.prologue()
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/executor/executor.py", line 86, in prologue
2022-03-09 16:45:23.823 self._install_build_packages()
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/executor/executor.py", line 198, in _install_build_packages
2022-03-09 16:45:23.823 packages.Repository.install_packages(sorted(build_packages))
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/packages/deb.py", line 438, in install_packages
2022-03-09 16:45:23.823 cls._install_packages(packages)
2022-03-09 16:45:23.823 File "/snap/charmcraft/844/lib/craft_parts/packages/deb.py", line 471, in _install_packages
2022-03-09 16:45:23.823 raise errors.BuildPackagesNotInstalled(packages=package_names) from err
2022-03-09 16:45:23.823 craft_parts.packages.errors.BuildPackagesNotInstalled: Cannot install all requested build packages: cargo=0.58.0-0ubuntu1~20.04.1, libstd-rust-1.57=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1, libstd-rust-dev=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1, rustc=1.57.0+dfsg1+llvm-0ubuntu1~20.04.1
2022-03-09 16:45:23.824 Full execution log: '/home/runner/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20220309-164520.979122.log'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without a fix. Maintainer clarified destructive mode requires sudo or preinstalled dependencies by design. The LXD hang was attributed to the GitHub Actions workflow, not charmcraft, and advised filing separately if it persists. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without code changes. Maintainer clarified destructive mode requires sudo or preinstalled dependencies. The LXD hang was attributed to the GitHub Action's exec calls rather than charmcraft, with a suggestion to report it separately. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed as a workflow configuration issue. Maintainers clarified that destructive mode requires sudo or preinstalled dependencies. The LXD hanging problem was advised to be tracked separately. No code changes were made. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without a fix. Maintainer clarified destructive mode requires sudo or preinstalled dependencies, rejecting it as a charmcraft bug. Suggested the LXD hanging warrants a separate report. User workarounds confirmed as expected. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #511 `charmcraft pack` fails running `apt update` | charmcraft | closed | Closed as out of scope. The failure stemmed from an LXD container networking bug, not charmcraft. No code changes were implemented; users were directed to external LXD and Discourse discussions for troubleshooting. | |
| #883 Charmcraft (2.0.0) pack with build-packages failing on GitHub actions (but 2.1.0 - latest/candidate - is working) | charmcraft | closed | Closed as not a Charmcraft bug. The build-packages failure on updated GitHub Actions runners was attributed to an underlying Craft Providers library update. A manual apt-get update workaround exists, and version 2.1.0 resolves the issue. | |
| #1260 Charmcraft hangs or fails with LXD 5.18 | charmcraft | closed | Closed due to an upstream LXD bug. A fix was released for LXD 5.18 compatibility, resolving the hangs and failures. The investigation also uncovered a separate craft-providers issue tracked independently. |