在Circleci上使用Snapcraft构建和发布Snap Packages
Snap packages provide a quick way to publish your software on multiple Linux distributions (distros). This document shows you how to build a snap package and publish it to the Snap Store using CircleCI.
概要
A.snap.
file can be created once and installed on any Linux distro that supportsSNAPD.
, such as Ubuntu, Debian, Fedora, Arch, and more. More information on Snapcraft itself can be found onSnapcraft’s website。
在Circleci上建立一个捕捉大多数与您的本地机器相同,包裹circleci 2.0语法。本文档介绍如何构建捕捉包并将其发布到Snap Store通过Circleci。以下部分使用样本的片段。Circleci./config.yml
file with the full version at theend of this doc。
Prerequisites
To build a snap in any environment (local, company servers CI, etc) there needs to be a Snapcraft config file. Typically this will be located atsnap/snapcraft.yml
。此文档假定您已经拥有此文件,可以在本地计算机上成功构建SNAP。如果没有,你可以阅读Build Your First Snapdoc by snapcraft将您的当地机器上的捕捉构建。
建立环境
# ...version:2工作s:建立:Docker.:-image:cibuilds/snapcraft:stableauth:username:mydockerhub-user密码:$ dockerhub_password.#上下文/项目UI ENV-VAR参考#...
TheDocker.
executor is used here with thecibuilds/snapcraft
Docker图像。此图像基于官方snapcore/snapcraft
Docker image by Canonical with all of the command-line tools you’d want to be installed in a CI environment. This image includes thesnapcraft
命令which will be used to build the actual snap.
Running Snapcraft
......steps:-查看-跑:名称:"BuildSnap"命令:snapcraft......
在Circleci上,需要此单个命令实际构建您的快照。这将运行snapcraft,然后将通过其所有构建步骤并生成一个.snap.
给你档案。此文件通常是格式的
。
测试
单元测试您的代码已在我们的博客和我们的文档中广泛介绍,并超出了本文档的范围。你可能想要创造一个工作
在构建拉动项目依赖项的捕捉之前,您要做的任何预检查,测试和编译。
Building snaps on CircleCI results in a.snap.
除了创建它的代码之外,文件是可测试的。你如何测试Snap本身取决于您。有些用户将尝试在各种发行版中安装捕捉,然后运行命令以确保安装过程有效。Snapcraft为散货队提供了一个用于散布舰队,允许您在您已经测试代码本身后测试不同的发行版。这可以找到这里。
Publishing
Publishing a snap is more or less a two-step process. Here’s on this might look on a Linux machine:
Snapcraft登录# Follow prompts for logging in with an Ubuntu One account snapcraft export-login snapcraft.login base64 snapcraft.login | xsel --clipboard
在我们上传到Circleci的本地计算机上创建一个Snapcraft“登录文件”。假设您的本地计算机已安装这些工具,您已登录到Snapcraft Store(
Snapcraft登录
), we use the commandSnapcraft Export-Login Snapcraft.Login
生成调用的登录文件snapcraft.login.
。由于我们不希望公众可见或存储在GIT存储库中,我们将Base64编码此文件并将其存储在一个private environment variablecalled$SNAPCRAFT_LOGIN_FILE
。Note: The default expiration time for the Snapcraft login file is 1 year. If you want the auth file to be valid for longer, make sure to set an expiration date with the
--expires
旗。......- 跑:名称:"Publish至商店”命令:|mkdir .snapcraft.echo $ snapcraft_login_file |base64 --decode --ignore-arterberm> .snapcraft / snapcraft.cfgSnapcraft Push * .snap--release stable......
一旦将文件的Base64编码版本存储在Circleci上作为私有环境变量,我们可以在构建中使用它来自动发布到商店。
In this example, Snapcraft automatically looks for login credentials in.snapcraft / snapcraft.cfg.
and the environment variable made previously is decoded into that location. Thesnapcraft push
然后使用命令将.snap文件上传到SNAP存储中。
上传VS发布
Snapcraft Push * .snap
默认情况下,将在Snap Store上载Snap Store,在服务器端运行任何商店检查,然后停止。捕捉不会“发布”,意思是用户不会自动查看更新。可以在本地发布施用snap release
命令or by logging into the Snap Store and clicking the release button.
在典型的Circleci时尚中,我们可以完全自动化(如上面的例子),但使用--release
旗。这是上传捕捉,确实验证,然后将自动释放指定通道中的捕捉。
Workflows
We can utilize multiple jobs to better organize our snap build. A job to build/compile the actual project, a job to build the snap itself, and a job that published the snap (and other packages) only onmaster
would all be useful.
Workflowscan help with building snaps in two ways:
- Snap Store频道- 正如我们在上一节中提到的那样,当我们上传到商店时,我们可以选择同时发布。这允许我们指定Circleci上的特定作业部署到特定的Snap频道。例如,
master
分支可以用来部署到edge
channelwhile tagged releases could be used to deploy to the
stable` channel. - 并发包装- 如果您的软件被打包为捕捉和别的东西,请参见FlatPak,.deb,.apk等,每个包类型都可以在自己的工作中放置并同时运行。这允许您的构建完成必须快速,而不是如果.deb包可以开始构建,直到捕捉完成,等等。
利用circleci.工作区
至move a generated snap file between jobs when necessary. Here’s an example showing a snippet from the “from” job and a snippet of the “to” job:
......#从已经有安全的作业-persist_to_workspace.:root:。path:-"*.snap"......#下一份工作的需要nap-attach_workspace:at:。......
以下是如何在Circleci上构建SNAP包的完整示例。使用相同的进程用于构建[Circleci本地CLI] [本地CLI-repo]的SNAP纸张。
完整的示例配置
version:2工作s:建立:Docker.:-image:cibuilds/snapcraft:stableauth:username:mydockerhub-user密码:$ dockerhub_password.#上下文/项目UI ENV-VAR参考steps:-查看-跑:名称:"BuildSnap"命令:snapcraft-persist_to_workspace.:root:。path:-"*.snap"publish:Docker.:-image:cibuilds/snapcraft:stableauth:username:mydockerhub-user密码:$ dockerhub_password.#上下文/项目UI ENV-VAR参考steps:-attach_workspace:at:。-跑:名称:"Publish至商店”命令:|mkdir .snapcraft.echo $ snapcraft_login_file |base64 --decode --ignore-arterberm> .snapcraft / snapcraft.cfgSnapcraft Push * .snap--release stableworkflows:version:2main:工作s:-建立-publish:需要:-建立过滤器:分支机构:只要:master