1
1
# Snapcraft: Advanced features
3
3
Once you have built [your first snap](your-first-snap.md), you will probably
4
want to learn more about snapcraft's more advanced features. Having a look at
5
our selection of examples is a good idea, as we want it to be a good showcase
4
want to learn more about snapcraft's more advanced features. Having a look at
5
our selection of examples is a good idea, as we want it to be a good showcase
6
6
of what is possible and generally relevant.
10
Our showcase can be found in the actual source of `snapcraft` itself. Check
10
Our showcase can be found in the actual source of `snapcraft` itself. Check
11
11
it out by simply running:
13
13
bzr branch lp:snapcraft
14
14
cd snapcraft/examples
16
Inspecting the source locally will make easier to build the examples and
17
play around with them. (You can
16
Inspecting the source locally will make easier to build the examples and
17
play around with them. (You can
18
18
[view them online](https://bazaar.launchpad.net/~snappy-dev/snapcraft/core/files/head:/examples/)
34
34
(like description, vendor information and everything else), naming
35
35
the individual parts will define the stucture of your `snapcraft.yaml` file.
36
36
Think of parts as individual components of your snap: Where do you pull them
37
from? How are they built?
37
from? How are they built?
39
39
### Prerequisites during the build
44
44
build-packages: [libssl-dev]
46
46
The above will install the `libssl-dev` package from the Ubuntu archive before
47
an attempted build. If you need a specific version of libssl-dev or a custom
47
an attempted build. If you need a specific version of libssl-dev or a custom
48
48
build, you will need to specify a separate part.
50
50
Also note that the above will not define which libraries are shipped with the
54
54
### Pulling and building
56
56
If you just intend to pull and build the source, take a look at the `gopaste`
57
example. In its `snapcraft.yaml` file you can find just this one `parts`
57
example. In its `snapcraft.yaml` file you can find just this one `parts`
63
63
source: git://github.com/wisnij/gopaste/gopasted
65
65
It starts off with the name of the specific part (`gopaste` here), the origin
66
of the part (it's a `git` URL) and how to build it (plugin: `go-project`).
66
of the part (it's a `git` URL) and how to build it (plugin: `go`).
67
67
Other possible scenarios would be Bazaar or Mercurial branches, or local
70
70
### Mixing and matching plugins
72
72
An interesting example is `py2-project` because it defines only one part
73
(`spongeshaker`), but uses two different plugins (`python2-project` and
74
`make-project) to assemble and build the snap:
73
(`spongeshaker`), but uses two different plugins (`python2` and `make`) to
74
assemble and build the snap:
78
plugin: python2-project
79
79
source: git://github.com/markokr/spongeshaker.git
83
84
The example above mixes and matches parts of different origin. Locally it
84
provides a binary we intend to ship (the `sha3sum.py` script) and a
85
provides a binary we intend to ship (the `sha3sum.py` script) and a
85
86
`Makefile` (to install our script in the right place).
87
88
`spongeshaker` is a python library we will need to pull from git, build as
91
92
binary which you maintain, but require a library you need to build from git
92
93
as opposed to simply including it from the Ubuntu archives.
94
What's happening during the `snapcraft` run is:
95
What's happening during the `snapcraft` run is:
96
97
1. Get `spongeshaker` from `git`.
97
1. Build it as a python project (which will include installing the python
98
1. Build it as a python project (which will include installing the python
98
99
library in the right place).
99
1. Running `make` (from the local `Makefile`) and thus installing our
100
1. Running `make` (from the local `Makefile`) and thus installing our
100
101
`sha3sum.py` script in the right place.
102
103
### Putting your parts in order
104
If your app is comprised of multiple parts, it might be necessary to build
105
If your app is comprised of multiple parts, it might be necessary to build
105
106
and stage parts in a particular order. This can be done by using the `after`
111
112
source: lp:~mterry/+junk/pipelinetest
115
plugin: autotools-project
116
117
source: lp:~mterry/libpipeline/printf
119
120
In the case of the `libpipeline` example above, the part named `pipelinetest`
120
will be built after `libpipeline`. Especially if you need specific
121
will be built after `libpipeline`. Especially if you need specific
121
122
functionality during a build or as part of checks during the `snap` phase,
122
123
this will be handy.
126
127
With snapcraft we want to make it easy to learn from other app vendors and
127
128
re-use parts which have worked well for them.
129
In the `downloader-with-wiki-parts` example, you can see that the `main`
130
In the `downloader-with-wiki-parts` example, you can see that the `main`
135
136
As we never define the `curl` part in the above example, `snapcraft` will
136
check the Ubuntu Wiki, which is where we currently host examples of
137
check the Ubuntu Wiki, which is where we currently host examples of
137
138
successful snapcraft parts. The build order in this case would be `curl`,
143
144
### Individual files
145
146
If you are planning to provide binaries and services to the users of your
146
apps, you need to specify them in your definition first. It's just a matter
147
apps, you need to specify them in your definition first. It's just a matter
147
148
of enumerating them.
149
150
The `godd` example has one binary:
162
163
description: "gopaste"
163
164
start: bin/gopasted
165
You define a name for the service, describe it (so log messages are more
166
descriptive), declare how to run the service and that's it. For more
166
You define a name for the service, describe it (so log messages are more
167
descriptive), declare how to run the service and that's it. For more
167
168
thoughts on services and their security, visit the
168
169
[snappy policy](https://developer.ubuntu.com/en/snappy/guides/security-policy/).
171
172
### Limiting the number of installed files
173
To check the list of files included in your snap, you can use `dpkg -c` on
174
To check the list of files included in your snap, you can use `dpkg -c` on
174
175
the resulting `.snap` file. If you find that certain files should not be
175
shipped to the user (download size being just one factor), you can
176
shipped to the user (download size being just one factor), you can
176
177
explicitly tell `snapcraft` which files to snap: