Every snap project depends on a file called snapcraft.yaml
, which is the recipe that instructs Snapcraft on how to build it. This page provides an overview of the major sections of a snapcraft.yaml
file.
For practical guidance about how to approach this file and your snap project for the first time, see the Snapcraft checklist. For a reference with all the keys and values available for this file, see the snapcraft.yaml schema.
The snapcraft.yaml
file can be organised into three main sections according to function:
Since the configuration is written in YAML, these sections are merely recommendations to make the file readable for humans. The order of the directives doesn’t affect the build process of Snapcraft.
The first block of the configuration typically contains all the base settings for the snap, which can be roughly split into two categories:
As an example, here are the first lines in snapcraft.yaml
for the Hello World snap:
name: hello
base: core22
version: '2.10'
summary: GNU Hello, the "hello world" snap
description: |
GNU hello prints a friendly greeting.
grade: stable
confinement: strict
The apps
key declares the applications and services that the snap runs. For each app you can declare settings that control how each app is executed and which system resources it can access. Example settings include the path and parameters to run, the app’s environment variables, and other binaries that the app requires.
Continuing with Hello World as an example, here’s its apps
key:
apps:
hello:
command: bin/hello
The parts
key details all of the upstream code components that contribute to the apps inside the snap. Every aspect of the part is managed here, such as its source, dependencies, and how it’s compiled. For a primer on parts, see Adding parts.
Cribbing from Hello World again, this is its parts
key:
parts:
gnu-hello:
source: http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
plugin: autotools
You can pass certain environment variables to Snapcraft during build. See Environment variables that Snapcraft exposes for a list of them.
See Snapcraft advanced grammar to learn how to check for specific conditions for certain keys.
Last updated 2 months ago.