Merge lp:~sergiusens/snapcraft/docs into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov on 2015-09-11
Status: Merged
Approved by: Sergio Schvezov on 2015-09-14
Approved revision: 188
Merged at revision: 162
Proposed branch: lp:~sergiusens/snapcraft/docs
Merge into: lp:~snappy-dev/snapcraft/core
Prerequisite: lp:~sergiusens/snapcraft/init
Diff against target: 425 lines (+165/-85)
4 files modified
docs/intro.md (+9/-9)
docs/your-first-snap.md (+130/-59)
examples/webcam-webui/snapcraft.yaml (+25/-15)
examples/webcam-webui/webcam-webui (+1/-2)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/docs
Reviewer Review Type Date Requested Status
John Lenton 2015-09-11 Approve on 2015-09-14
Review via email: mp+270830@code.launchpad.net

Commit Message

docs refresh

Description of the Change

To run through the intro instead of going to the ppa, build a local copy from
these sources by running:

bzr bd; sudo dpkg -i ../build-area/snapcraft_0.2_all.deb

You can review the diff to inspect the changes, but I'd appreciate someone going through

http://bazaar.launchpad.net/~sergiusens/snapcraft/docs/view/head:/docs/your-first-snap.md

To post a comment you must log in.
lp:~sergiusens/snapcraft/docs updated on 2015-09-11
184. By Sergio Schvezov on 2015-09-11

edit, remove list

John Lenton (chipaca) :
Sergio Schvezov (sergiusens) wrote :

thanks for the review

lp:~sergiusens/snapcraft/docs updated on 2015-09-14
185. By Sergio Schvezov on 2015-09-14

review fixes

Sergio Schvezov (sergiusens) wrote :

review fixes are in 185

lp:~sergiusens/snapcraft/docs updated on 2015-09-14
186. By Sergio Schvezov on 2015-09-14

fool proof fix

187. By Sergio Schvezov on 2015-09-14

pedantic

188. By Sergio Schvezov on 2015-09-14

snap crafting all together now

John Lenton (chipaca) wrote :

You have earned an official stamp of approval.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/intro.md'
2--- docs/intro.md 2015-08-05 13:38:39 +0000
3+++ docs/intro.md 2015-09-14 20:53:45 +0000
4@@ -1,8 +1,8 @@
5 # Intro
6
7 Snapcraft allows easy crafting of packages for Snappy Ubuntu. It makes it
8-easy to incorporate components from different sources like GitHub, Launchpad,
9-or npm.
10+easy to incorporate components from different sources and build technologies or
11+solutions.
12
13 # Snappy
14
15@@ -17,8 +17,8 @@
16 # Key concepts
17
18 A `.snap` package for the Ubuntu Core system contains all its
19-dependencies. This has a couple of advantages over traditional deb or
20-rpm based dependency handling, the most important being that a
21+dependencies. This has a couple of advantages over traditional `deb` or
22+`rpm` based dependency handling, the most important being that a
23 developer can always be assured that there are no regressions triggered by
24 changes to the system underneath their app.
25
26@@ -32,12 +32,12 @@
27 build other parts. Each part is managed by a snapcraft plugin and parts
28 are usually independent of each other.
29
30-## Plugins
31+## Type of a Part
32
33-Snapcraft plugins are written in Python and have a yaml
34-description. A lot of default plugins are included, for example for
35-projects written in Go, Java, Python or C. It is also possible
36-to simply download binary content as part of the snapcraft recipe.
37+Each part has a `type` associated to it, this `type` provides the mechanism
38+to handle it. The `type` a part has is extendable through plugins, there are
39+a variety of plugins already included for python 2 and 3, go, java, and cmake or
40+autotools based projects.
41
42 ## Lifecycle
43
44
45=== modified file 'docs/your-first-snap.md'
46--- docs/your-first-snap.md 2015-09-07 13:30:05 +0000
47+++ docs/your-first-snap.md 2015-09-14 20:53:45 +0000
48@@ -15,7 +15,7 @@
49
50 You should also install Snapcraft:
51
52- $ sudo add-apt-repository ppa:snappy-dev/snapcraft-daily
53+ $ sudo add-apt-repository ppa:snappy-dev/tools
54 $ sudo apt-get update
55 $ sudo apt-get install snapcraft
56
57@@ -28,6 +28,9 @@
58 Namely, we'll combine a web server with a webcam program and combine
59 them to serve a new frame every ten seconds.
60
61+> The resulting package is also part of the examples directory in the
62+> [snapcraft sources](http://bazaar.launchpad.net/~snappy-dev/snapcraft/core/files/head:/examples/webcam-webui/)
63+
64 ### The Web Server
65
66 Go has a simple web server in its standard libraries. So let's just use that.
67@@ -40,11 +43,11 @@
68 panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("."))))
69 }
70
71-This will serve the current directory on port `:8080`. If there is an
72-`index.html` in the current directory, it will be served. Otherwise a
73+This will serve the current directory on port `:8080`. If there is an
74+`index.html` in the current directory, it will be served. Otherwise a
75 directory listing will be shown.
76
77-I've provided the above code in a simple GitHub
78+This code is hosted on a simple GitHub
79 [repository](https://github.com/mikix/golang-static-http).
80
81 ### The Webcam Program
82@@ -64,22 +67,53 @@
83 code. It contains a list of `parts`, or pieces of code, and some metadata for
84 the final snap it will create. But let's not worry about the metadata yet.
85
86+### Initializing a project
87+
88+To get started with a base template create a folder that will hold your
89+project, and initialize it:
90+
91+ $ mkdir webcam-webui
92+ $ cd webcam-webui
93+ $ snapcraft init
94+
95+then open the created snapcraft.yaml and edit the templated values for `name`,
96+`version`, `vendor`, `summary` and `description`. You can make it look like
97+this:
98+
99+ name: webcam-webui
100+ version: 1
101+ vendor: You <you@example.com>
102+ summary: Webcam web UI
103+ description: Exposes your webcam over a web UI
104+ icon: icon.png
105+
106+and copy over an icon to `icon.png` or change the path accordingly (if you
107+change the path just make sure it is part of your project directory and that
108+the path is relative to be able to share your snapcrafting):
109+
110+ $ cp /usr/share/icons/hicolor/64/mimetypes/text-x-apport.png ./icon.png
111+
112+If you run `snapcraft` now, it will complain about not having any `parts`.
113+
114+We will look more into this metadata in a bit, but first let's look at adding
115+some `parts`.
116+
117 ### Web Server Part
118
119 Let's start with the web server.
120
121 parts:
122- golang-static-http:
123- plugin: go-project
124+ cam:
125+ type: go-project
126 source: git://github.com/mikix/golang-static-http
127
128-You've got a `parts` list with one item, named `golang-static-http`, but we
129-could call it anything. That part has a few options. A `plugin` option that
130-tells Snapcraft how to interpret the part. In this case, it's a Go project.
131-And finally, a `source` option telling Snapcraft where to download the code.
132+You've just defined a `part` inside `parts` named `cam`, but you
133+could call it anything. That part has a two options: A `type` option that
134+tells Snapcraft how to interpret the part (in this case, it's a Go project),
135+and a `source` option telling Snapcraft where to download the code.
136
137-Go ahead and create `snapcraft.yaml` with the above contents in an empty
138-directory.
139+Go ahead and append the above contents to your recently created
140+`snapcraft.yaml`.
141
142 Now we can build and "stage" this recipe. Staging just means putting the output
143 of the parts in a common folder that has the same layout as the snap we'll
144@@ -88,7 +122,8 @@
145
146 $ snapcraft stage
147
148-You'll see a bunch of output, including Snapcraft downloading the Go compiler.
149+You'll see a bunch of output, including Snapcraft downloading the Go compiler
150+if not already installed on your host build environment.
151 It will use this to compile the code found on GitHub. Eventually when it is
152 done, you'll be able to inspect the `./stage` folder and see the web server
153 executable sitting in `./stage/bin`:
154@@ -96,28 +131,26 @@
155 $ ls stage/bin
156 golang-static-http
157
158-### Webcam Part
159+### Adding an Ubuntu dependency to a part.
160
161 Now let's add the webcam program `fswebcam` to our snap. Edit `snapcraft.yaml`
162-to look like:
163+to make the `cam` part look like:
164
165 parts:
166- golang-static-http:
167- plugin: go-project
168+ cam:
169+ type: go-project
170 source: git://github.com/mikix/golang-static-http
171- fswebcam:
172- plugin: ubuntu
173-
174-We've added a new part called `fswebcam` handled by the `ubuntu` plugin. That
175-plugin will include an Ubuntu package and its dependencies into your snap. It
176-will use the name of the part as the package name to include.
177-
178-Now let's stage our recipe again.
179-
180- $ snapcraft stage
181-
182-You'll note that Snapcraft skipped downloading and building
183-`golang-static-htpp` again because it knew it had already done so.
184+ stage-packages:
185+ - fswebcam
186+
187+We've just added a new property to the `cam` part called `stage-packages` which
188+contains a yaml list with any supporting Ubuntu package we want; in this case
189+our list has one element with an entry for the `fswebcam` Ubuntu `deb` based
190+package.
191+
192+Now let's stage our recipe again (and force it to go through the lifecycle).
193+
194+ $ snapcraft stage --force
195
196 You'll also see Snapcraft downloading and unpacking all the Ubuntu packages
197 into your snap. If you look at `./stage`, you'll see a lot more files now:
198@@ -125,7 +158,7 @@
199 $ ls stage
200 bin etc lib usr var
201
202-### Gluing the Parts Together
203+### A copy Part
204
205 OK, so we have the two programs in our staging area. But how do we make them
206 work together?
207@@ -135,7 +168,7 @@
208 #!/bin/sh
209 set -e
210
211- cd "$SNAPP_APP_DATA_PATH"
212+ cd "$SNAP_APP_DATA_PATH"
213
214 golang-static-http &
215
216@@ -151,19 +184,19 @@
217 Alright, let's put this script in our snap too:
218
219 parts:
220- golang-static-http:
221- plugin: go-project
222+ cam:
223+ type: go-project
224 source: git://github.com/mikix/golang-static-http
225- fswebcam:
226- plugin: ubuntu
227+ stage-packages:
228+ - fswebcam
229 glue:
230- plugin: copy
231+ type: copy
232 files:
233 webcam-webui: bin/webcam-webui
234
235-The `copy` plugin takes a list of files to just directly copy without building
236-or downloading anything. In this case, we just want to put our glue script in
237-the `bin/` directory.
238+A part of type `copy` takes a list of files to just directly copy without
239+building or downloading anything. In this case, we just want to put our glue
240+script in the `bin/` directory.
241
242 If we run Snapcraft again, we won't be surprised:
243
244@@ -175,26 +208,69 @@
245 $ ls stage/bin
246 golang-static-http webcam-webui
247
248-### Package Metadata
249-
250-"But how do we actually make a snap?", you may be wondering. To do that, we
251-need to add some Snappy metadata that describes how our code should be
252-installed and run.
253-
254-You can read all about the [format of this metadata](https://developer.ubuntu.com/en/snappy/guides/packaging-format-apps/),
255+### Filesets
256+
257+Some files in `./stage` could be needed for building dependent parts during the
258+staging phase and some of these would be useful for the resulting snap. In
259+this case we don't need some of these for either staging or the resulting snap,
260+so let's add some filesets for the snap.
261+
262+Edit `snapcraft.yaml` once more to make the `cam` part in `parts` to look like:
263+
264+ parts:
265+ cam:
266+ type: go-project
267+ source: git://github.com/mikix/golang-static-http
268+ stage-packages:
269+ - fswebcam
270+ filesets:
271+ fswebcam:
272+ - usr/bin/fswebcam
273+ - lib
274+ - usr/lib
275+ go-server:
276+ - bin/golang-*
277+ snap:
278+ - $fswebcam
279+ - $go-server
280+ glue:
281+ type: copy
282+ files:
283+ webcam-webui: bin/webcam-webui
284+
285+What we did was add two `filesets`, one named `fswebcam` and another one named
286+`go-server` and then added a `snap` entry referencing these two filesets with
287+`$`. All these filesets are inclusion based filesets, you can use `*` to glob
288+many files and directories (if `*` is the first character, it needs to be
289+quoted e.g.; `'*'`). An exclusion can be added by prefixing the file
290+with a `-`. Additionally, you don't need to define a fileset, you can explicitly
291+mention the file, directory or match under `snap` or `stage`.
292+
293+### Extending the Metadata
294+
295+The defined values in `snapcraft.yaml` are used to build the corresponding
296+`meta` directory that holds all the package information.
297+
298+You can read all about the resulting [format of this metadata](https://developer.ubuntu.com/en/snappy/guides/packaging-format-apps/),
299 but we'll assume here that you're already familiar.
300
301-Let's add some metadata to our snapcraft file
302+The templated values when `snapcraft init` was run did not hold any `parts`
303+which we've filled along the way. It also did not define any `services` or
304+`binaries` which we will be adding now
305+
306+Edit `snapcraft.yaml` once more and add the `services` and `binaries` entry,
307+your resulting `snapcraft.yaml` should look very similar to:
308
309 name: webcam-webui
310 version: 1
311 vendor: You <you@example.com>
312+ summary: Webcam web UI
313+ description: Exposes your webcam over a web UI
314+ icon: icon.png
315 services:
316 - name: webcam-webui
317 start: bin/webcam-webui
318- summary: Webcam web UI
319- description: Exposes your webcam over a web UI
320- icon: icon.png
321+
322 parts:
323 golang-static-http:
324 plugin: go-project
325@@ -206,13 +282,9 @@
326 files:
327 webcam-webui: bin/webcam-webui
328
329-Copy a png icon of your choice into your current directory:
330-
331- $ cp /usr/share/icons/hicolor/64/mimetypes/text-x-apport.png ./icon.png
332-
333 and tell Snapcraft to actually make the snap package:
334
335- $ snapcraft assemble
336+ $ snapcraft
337
338 You should now have a `webcam-webui_1_amd64.snap` file sitting in your
339 directory (assuming you are running on amd64). Congratulations!
340@@ -221,13 +293,13 @@
341 ## Next steps
342
343 Well done, your first snap using snapcraft is ready. If you want to check out
344-a few examples for reference or to get inspired, have a look at the
345+a few examples for reference or to get inspired, have a look at the
346 `examples` directory in the source directory of snapcraft:
347
348 bzr branch lp:snapcraft
349 cd snapcraft/examples
350
351-In `examples/` you can find a diverse set of examples which should help you
352+In `examples/` you can find a diverse set of examples which should help you
353 get started on your own projects.
354
355 If you should have any more questions, ask us on
356@@ -235,4 +307,3 @@
357 * `#snappy` on `irc.freenode.net` or
358 * the [snappy-app-devel](https://lists.ubuntu.com/mailman/listinfo/snappy-app-devel)
359 mailing list
360-
361
362=== renamed directory 'examples/webcam-webui-snap' => 'examples/webcam-webui'
363=== modified file 'examples/webcam-webui/snapcraft.yaml'
364--- examples/webcam-webui-snap/snapcraft.yaml 2015-09-08 11:48:30 +0000
365+++ examples/webcam-webui/snapcraft.yaml 2015-09-14 20:53:45 +0000
366@@ -1,21 +1,31 @@
367 name: webcam-webui
368-version: 1.0.0
369-vendor: Loïc Minier <loic.minier@ubuntu.com>
370-services:
371- - name: webcam-webui
372- start: bin/webcam-webui
373- security-template: unconfined
374+version: 1
375+vendor: Vendor <email@example.com>
376 summary: Webcam web UI
377 description: Exposes your webcam over a web UI
378 icon: icon.png
379+services:
380+ - name: webcam-webui
381+ start: bin/webcam-webui
382
383 parts:
384- golang-static-http:
385- type: go-project
386- source: git://github.com/mikix/golang-static-http
387- glue:
388- type: copy
389- stage-packages:
390- - fswebcam
391- files:
392- webcam-webui: bin/webcam-webui
393+ cam:
394+ type: go-project
395+ source: git://github.com/mikix/golang-static-http
396+ stage-packages:
397+ - fswebcam
398+ filesets:
399+ fswebcam:
400+ - usr/bin/fswebcam
401+ - lib
402+ - usr/lib
403+ go-server:
404+ - bin/golang-*
405+ snap:
406+ - $fswebcam
407+ - $go-server
408+ glue:
409+ type: copy
410+ files:
411+ webcam-webui: bin/webcam-webui
412+
413
414=== modified file 'examples/webcam-webui/webcam-webui'
415--- examples/webcam-webui-snap/webcam-webui 2015-07-28 20:09:09 +0000
416+++ examples/webcam-webui/webcam-webui 2015-09-14 20:53:45 +0000
417@@ -1,8 +1,7 @@
418 #!/bin/sh
419-
420 set -e
421
422-cd "$SNAPP_APP_DATA_PATH"
423+cd "$SNAP_APP_DATA_PATH"
424
425 golang-static-http &
426

Subscribers

People subscribed via source and target branches