How to pack your hooks-based charm with Charmcraft

See also:

You want a hooks-based charm. Such a charm cannot be initialised with Charmcraft. However, it can be packed with Charmcraft. This document shows you how.

Introduced in Charmcraft 1.4

Suppose you have a hooks-only charm, for example, tiny-bash, which you can obtain as follows:

$ git clone https://github.com/erik78se/tiny-bash

To make it packable by Charmcraft, all you need to do is navigate inside the charm directory and create a charmcraft.yaml file with the part definition for a hooks-based charm, as shown below:

type: charm

bases:
  - build-on:
    - name: "ubuntu"
      channel: "20.04"
    run-on:
    - name: "ubuntu"
      channel: "20.04"

parts:
  tiny-bash:
    plugin: dump
    source: .
    prime:
      - LICENSE
      - README.md
      - config.yaml
      - copyright
      - hooks
      - icon.svg
      - metadata.yaml

After this, you can pack your charm with charmcraft pack, as usual:

$ charmcraft pack
Charms packed:
    tiny-bash_ubuntu-20.04-amd64.charm

If successful, the result should look as below, i.e., the charm file should contain all the files listed in the prime section of the tiny-bash part and the charm manifest.

$ unzip -l tiny-bash_ubuntu-20.04-amd64.charm
Archive:  tiny-bash_ubuntu-20.04-amd64.charm
  Length      Date    Time    Name
---------  ---------- -----   ----
      423  2021-11-12 19:37   metadata.yaml
      431  2021-11-12 19:37   README.md
       12  2021-11-12 19:37   config.yaml
     3693  2021-11-12 19:37   icon.svg
       38  2021-11-12 19:37   copyright
      261  2021-11-12 20:08   manifest.yaml
    34523  2021-11-12 19:37   LICENSE
      381  2021-11-12 19:37   hooks/update-status
      346  2021-11-12 19:37   hooks/start
     1294  2021-11-12 19:37   hooks/shared-fs-relation-changed
      563  2021-11-12 19:37   hooks/stop
      497  2021-11-12 19:37   hooks/leader-elected
      447  2021-11-12 19:37   hooks/install
      417  2021-11-12 19:37   hooks/leader-settings-changed
      811  2021-11-12 19:37   hooks/upgrade-charm
      625  2021-11-12 19:37   hooks/config-changed
---------                     -------
    44762                     16 files

And you can also deploy your application with juju deploy, as usual:

$ juju deploy ./tiny-bash_ubuntu-20.04-amd64.charm
Located local charm "tiny-bash", revision 0
Deploying "tiny-bash" from local charm "tiny-bash", revision 0

If successful, the result should look as below, i.e., with the application status active.

$ juju status
Model    Controller           Cloud/Region         Version  SLA          Timestamp
default  localhost-localhost  localhost/localhost  2.9.12   unsupported  17:23:23-03:00

App        Version  Status  Scale  Charm      Store  Channel  Rev  OS      Message
tiny-bash           active      1  tiny-bash  local             0  ubuntu  update-status ran: 20:22

Unit          Workload  Agent  Machine  Public address  Ports  Message
tiny-bash/0*  active    idle   0        10.2.17.31             update-status ran: 20:22

Machine  State    DNS         Inst id        Series  AZ  Message
0        started  10.2.17.31  juju-55481c-0  focal       Running
3 Likes

I should probably update this tutorial/repo to make some adjustments to the charmcraft tool


@cmatsuoka I think I hit a bug when adding your suggestion and trying to charmcraft build on version 1.3.1 of charmcraft.

charmcraft build fails.

2021-11-22 23:36:00,821  charmcraft.providers._logs               DEBUG    :: mm 2021-11-22 22:36:00,006  charmcraft                               ERROR    Parts processing error: Failed to copy '/root/stage/src': no such file or directory. (full execution logs in '/tmp/charmcraft.log')
2021-11-22 23:36:00,834  craft_providers.lxd.lxc                  DEBUG    Executing on host: lxc --project charmcraft config device show local:charmcraft-tiny-bash-6559631-0-0-amd64
2021-11-22 23:36:00,915  craft_providers.lxd.lxc                  DEBUG    Executing on host: lxc --project charmcraft config device remove local:charmcraft-tiny-bash-6559631-0-0-amd64 disk-/root/project
2021-11-22 23:36:01,134  craft_providers.lxd.lxc                  DEBUG    Executing on host: lxc --project charmcraft stop local:charmcraft-tiny-bash-6559631-0-0-amd64
2021-11-22 23:36:03,601  charmcraft                               ERROR    Failed to build charm for bases index '0'. (full execution logs in '/home/erik/snap/charmcraft/common/charmcraft-log-m8cxkcx3')

@erik-lonroth This is a strange error, is it reproducible? If it builds correctly after you run charmcraft clean, I suspect it is a manifestation of issue 501. Did you do anything different that may have triggered this error?

erik@pixel:~/PycharmProjects/tiny-bash$ charmcraft clean
Cleaned project 'tiny-bash'.
erik@pixel:~/PycharmProjects/tiny-bash$ charmcraft build
Packing charm 'tiny-bash_ubuntu-20.04-amd64_ubuntu-18.04-amd64.charm'...
Parts processing error: Failed to copy '/root/stage/src': no such file or directory. (full execution logs in '/tmp/charmcraft.log')
Failed to build charm for bases index '0'. (full execution logs in '/home/erik/snap/charmcraft/common/charmcraft-log-ig7ib2l6')

Yes.

Logs:

2021-11-23 22:37:12,268  charmcraft.providers._logs               DEBUG    :: mm 2021-11-23 21:37:11,595  craft_parts.executor.executor            DEBUG    execute action charm:Action(part_name='charm', step=Step.PRIME, action_type=ActionType.RUN, reason=None)
2021-11-23 22:37:12,268  charmcraft.providers._logs               DEBUG    :: mm 2021-11-23 21:37:11,601  charmcraft                               ERROR    Parts processing error: Failed to copy '/root/stage/src': no such file or directory. (full execution logs in '/tmp/charmcraft.log')
2021-11-23 22:37:12,269  craft_providers.lxd.lxc                  DEBUG    Executing on host: lxc --project charmcraft config device show local:charmcraft-tiny-bash-6559631-0-0-amd64
2021-11-23 22:37:12,386  craft_providers.lxd.lxc                  DEBUG    Executing on host: lxc --project charmcraft config device remove local:charmcraft-tiny-bash-6559631-0-0-amd64 disk-/root/project
2021-11-23 22:37:12,563  craft_providers.lxd.lxc                  DEBUG    Executing on host: lxc --project charmcraft stop local:charmcraft-tiny-bash-6559631-0-0-amd64
2021-11-23 22:37:14,364  charmcraft                               ERROR    Failed to build charm for bases index '0'. (full execution logs in '/home/erik/snap/charmcraft/common/charmcraft-log-ig7ib2l6')

What filesystem is this host (pixel) on for ~/PycharmProjects/tiny-bash?

cat /etc/mtab | grep sda

/dev/sda2 / ext4 rw,relatime,errors=remount-ro 0 0

Sorry for taking so long to get back to you, Can you please provide the output for

  • lxc storage list
  • lxc profile show default
  • lxc list --format yaml charmcraft-tiny-bash-6559631-0-0-amd64 (or new container name from the logs)

Charmcraft 1.3.1 is expected to fail. The changes need to pack hooks-based charms are currently available only in the edge channel.

Using 1.3.1:

$ charmcraft pack
Packing charm 'tiny-bash_ubuntu-20.04-amd64.charm'...
Parts processing error: Failed to copy '/root/stage/src': no such file or directory. (full execution logs in '/tmp/charmcraft.log')
Failed to build charm for bases index '0'. (full execution logs in '/home/claudio/snap/charmcraft/common/charmcraft-log-1rta109t')

Using 1.3+152.g32c8650:

$ charmcraft pack                                                                                             
Charms packed:                                                                                                                                                                           
    tiny-bash_ubuntu-20.04-amd64.charm                                          
2 Likes

@emcp this is why.

Charmcraft 1.4 is now available in candidate and can be used to pack hooks-based charms.

2 Likes

Charmcraft 1.4 released to stable.

2 Likes

I have an existing charm I’d like to use charmcraft to pack, but the execution fails with Parts processing error: Failed to copy '/root/stage/src': no such file or directory.

Is there some way I can go about excluding this directory, which is not present on the charm?

Would that also affect Reactive charms in the same way?

This is my charmcraft.yaml for reference - I’ve added some extra items there for the charm which may have been missing from the original example, if they’re not automatically picked up already.

type: charm

bases:
  - build-on:
    - name: "ubuntu"
      channel: "20.04"
    run-on:
    - name: "ubuntu"
      channel: "20.04"
    - name: "ubuntu"
      channel: "18.04"

parts:
  tiny-bash:
    plugin: dump
    source: .
    prime:
      - LICENSE
      - README.md
      - config.yaml
      - copyright
      - hooks
      - icon.svg
      - metadata.yaml
      - actions
      - actions.yaml
      - lib
      - templates
      - files
      - mod

Would you please clean up the environment (charmcraft clean) and try to pack again? Then if still failing provide us the logs, thanks!

1 Like

Hi,

Tried again immediately after a charmcraft clean, here’s the log:

xav@xplt:~/charms/charm-nrpe$ charmcraft pack
Failed to build charm for bases index '0'.                                                                                                                                                                       
Full execution log: '/home/xav/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20220203-081935.856566.log'                                                                                                
xav@xplt:~/charms/charm-nrpe$ cat /home/xav/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20220203-081935.856566.log
2022-02-03 08:19:35.857 Starting charmcraft version 1.4.0+28.gbe5c58d
2022-02-03 08:19:35.857 Raw pre-parsed sysargs: args={'help': False, 'verbose': False, 'quiet': False, 'trace': False, 'project_dir': None} filtered=['pack']
2022-02-03 08:19:35.857 General parsed sysargs: command='pack' args=[]
2022-02-03 08:19:35.860 Command parsed sysargs: Namespace(bases_index=None, debug=False, destructive_mode=False, entrypoint=None, force=False, requirement=None, shell=False, shell_after=False)
2022-02-03 08:19:35.860 Packing the charm.
2022-02-03 08:19:35.860 Working arguments: {'from': PosixPath('/home/xav/charms/charm-nrpe'), 'destructive_mode': False, 'entrypoint': None, 'requirement': [], 'bases_indices': None, 'force': False, 'debug': False, 'shell': False, 'shell_after': False}
2022-02-03 08:19:35.860 Parsing '/home/xav/charms/charm-nrpe/metadata.yaml'
2022-02-03 08:19:36.127 Executing on host: lxc --project default profile show local:default
2022-02-03 08:19:36.188 Building for 'bases[0]' as host matches 'build-on[0]'.
2022-02-03 08:19:36.188 Building for 'bases[0][0]'.
2022-02-03 08:19:36.188 Launching environment to pack for base name='ubuntu' channel='20.04' architectures=['amd64']
2022-02-03 08:19:36.188 Executing on host: lxc remote list --format=yaml
2022-02-03 08:19:36.244 Remote 'craft-com.ubuntu.cloud-buildd' already exists.
2022-02-03 08:19:36.244 Executing on host: lxc project list local: --format=yaml
2022-02-03 08:19:36.308 Executing on host: lxc --project charmcraft list local: --format=yaml
2022-02-03 08:19:36.485 Executing on host: lxc --project charmcraft image list local: --format=yaml
2022-02-03 08:19:36.555 Using compatible snapshot 'snapshot-craft-com.ubuntu.cloud-buildd-20.04-charmcraft-buildd-base-v0.0'.
2022-02-03 08:19:36.555 Executing on host: lxc --project charmcraft info local:
2022-02-03 08:19:36.649 Executing on host: lxc --project charmcraft launch local:snapshot-craft-com.ubuntu.cloud-buildd-20.04-charmcraft-buildd-base-v0.0 local:charmcraft-nrpe-9315395-0-0-amd64 --config 'raw.idmap=both 1000 0' --config security.syscalls.intercept.mknod=true
2022-02-03 08:19:38.889 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 cat /etc/os-release
2022-02-03 08:19:38.986 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2022-02-03 08:19:39.082 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 cat /etc/craft-instance.conf
2022-02-03 08:19:39.187 Executing on host: lxc --project charmcraft file push /home/xav/snap/charmcraft/common/tmpxebnpu04 local:charmcraft-nrpe-9315395-0-0-amd64/etc/environment --mode=0644
2022-02-03 08:19:39.269 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 chown root:root /etc/environment
2022-02-03 08:19:39.389 Waiting for environment to be ready...
2022-02-03 08:19:39.390 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:39.507 systemctl is-system-running status: starting
2022-02-03 08:19:39.757 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:39.862 systemctl is-system-running status: starting
2022-02-03 08:19:40.112 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:40.199 systemctl is-system-running status: starting
2022-02-03 08:19:40.450 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:40.562 systemctl is-system-running status: starting
2022-02-03 08:19:40.812 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:40.900 systemctl is-system-running status: starting
2022-02-03 08:19:41.151 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:41.238 systemctl is-system-running status: starting
2022-02-03 08:19:41.489 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-02-03 08:19:41.626 Executing on host: lxc --project charmcraft file push /home/xav/snap/charmcraft/common/tmp6fyw3v3t local:charmcraft-nrpe-9315395-0-0-amd64/etc/craft-instance.conf --mode=0644
2022-02-03 08:19:41.695 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 chown root:root /etc/craft-instance.conf
2022-02-03 08:19:41.785 Executing on host: lxc --project charmcraft file push /home/xav/snap/charmcraft/common/tmpu1xlfetk local:charmcraft-nrpe-9315395-0-0-amd64/etc/hostname --mode=0644
2022-02-03 08:19:41.854 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 chown root:root /etc/hostname
2022-02-03 08:19:41.946 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 hostname -F /etc/hostname
2022-02-03 08:19:42.037 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
2022-02-03 08:19:42.138 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl enable systemd-resolved
2022-02-03 08:19:42.313 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl restart systemd-resolved
2022-02-03 08:19:42.673 Executing on host: lxc --project charmcraft file push /home/xav/snap/charmcraft/common/tmpawzw764l local:charmcraft-nrpe-9315395-0-0-amd64/etc/systemd/network/10-eth0.network --mode=0644
2022-02-03 08:19:42.739 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 chown root:root /etc/systemd/network/10-eth0.network
2022-02-03 08:19:42.836 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl enable systemd-networkd
2022-02-03 08:19:43.008 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl restart systemd-networkd
2022-02-03 08:19:43.357 Waiting for networking to be ready...
2022-02-03 08:19:43.357 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 getent hosts snapcraft.io
2022-02-03 08:19:43.757 Executing on host: lxc --project charmcraft file push /home/xav/snap/charmcraft/common/tmpjj1ai0p_ local:charmcraft-nrpe-9315395-0-0-amd64/etc/apt/apt.conf.d/00no-recommends --mode=0644
2022-02-03 08:19:43.854 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 chown root:root /etc/apt/apt.conf.d/00no-recommends
2022-02-03 08:19:43.961 Executing on host: lxc --project charmcraft file push /home/xav/snap/charmcraft/common/tmpai64zxz6 local:charmcraft-nrpe-9315395-0-0-amd64/etc/apt/apt.conf.d/00update-errors --mode=0644
2022-02-03 08:19:44.027 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 chown root:root /etc/apt/apt.conf.d/00update-errors
2022-02-03 08:19:44.125 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 apt-get update
2022-02-03 08:19:50.069 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 apt-get install -y apt-utils
2022-02-03 08:19:50.879 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 apt-get install -y fuse udev
2022-02-03 08:20:07.288 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl enable systemd-udevd
2022-02-03 08:20:07.483 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl start systemd-udevd
2022-02-03 08:20:07.594 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 apt-get install -y snapd
2022-02-03 08:20:28.275 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl start snapd.socket
2022-02-03 08:20:28.456 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl restart snapd.service
2022-02-03 08:20:28.991 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 snap wait system seed.loaded
2022-02-03 08:20:29.144 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 rm -f /tmp/charmcraft.snap
2022-02-03 08:20:29.382 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 test -d /tmp
2022-02-03 08:20:29.509 Executing on host: lxc --project charmcraft file push /home/xav/tmp_nsy7g55.tmp-craft/charmcraft.snap local:charmcraft-nrpe-9315395-0-0-amd64/tmp/charmcraft.snap --gid=0 --uid=0
2022-02-03 08:20:30.493 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 snap install /tmp/charmcraft.snap --classic --dangerous
2022-02-03 08:20:37.900 Executing on host: lxc --project charmcraft config device show local:charmcraft-nrpe-9315395-0-0-amd64
2022-02-03 08:20:38.013 Executing on host: lxc --project charmcraft config device add local:charmcraft-nrpe-9315395-0-0-amd64 disk-/root/project disk source=/home/xav/charms/charm-nrpe path=/root/project
2022-02-03 08:20:38.124 Packing the charm
2022-02-03 08:20:38.125 Running ['charmcraft', 'pack', '--bases-index', '0']
2022-02-03 08:20:38.125 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 --cwd /root/project -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 charmcraft pack --bases-index 0
Parts processing error: Failed to copy '/root/stage/lib': no such file or directory.                      
2022-02-03 08:20:44.397 :: Full execution log: '/root/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20220202-192040.503120.log'
2022-02-03 08:20:44.598 Executing in container: lxc --project charmcraft exec local:charmcraft-nrpe-9315395-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 test -f /tmp/charmcraft.log
2022-02-03 08:20:44.904 No logs found in instance.
2022-02-03 08:20:44.905 Executing on host: lxc --project charmcraft config device show local:charmcraft-nrpe-9315395-0-0-amd64
2022-02-03 08:20:45.012 Executing on host: lxc --project charmcraft config device remove local:charmcraft-nrpe-9315395-0-0-amd64 disk-/root/project
2022-02-03 08:20:45.145 Executing on host: lxc --project charmcraft stop local:charmcraft-nrpe-9315395-0-0-amd64
2022-02-03 08:20:46.850 Failed to build charm for bases index '0'.
2022-02-03 08:20:46.853 Traceback (most recent call last):
2022-02-03 08:20:46.853   File "/snap/charmcraft/786/lib/charmcraft/commands/build.py", line 448, in pack_charm_in_instance
2022-02-03 08:20:46.853     instance.execute_run(
2022-02-03 08:20:46.853   File "/snap/charmcraft/786/lib/craft_providers/lxd/lxd_instance.py", line 221, in execute_run
2022-02-03 08:20:46.853     return self.lxc.exec(
2022-02-03 08:20:46.853   File "/snap/charmcraft/786/lib/craft_providers/lxd/lxc.py", line 307, in exec
2022-02-03 08:20:46.853     return runner(final_cmd, **kwargs)  # pylint: disable=subprocess-run-check
2022-02-03 08:20:46.853   File "/snap/charmcraft/786/usr/lib/python3.8/subprocess.py", line 516, in run
2022-02-03 08:20:46.853     raise CalledProcessError(retcode, process.args,
2022-02-03 08:20:46.853 subprocess.CalledProcessError: Command '['lxc', '--project', 'charmcraft', 'exec', 'local:charmcraft-nrpe-9315395-0-0-amd64', '--cwd', '/root/project', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'CHARMCRAFT_MANAGED_MODE=1', 'charmcraft', 'pack', '--bases-index', '0']' returned non-zero exit status 1.
2022-02-03 08:20:46.853 Full execution log: '/home/xav/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20220203-081935.856566.log'

Hey @xavpaice, thanks for the report. I’m still struggling to understand what’s going on, so I have some questions and a suggestion.

  • It looks you’re defining your own part (tiny-bash), overriding the default charm packing mechanism. Is that on purpose? if not, you should call your part charm. If yes, probably the prime directive is misused there.

  • Are you trying to build a reactive charm? If yes, you should use the reactive plugin.

Regarding the suggestion
 I forgot to tell you to run Charmcraft in verbose mode, as we had a glitch retrieving the logs from the building instance (which we fixed already, a couple of commits more recent than the version you’re using). It would be charmcraft --verbose pack. Can you try it this way? Thanks!

The part tiny-bash is from the tutorial above. This isn’t a reactive charm, it’s hooks based.

I have had more success by copying a charmcraft.yaml from the Keystone charm, which uses the same dump plugin, but the syntax for the list of files to prime includes wildcards like this:

  charm:
    plugin: dump
    source: .
    prime:
      - actions/*
      - files/*
      - hooks/*
      - hooks/charmhelpers/*
      - templates/*
      - actions.yaml
      - config.yaml
      - copyright
      - LICENSE
      - metadata.yaml
      - README.md
1 Like

And that works ok, right?

1 Like

yes, it works well with the wildcards. Perhaps we could edit the original tutorial to add the wildcards, and make it clear that the ‘tiny-bash’ part isn’t some special name, but the charm name?

Where is the code for the bash version of “charmhelpers” ? That would be very useful for stuff like open/close ports etc.