如何在创建快照时更快地迭代?

我正在研究一个更大的软件并构建快照,删除旧软件,安装新软件只需要很长时间。

我想迭代创建快照并更快地测试。 我知道snap构建得很好,现在我有兴趣测试启动应用程序及其集成等内容。 有没有办法做到这一点?

前言

解决这个问题的一种方法是使用snap try 。 从它的--help消息:

 The try command installs an unpacked snap into the system for testing purposes. The unpacked snap content continues to be used even after installation, so non-metadata changes there go live instantly. Metadata changes such as those performed in snap.yaml will require reinstallation to go live. 

它还附带一个选项:

 --devmode Install in development mode and disable confinement 

如果您想测试限制位并正确使用接口,这将特别有用。

用法

使用它的方法很简单,只需运行:

 snapcraft prime snap try prime/ 

在第一步,你告诉snapcraft

 Final copy and preparation for the snap. 

在第二步中, snapd使用目录的内容来“安装”快照。 现在,您可以使用该包,同时仍然可以对其进行更改。

让我们使用Snappy Playpen中的一个示例来说明如何使用它。

我们正在使用领事,因为它的构建和使用相对较快:

 $ git clone https://github.com/ubuntu/snappy-playpen $ cd snappy-playpen/consul/ snappy-playpen/consul$ snapcraft prime Preparing to pull consul [...] Staging consul Priming consul snappy-playpen/consul$ 

现在让我们确保我们没有安装其他版本,然后继续安装。

 snappy-playpen/consul$ which consul snappy-playpen/consul$ snap try prime Name Version Rev Developer Notes consul 0.6.4 x1 try snappy-playpen/consul$ consul --help usage: consul [--version] [--help]  [] Available commands are: agent Runs a Consul agent [...] snappy-playpen/consul$ 

到现在为止还挺好。 它似乎工作得很好。 现在让我们用/bin/echo替换它,看看它是如何工作的:

 snappy-playpen/consul$ cp /bin/echo prime/bin/consul snappy-playpen/consul$ consul --help Usage: /snap/consul/x1/bin/consul [SHORT-OPTION]... [STRING]... or: /snap/consul/x1/bin/consul LONG-OPTION Echo the STRING(s) to standard output. [...] daniel@daydream:/tmp/test/snappy-playpen/consul$ 

正如您所看到的,我们可以在处于限制状态的情况下对prime系统进行更改。 这通常是快速启动并运行并经过全面测试的好方法。

注意:对于2.0.10(2016-07-09)之前的snapd ,你必须在运行snapcraft clean之前移动快照,否则snapd会陷入一种糟糕的状态,并抱怨无法找到已安装的快照。 2.0.11还有一些更多的修复,也应该在几天内完成。