canonical / open-documentation-academy

Learn open-source software documentation skills with Canonical
https://canonical.com/documentation
Apache License 2.0
48 stars 28 forks source link

Snapcraft: tutorial error - '/bin/hello' path issue and outdated GNU Bash version #97

Open akcano opened 2 weeks ago

akcano commented 2 weeks ago

Update the following guide:

Create your first snap

Background

Following the tutorial results in an error after adding the initial command:

apps:
  hello:
    command: /bin/hello

Error message:

Generated snap metadata
Command '['snap', 'pack', '--filename', 'hello_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returns non-zero exit status 1.
Failed to execute pack in instance.
Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

Online resources do not provide a solution, and using --debug does not yield better logs. Investigating the VM environment with --debug reveals a different error when running snap pack directly under 'prime':

2024/02/22 20:26:10.165656 container.go:215: in snap "hello": path "bin/hello" does not exist
2024/02/22 20:26:10.165730 container.go:215: in snap "hello": path "bin" does not exist
error: cannot pack ".": snap is unusable due to missing files

The executable is located under usr/local/bin. Changing the command to:

apps:
  hello:
    command: usr/local/bin/hello

resolves the issue. The tutorial might be outdated due to the Usrmerge change. Additionally, the next part of the tutorial (https://ubuntu.com/tutorials/create-your-first-snap#5-a-snap-is-made-of-parts) is also affected. Post-Core20, snapd no longer wraps commands to change paths. Specifying both command paths explicitly resolves the packing issue. However, the provided GNU Bash version 4.3 is outdated and incompatible with the Core22 environment. Updating to GNU Bash version 5.2 fixes this problem.

References:

Prerequisites

Familiarity with Snapcraft or snaps is needed to understand the content and test any conjectures. The documentation is Discourse-hosted, so some experience with Discourse is also a plus.

pgfaller commented 1 week ago

Hi @akcano - please assign this to me. I don't have huge experience with snaps, other than hitting a dead end with https://github.com/canonical/open-documentation-academy/issues/4; but I'll take it on.

pgfaller commented 6 days ago

Hi @akcano / @degville - I've gone through the tutorial and identified the change required. How do I get the changes done on the Discourse page? I don't see any 'Edit' button as I do see on e.g. the Ruby tutorial page. Are there any specific requirements for screenshots, e.g. sizes, aspect ratios, ...? How do screenshots get uploaded?

akcano commented 2 days ago

Hi @pgfaller!

Do you mean there's no Edit button visible here? https://discourse.ubuntu.com/t/create-your-first-snap/14006

If so, it's a matter of permissions, so @degville may be able to help or at least point at someone who can.

As for the screenshots, nothing in the article looks well-regulated, but I'd venture it that keeping to an accepted format works best (e.g. 16:9, 4:3):

degville commented 2 days ago

If so, it's a matter of permissions, so @degville may be able to help or at least point at someone who can.

Thanks for the ping - and yes, it was a permission issue. I've boosted your credentials on the forum @pgfaller, but let me know if this isn't enough. These tutorials are interesting in that they live in a separate Discourse instance to the Snapcraft Discourse, which can be confusing.