我们知道在现在的Ubuntu桌面中,我们几乎都使用的是debian包.有的Linux系统上是使用rpm包.在Snappy Ubuntu上,我们使用的包叫做snap包.它的包的扩展名叫做.snap.这是一种崭新的包,和我们以前使用的不一样哦.我们知道debian包的打包非常难懂.相比较而言,snap包的语法就简单得多.今天在我们的教程中,我们来以一个简单的例程来介绍.在以后的教程中,我们用更加详细的方式来介绍snapcraft.snapcraft的功能是:
snap包具有如下的特性:
snapcraft的安装如下.如果大家已经按照"Snappy Ubuntu 入门"文章中介绍的那样就已经安装好了.
$ sudo add-apt-repository ppa:snappy-dev/tools
$ sudo apt-get update
$ sudo apt-get install snappy-tools bzr snapcraft
在安装完上面的包以后 ,我们将得到如下的工具
snappy build - make snap packages out of a file hierarchy
snappy-remote - run snappy operations on remote snappy target by IP
snapcraft - the snap build tool for all snaps
ubuntu-device-flash - image creation tool for snappy ubuntu
我们可以在地址找到snapcraft的源码.里面也有许多的例程供我们来参考.综合下来,一个snap工程有一下几个部分 (icon图片,snapcraft.yaml及应用代码):
$ touch icon.png
如果我们想把我们的snap最终发布到snap商店上,我们必须设计自己的图标.
name: mqtttestclient
version: 1
vendor: Thibaut Rouffineau
summary: MQTT client on Eclipse Foundation sandbox
description: This app is a small client using Eclipse Foundation MQTT client and using the Eclipse Foundation sandbox
icon: ./icons/Paho.png
binaries:
mqttpublish:
exec: python3 bin/mqttpublish
parts:
mqtt:
plugin: python3
source: git://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python
publish:
plugin: copy
files:
./bin/mqttpublish.py: bin/mqttpublish
ant
autotools
catkin
cmake
copy
go
jdk
make
maven
nil
nodejs
python2
python3
qml
roscore
scons
tar-content
$ snapcraft init
name: hello-xiaoguo
version: 1.0.18
vendor: Snappy Developers
icon: hello.png
binaries:
echo:
exec: bin/echo
env:
exec: bin/env
evil:
exec: bin/evil
showdev:
exec: bin/showdev
usehw:
exec: bin/usehw
sh:
exec: bin/sh
summary: Hello xiaoguo
description: This is a simple hello world example
parts:
hello:
plugin: copy
files:
./bin/echo: bin/echo
./bin/env: bin/env
./bin/evil: bin/evil
./bin/showdev: bin/showdev
./bin/usehw: bin/usehw
./bin/sh: bin/sh
liuxg@liuxg:~/snappy/examples/hello-world$ snapcraft
liuxg@liuxg:~/snappy/examples/hello-world$ snapcraft clean
architectures:
- amd64
binaries:
- exec: bin/echo.wrapper
name: echo
- exec: bin/evil.wrapper
name: evil
- exec: bin/usehw.wrapper
name: usehw
- exec: bin/env.wrapper
name: env
- exec: bin/showdev.wrapper
name: showdev
- exec: bin/sh.wrapper
name: sh
icon: meta/hello.png
name: hello-xiaoguo
vendor: Snappy Developers
version: 1.0.18
Hello xiaoguo
This is a simple hello world example
#!/bin/sh
set -e
echo "Hello a nice World!"
echo "This example demonstrates the app confinement"
echo "This app tries to write to its own user directory"
echo "Haha" > $HOME/test.txt
echo "Succeeded! Please find a file created at $HOME/test.txt"
echo "If do not see this, please file a bug"
liuxg@liuxg:~$ snapcraft --help
usage: snapcraft [-h] [-v]
{init,shell,run,list-plugins,clean,pull,build,stage,snap,assemble,all,version,help}
...
positional arguments:
{init,shell,run,list-plugins,clean,pull,build,stage,snap,assemble,all,version,help}
init start a project
shell enter staging environment
run run snap in kvm
list-plugins list the available plugins that handle different types
of a part
clean clean up the environment (to start from scratch)
pull get sources
build build parts
stage put parts into staging area
snap put parts into snap area
assemble (all) make snap package
version show the program's version number and exit
help obtain help for plugins and specific topics
optional arguments:
-h, --help show this help message and exit
-v, --version show the program's version number and exit
liuxg@liuxg:~$ snapcraft help
usage: Get help on additional topics or plugin usage.
snapcraft help topics To get the list of topics
snapcraft help To get help for a specific plugin
snapcraft help To get help on a speficic topic
To see the list of available plugins run
snapcraft list-plugins
snapcraft help: error: the following arguments are required: topic
liuxg@liuxg:~$ snapcraft help python3
The python3 plugin can be used for python 3 based parts.
The python3 plugin can be used for python 3 projects where you would
want to do:
- import python modules with a requirements.txt
- build a python project that has a setup.py
- install sources straight from pip
This plugin uses the common plugin keywords as well as those for "sources".
For more information check the 'plugins' topic for the former and the
'sources' topic for the latter.
Additionally, this plugin uses the following plugin-specific keywords:
- requirements:
(string)
path to a requirements.txt file
- python-packages:
(list)
A list of dependencies to get from PyPi