The Snapcraft tool can perform a variety of operations, including:
These operations translate into practical tasks like:
The list of available global options and commands can be checked with one of:
snapcraft help
snapcraft help --all
Snaps are created using a build recipe defined in a file called snapcraft.yaml
.
When the snapcraft tool is executed on the command line, it will look for the file in the current project work directory, either in the top-level folder or a snap
subdirectory. If the file is found, snapcraft will then parse its contents and progress the build toward completion.
snapcraft.yaml
is a configuration file written in the YAML language, with stanzas defining the application structure and behavior. When snapcraft runs and parses this file, it will use the declared information to build the snap. For developers more familiar with the traditional Linux build systems, the process is somewhat similar to the use of a Makefile or an RPM spec file.
You can create the snapcraft.yaml
file manually, or you can run the snapcraft init
command to create a template file in the snap
subdirectory.
snapcraft init
A generated template file contains just enough data to build, split across three stanzas:
There is no one way for how a snap ought to be assembled. However, most snapcraft.yaml
files have the same common elements, including a number of mandatory declarations. Below is a short list of these keys, which will be further explained in the Examples sections later in the tutorial.
It is important to note several additional details:
snapcraft.yaml
file uses Snapcraft build system or language-specific plugins to simplify the build process.The parts section may also include a list of stage packages (stage-packages) that will be used by the snap’s applications at runtime, e.g.: python-bcrypt. These will be obtained from the repository archives in the build instance.
Snaps are built in several steps, collectively known as the “lifecycle”:
The artifact of a successful Snapcraft build run is a snap file, which is itself a compressed Squashfs archive distinguished by the .snap suffix.
A snap may contain one or more files that allow the applications to run without reliance on the underlying host system’s libraries. A snap will contain one or more applications, daemons, configuration files, assets like icons, and other objects.
Typically, the content of a snap will resemble a Linux filesystem layout:
drwxr-xr-x 10 igor igor 4096 Jun 10 2020 ./
drwxrwxrwx 14 igor igor 16384 Oct 17 16:40 ../
drwxr-xr-x 2 igor igor 4096 Jun 10 2020 bin/
drwxr-xr-x 10 igor igor 4096 Jun 10 2020 etc/
-rw-r--r-- 1 igor igor 14 Jun 10 2020 flavor-select
drwxr-xr-x 3 igor igor 4096 Jun 10 2020 lib/
drwxr-xr-x 2 igor igor 4096 Jun 10 2020 lib64/
drwxr-xr-x 3 igor igor 4096 Jun 10 2020 meta/
drwxr-xr-x 3 igor igor 4096 Jun 10 2020 snap/
drwxr-xr-x 7 igor igor 4096 Jun 10 2020 usr/
drwxr-xr-x 3 igor igor 4096 Feb 26 2018 var/
The end user can examine the contents of a snap by either looking through the ‘prime’ directory of the build environment, or by extracting the snap archive:
unsquashfs <file>.snap
Last updated 1 year, 2 months ago.