#My Notes on My First Snap Building Experience
Hi, I wanted to try building a Snap package, so from my experiment thought on leave what my wandering left me, lot's of this content is from the Ubuntu Desktop Developer website . The website has a nice getting started too! .
I advise using Ubuntu 16.04 LTS as a building environment. I made a clean Virtual Box machine (my main PC is 14.04, but I also prefer a clean environment to work). In the machine, snaps should be already available, so you only need snapcraft. For completeness, the minimum requirement is below. I used a 15 GB drive, but you can sure go smaller if you want.
in command line:
sudo apt install snapd snapcraft
Building a snap app from already existent source is easy. Create an empty dir somewhere.
in command line:
mkdir ~/my1snap
cd ~/my1snap
The most important file in building a snap is the snapcraft YAML file descriptor. I didn't knew YAML before, the most easy docs on it is this ANSIBLE docs , the important thing here is how to list things:
[ apple, banana, coconut]
or
- apple
- banana
- coconut
Now, snapcraft.yaml syntax
is available here
but the best way to dive into it, is really getting started. Since we
are already with terminal opened in that empty my1snap
dir, let's
start.
in command line:
snapcraft init
This will create an almost empty snapcraft.yaml file. It's content must be something like below.
name: # the name of the snap
version: # the version of the snap
summary: # 79 char long summary
description: # A longer description for the snap
Ok, so open this file in your preferred editor and fill the name,
version, summary and description. Just write something at the right of
the :
.
Next, let's look at this tutorial Your First Snap.
name: webcam-webui
version: 1
summary: Webcam web UI
description: Exposes your webcam over a web UI
icon: icon.png
apps:
webcam-webui:
command: bin/webcam-webui
daemon: simple
parts:
golang-static-http:
plugin: go
source: git://github.com/mikix/golang-static-http
stage-packages:
- fswebcam
glue:
plugin: copy
files:
webcam-webui: bin/webcam-webui
From the snapcraft.yaml file here in this tutorial it's possible to
understand that there is a main part called apps
, that let's you
specify a daemon to start and a command to call - for this app. And
also there is the parts
, which contain the pieces that build the app
itself.
You can see that there plugins associated to each piece in the
parts
, these plugins are really a nicely crafted part of snaps.
Let's learn about some plugins.
in command line:
snapcraft help python3
snapcraft help go
snapcraft help copy
So in the python3, for example, you can add an additional line called
python-packages
that will list which python packages you want to
install. You can use source
to point to a source code that will
benefit from those packages.
python-packages: [pack1, pack2]
python-packages:
- pack1
- pack2
You can also add to this piece inside the parts
the stage-packages
which are binaries straight from the apt or more recommended
build-packages
, which will build from source - it's important to
make your snapcraft.yaml file platform agnostic when possible. For
example, the package pillow
in Python requires libjpeg. To build it
from source, add in your piece.
build-packages: [libjpeg-dev]
For building a package that includes a source, it's important that
your source has an adequate setup.py
file, and follows all the
recommended practices of distributing packages in python. If you
don't, it's harder to make it work with snaps. This will be important
for other languages too. The documentation at the moment is a little
small, but I recommend reading and using snapcraft --help
to learn
more. Also any problems in the official docs, fill bug reports, the
developers will answer.
If you are having problems, and everything fails (google, stackoverflow, and others), I would recommend trying the #snappy channel on irc.freenode.net .