[translated]Apps to Snaps

This commit is contained in:
alim0x 2016-06-05 23:21:49 +08:00
parent 44da04b728
commit fad7d2b611
2 changed files with 61 additions and 63 deletions

View File

@ -1,63 +0,0 @@
alim0x transalting
Apps to Snaps
================
![](https://insights.ubuntu.com/wp-content/uploads/27eb/app-snap.png)
Distributing applications on Linux is not always easy. You have different packaging formats, base systems, available libraries, and distribution release cadences all of which contribute to the headache. But now we have something much simpler: Snaps.
Snaps are a new way for developers to package their applications, bringing with it many advantages over the more traditional package formats such as .deb, .rpm, and others. Snaps are secure, isolated from each other and the host system using technologies such as AppArmor, they are cross-platform, and they are self-contained, allowing a developer to package the exact software their application needs. This sandboxed isolation also improves security and allows applications, and whole snap-based systems, to be rolled back should an issue occur. Snaps really are the future of Linux application packaging.
Creating a snap is not difficult. First, you need the snap-based runtime environment that is able to understand and execute snaps on your desktop; this tool is named snapd and comes as default on all Ubuntu 16.04 systems. Next you need the tool to create snaps, Snapcraft, which can be installed simply with:
```
$ sudo apt-get install snapcraft
```
Once you have this environment available it is time to get snapping.
Snaps use a special YAML formatted file named snapcraft.yaml that defines how the application is packaged as well as any dependencies it may have. Taking a simple application to demonstrate this point, the following YAML file is a real example of how to snap the moon-buggy game, available from the Ubuntu archive.
```
name: moon-buggy
version: 1.0.51.11
summary: Drive a car across the moon
description: |
A simple command-line game where you drive a buggy on the moon
apps:
play:
command: usr/games/moon-buggy
parts:
moon-buggy:
plugin: nil
stage-packages: [moon-buggy]
snap:
usr/games/moon-buggy
```
The above code demonstrates a few new concepts. The first section is all about making your application discoverable in the store; setting the packaging metadata name, version, summary, and description. The apps section implements the play command which points to the location of the moon-buggy executable. The parts section tells Snapcraft about any required plugins that are needed to build the application along with any packages it depends on. In this simple example all we need is the moon-buggy application itself from the Ubuntu archive and Snapcraft takes care of the rest.
Running snapcraft in the directory where you have the snapcraft.yaml file will create the moon-buggy_1.0.51.11_amd64.snap which can be installed by running:
```
$ snap install moon-buggy_1.0.51.11_amd64.snap
```
To seen an example of snapping something a little more complex, like the Electron-based Simplenote application [see here][1], for a tutorial online [here][2] and the corresponding code on [GitHub][3]. More examples can be found on the getting Ubuntu developer [website here][4].
--------------------------------------------------------------------------------
via: https://insights.ubuntu.com/2016/06/01/apps-to-snaps/
作者:[Jamie][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://insights.ubuntu.com/author/jamiebennett/
[1]: http://www.simplenote.com/
[2]: http://www.linuxuk.org/post/20160518_snapping_electron_based_applications_simplenote/
[3]: https://github.com/jamiedbennett/snaps/tree/master/simplenote
[4]: https://developer.ubuntu.com/en/desktop/get-started/

View File

@ -0,0 +1,61 @@
Apps to Snaps
================
![](https://insights.ubuntu.com/wp-content/uploads/27eb/app-snap.png)
在 Linux 分发应用不总是那么容易。你有不同的包格式基础系统可用库以及发行版发布周期所有的这些都让人头疼。但现在我们有了更简单的东西Snap。
Snap 是开发者打包他们应用的新途径,它相对于传统包格式,如 .deb.rpm 等带来了许多优点。Snap 安全,互相独立,宿主系统使用类似 AppArmor 的技术,它们跨平台,而且是自足的,让开发者可以准确打包它们应用所需要的依赖。沙盒隔离也加强了安全,并允许应用和整个基于 snap 的系统在出现问题的时候可以回滚。Snap 确实是 Linux 应用打包的未来。
创建一个 snap 包并不困难。首先,你需要一个 snap 基础运行环境,能够在你的桌面理解和运行 snap这个工具叫做 snapd 并且默认内置于所有 Ubuntu 16.04 系统中。接着你需要创建 snap 的工具Snapcraft可以通过一个简单的命令安装
```
$ sudo apt-get install snapcraft
```
这个环境安装好了之后就可以 snap 起来了。
Snap 使用一个特殊的 YAML 格式文件,称作 snapcraft.yaml它定义了应用是如何打包的以及它需要的依赖。用一个简单的应用来演示一下下面的 YAML 文件是个如何 snap 打包 moon-buggy 游戏的实际例子,该游戏在 Ubuntu 源中提供。
```
name: moon-buggy
version: 1.0.51.11
summary: Drive a car across the moon
description: |
A simple command-line game where you drive a buggy on the moon
apps:
play:
command: usr/games/moon-buggy
parts:
moon-buggy:
plugin: nil
stage-packages: [moon-buggy]
snap:
usr/games/moon-buggy
```
上面的代码演示了几个新概念。第一部分是关于让你的应用可以在商店找到的设置包元数据名称版本号摘要以及描述。Apps 部分实现了运行命令,指向 moon-buggy 可执行文件位置。Parts 部分告诉 snapcraft 用来构建应用所需要的插件以及依赖的包。在这个简单的例子中我们需要的所有东西就是 Ubuntu 源中的 moon-buggy 应用本身snapcraft 负责剩下的工作。
在你的 snapcraft.yaml 所在目录下运行 snapcraft 会创建 moon-buggy_1.0.51.11_amd64.snap 包,可以通过以下命令来安装它:
```
$ snap install moon-buggy_1.0.51.11_amd64.snap
```
想了解更复杂一点的 snap 打包,比如基于 Electron 的 Simplenote [看这里][1],在线教程在[这里][2],相应的代码在[Github][3]。更多的例子可以在这里的 Ubuntu 开发者[站点][4]找到。
--------------------------------------------------------------------------------
via: https://insights.ubuntu.com/2016/06/01/apps-to-snaps/
作者:[Jamie][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://insights.ubuntu.com/author/jamiebennett/
[1]: http://www.simplenote.com/
[2]: http://www.linuxuk.org/post/20160518_snapping_electron_based_applications_simplenote/
[3]: https://github.com/jamiedbennett/snaps/tree/master/simplenote
[4]: https://developer.ubuntu.com/en/desktop/get-started/