~snappy-dev/snapcraft/core

« back to all changes in this revision

Viewing changes to docs/snapcraft-advanced-features.md

  • Committer: Sergio Schvezov
  • Date: 2015-10-01 08:54:15 UTC
  • mto: This revision was merged to the branch mainline in revision 225.
  • Revision ID: sergio.schvezov@canonical.com-20151001085415-bnh59efda36tjyt1
Remove the -project from plugin names that have been released and add a deprecation message

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Snapcraft: Advanced features
2
2
 
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.
7
7
 
8
8
## Examples
9
9
 
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:
12
12
 
13
13
        bzr branch lp:snapcraft
14
14
        cd snapcraft/examples
15
15
 
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/)
19
19
as well.)
20
20
 
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?
38
38
 
39
39
### Prerequisites during the build
40
40
 
44
44
        build-packages: [libssl-dev]
45
45
 
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.
49
49
 
50
50
Also note that the above will not define which libraries are shipped with the
54
54
### Pulling and building
55
55
 
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`
58
58
paragraph:
59
59
 
60
60
        parts:
61
61
          gopaste:
62
 
            plugin: go-project
 
62
            plugin: go
63
63
            source: git://github.com/wisnij/gopaste/gopasted
64
64
 
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
68
68
directories.
69
69
 
70
70
### Mixing and matching plugins
71
71
 
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:
75
75
 
76
76
        parts:
77
 
          spongeshaker:
78
 
            plugin: python2-project
 
77
        spongeshaker:
 
78
            plugin: python2
79
79
            source: git://github.com/markokr/spongeshaker.git
80
80
          make-project:
 
81
                  plugin: make
81
82
            source: .
82
83
 
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).
86
87
 
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.
93
94
 
94
 
What's happening during the `snapcraft` run is: 
 
95
What's happening during the `snapcraft` run is:
95
96
 
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.
101
102
 
102
103
### Putting your parts in order
103
104
 
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`
106
107
keyword:
107
108
 
108
109
        parts:
109
110
            pipelinetest:
110
 
                plugin: make-project
 
111
                plugin: make
111
112
                source: lp:~mterry/+junk/pipelinetest
112
113
                after:
113
114
                    - libpipeline
114
115
            libpipeline:
115
 
                plugin: autotools-project
 
116
                plugin: autotools
116
117
                source: lp:~mterry/libpipeline/printf
117
118
 
118
119
 
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.
123
124
 
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.
128
129
 
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`
130
131
part is built:
131
132
 
132
133
                after:
133
134
                    - curl
134
135
 
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`,
138
139
then `main`.
139
140
 
143
144
### Individual files
144
145
 
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.
148
149
 
149
150
The `godd` example has one binary:
162
163
            description: "gopaste"
163
164
            start: bin/gopasted
164
165
 
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/).
169
170
 
170
171
 
171
172
### Limiting the number of installed files
172
173
 
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:
177
178
 
178
179
            snap:
185
186
during the `snap` phase. As you can see above, globs (using asterisks as
186
187
wildcard characters) are a good way of handling complexities within the
187
188
directory structure.
188