Canonical Voices

UbuntuTouch

在这篇文章中,我们将介绍一个崭新的工具snapcraft-gui来帮我们开发snap应用.对于一些刚开始开发snap应用的开发者来说,很多的命令及格式对它们来说非常不熟悉.我们可以利用现有的一个含有GUI的Qt应用来帮助我们来创建一个崭新的应用或用来管理我们已经创建好的一个应用.我们再也不需要那些繁琐的命令来帮我们了.我们只需要做的就是按下工具里面的按钮或在文本输入框中直接编辑我们的snapcraft.yaml项目文件即可.


1)下载及安装


我们可以在如下的地址:


找到这个项目的开源地址.我们可以在地址下载它的最新的发布.它目前有deb包.当我们下载完后,只需要双击就可以安装这个debian包了.请注意,由于目前开发snap的应用只限于在Ubuntu 16.04及以上的版本上,我们需要将我们的Ubuntu桌面升级到相应的版本.

等安装完我们的应用后,我们直接在dash中找到这个应用:






在上面我们可以看到应用启动后的界面.


2)使用snapcraft-gui来创建及管理我们的snap项目


首先,我们可以利用snapcraft-gui项目来管理我们已经创建的一个项目.比如我们可以在地址:


下载我之前做过的一个项目:

$ git clone https://github.com/liu-xiao-guo/helloworld-demo

我们可以选择"Open (yaml)"这个按钮导入我们已经创建的项目:


我们可以通过这个界面来管理我们的snapcraft.yaml文件(比如修改并保存).当然我们也可以按照我们build一个snap包的顺序点击按钮进行打包我们的snap.


我们可以在工具的右上角发现这些build的步骤.当然我们也可以选择针对我们项目中的某个part进行单独操作.这特别适合于有些part的编译及下载需要很长的时间.如果这个part没有改动,我们不需要在重新build时clean它,进而节省我们的时间.

我们也可以关掉当前的项目,并点击"New (init)"来创建一个崭新的项目(snapcraft.yaml),比如:




我们可以在上面的工具中,编辑我们的snapcraft.yaml,并调试我们的最终的项目.

如果你想对snap有更多的了解,请参阅我的文章:安装snap应用到Ubuntu 16.4桌面系统

作者:UbuntuTouch 发表于2016/9/19 10:15:54 原文链接
阅读:520 评论:0 查看评论

Read more
UbuntuTouch

[原]如何打包nodejs snap应用

在snap应用开发中,我们可以把一个nodejs的应用打包为snap包.它的开发其实非常简单.在今天的这篇文章中,我们来介绍如何开发一个nodejs的snap应用.


1)在desktop上开发并测试


我们可以在我们的Ubuntu Destop上开发好我们的nodejs应用.这个应用可以不是snap包形式的.我们可以使用不同的framework来开发充分并测试我们的应用.虽然IoT的设备环境和我们的PC环境不同,但是我们还是可以测试我们的大部分功能.


2)打包我们的nodejs应用成为snap包


我们首先把我们的如下的项目:


首先,我们需要把我们的js文件的开头部分添加:

#!/usr/bin/env node

这样确保它是一个可以被执行的文件.这个步骤非常重要.否则我们的应用可能不会正常运行.具体的例程代码:

#!/usr/bin/env node
// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello snapcrafter\n");
    });

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

每个nodejs的项目有一个package.json的文件,我们通常可以把我们npm所需要安装的包放入到这个文件中,比如:

package.json

{
  "name": "lights",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "sudo node ./bin/www"
  },
  "bin": {
    "lights": "./bin/www",
    "server": "./bin/server.js",
    "publish": "./bin/publish.js",
    "subscribe": "./bin/subscribe.js"
  },
  "dependencies": {
    "body-parser": "~1.15.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.2.0",
    "express": "~4.13.4",
    "fs": "0.0.1-security",
    "jade": "~1.11.0",
    "morgan": "~1.7.0",
    "mosca": "^2.2.0",
    "mqtt": "^2.0.1",
    "serialport": "^4.0.3",
    "serve-favicon": "~2.3.0"
  }
}

我们可以通过上面的方法,把我们所需要的包最终打入到我们的snap包中.另外我们也可以直接在我们的snapcraft.yam中定义所需要的安装包.开发者可以根据自己的需要进行选择.

snapcraft.yaml

name: shout
version: 0.52.0
summary: A self hosted web IRC client
description: This example is not really production quality
confinement: strict

apps:
  server:
    command: bin/shout --home $SNAP_DATA
    daemon: simple
    plugs: [network, network-bind]

parts:
  shout:
    plugin: nodejs
    node-packages:
      - shout

在上面,我们也定义了一个npm所需要安装的包shout.我们甚至可以运用node-engine来定义我们所需要的nodejs的版本:

  node:
    plugin: nodejs
    source: . 
    node-engine: 6.9.1

当然最重要的是指定我们所需要的执行文件.在上面的例程中,我们指定/bin/shout来运行我们的应用.更多关于nodejs plugin的介绍可以在我们的官方文档中介绍.

我们的nodejs应用可以在我们的Ubuntu Desktop 16.04上打包为snap应用,并测试.如果我们想把我们nodejs应用运用到我们的arm设备上,我们可以参阅我的文章"如何为树莓派安装Ubuntu Core并在Snap系统中进行编译".

好啦,打包一个nodejs为snap应用就是这么简单.你们会了吗?


作者:UbuntuTouch 发表于2016/11/11 9:31:10 原文链接
阅读:168 评论:0 查看评论

Read more
UbuntuTouch

在我先前的一个例程webcam中,我们的snapcraft.yaml显示如下:

name: webcam-app
version: "1.0"
summary: Webcam app for snappy ubuntu core
description: Exposes your webcam and access using a Ubuntu phone app called "webcamapp"
confinement: strict

apps:
  webcam:
    command: bin/webcamserv
    daemon: simple
    plugs: [camera,network,network-bind]
  sh:
    command: bin/sh

parts:
  cam:
    plugin: go
    source: https://github.com/liu-xiao-guo/webcamserv
    source-type: git
    stage-packages:
      - fswebcam
    filesets:
      fswebcam:
        - usr/bin/fswebcam
        - lib
        - usr/lib
      go-server:
        - bin/webcam*
    snap:
        - $fswebcam
        - $go-server
  glue:
    plugin: copy
    files:
      webcam: bin/webcam
      capture: bin/capture
      ./bin/sh: bin/sh
      


我们使用了copy plugin来拷贝我们的文件.如果我们编译我们的项目的话,你就会发现:

liuxg@liuxg:~/temp/webcam$ snapcraft
"grade" property not specified: defaulting to "stable"
DEPRECATED: The 'copy' plugin's functionality has been replaced by the 'dump' plugin, and it will soon be removed.

它建议我们使用dump plugin来替换.关于plugin的更多的技术细节,我们可以在http://snapcraft.io/docs/reference/plugins/地址找到.我们可以找到dump plugin的技术细节http://snapcraft.io/docs/reference/plugins/dump

This plugin just dumps the content from a specified source.
In the cases where dumping the content needs some mangling or organizing one would take advantage of the core functionalities available to plugins such as: filesets, stage, snap and organize.

在上面的网址,我们可以找到很多例程来参考.针对我们的例子,我们可以有如下的方案:

方案一:

我们把我们项目中的webcam及capture两个执行文件移到我们的bin目录下,这样整个的项目文件如下:

liuxg@liuxg:~/snappy/desktop/webcam$ tree
.
├── bin
│   ├── capture
│   ├── sh
│   └── webcam
└── snapcraft.yaml

接下来,我们通过修改我们的snapcraft.yaml:

  glue:
    plugin: dump
    source: .

通过这样的改动,它将把我们当前目录中所有的文件打包到我们包中的相应的目录中.

liuxg@liuxg:~/snappy/desktop/webcam/prime$ tree -L 3
.
├── bin
│   ├── capture
│   ├── sh
│   ├── webcam
│   └── webcamserv
├── command-sh.wrapper
├── command-webcam.wrapper
├── lib
│   └── x86_64-linux-gnu
│       ├── libexpat.so.1 -> libexpat.so.1.6.0
│       ├── libexpat.so.1.6.0
│       ├── libpng12.so.0 -> libpng12.so.0.54.0
│       └── libpng12.so.0.54.0
├── meta
│   └── snap.yaml
└── usr
    ├── bin
    │   └── fswebcam
    └── lib
        ├── gcc
        └── x86_64-linux-gnu


方案二:

如果我们不想把我们的webcam和capture移动到我们的bin目录下,那么我们怎么办呢?我们可以通过利用organize的方法来做.具体实践,我们可以参阅一个例程:

我们把我们的snapcraft.yaml的文件修改为:

  glue:
    plugin: dump
    source: .
    organize:
      webcam: bin/webcam
      capture: bin/capture
    stage:
      - bin/webcam
      - bin/capture
      - bin/sh
    snap:
      - bin/webcam
      - bin/capture
      - bin/sh

编译完我们的项目后,我们可以重新看到我们的包里的内容:

  glue:
    plugin: dump
    source: .
    organize:
      webcam: bin/webcam
      capture: bin/capture
    stage:
      - bin/webcam
      - bin/capture
      - bin/sh
    snap:
      - bin/webcam
      - bin/capture
      - bin/sh

在这里我们通过organize的方法把我们的文件移动到我们相应的目录中.当然在我们的上面的设计中,我们可以更进一步把我们的glue part精简为:

  glue:
    plugin: dump
    source: .
    organize:
      webcam: bin/webcam
      capture: bin/capture      

在这里我们除去了stage及snap的部分.只是对于我们来说,在这个项目中,我们不必要对这些文件做更进一步的treak.如果需要的话,我们可以通过stage及snap的方法来做.

我们也可以把上面的代码更进一步修改为:

glue:
    plugin: dump
    source: .
    organize:
      '*': bin/
      
这样我么可以把我们当前目录下的所有的文件安装到我们的bin目录下.





作者:UbuntuTouch 发表于2016/10/8 11:04:14 原文链接
阅读:365 评论:0 查看评论

Read more
UbuntuTouch

在这篇文章中,我们将介绍如何在snap系统中进行交叉汇编来把我们的应用编译并安装到目标机器中.我们知道目前Snap支持ARM及x86芯片.在我们的Classic 16.04的系统中,我们很容易地编译出我们想要的在x86上的snap文件,但是我们如何生产为ARM板生产相应的armhf的snap文件呢?

下面我们以树莓派2板子为例来描述是如何实现的.但是这里的教程适合于任何其它的Ubuntu Core所支持的板子,比如高通的snapdragon 410c板子.


1)为树莓派2/3安装snap系统


我们可在地址下载最新的树莓派2的image,并存于系统的~/Downloads目录中.如果你是使用树莓派3的话,那么你可以在地址下载image.你也可以在如下的地址找到所有最新的Ubuntu Core image:

http://cdimage.ubuntu.com/ubuntu-snappy/16.04/current/

如果你希望使用最新的daily build 镜像的话,可以使用连接:

http://cdimage.ubuntu.com/ubuntu-core/xenial/daily-preinstalled/current/

正式的发布软件可以在地址http://releases.ubuntu.com/ubuntu-core/16/找到.

如果大家有beaglebone的板子的话,那么你可以在地址http://people.canonical.com/~ogra/snappy/all-snaps/stable/current/找到最新的Ubuntu Core的软件.


整个image的大小约为161M.我们把我们的SD卡插入到我们电脑的MMC卡槽中,或插入到一个USB的adapter中.在进行拷贝image前,我们必须unmount我们的卡.然后,我们使用如下的命令来拷贝我们的image到卡中:


# Note: replace /dev/sdX with the device name of your SD card (e.g. /dev/mmcblk0, /dev/sdg1 ...)

xzcat ~/Downloads/ubuntu-core-16-pi2.img.xz | sudo dd of=/dev/sdX bs=32M
sync

注意这里的"ubuntu-core-16-pi2.img.xz"是我们下载后的image的名称.目前对于p3设备来说,默认的输出是通过串口,可以连接到我们的电脑上并进行查看启动的信息.大家可以买一个像链接所示的串口线.在我们的terminal中打入如下的命令:

$ sudo screen /dev/ttyUSB0 115200

这样就可以看到我们启动时的信息了.

当然,如果大家没有这样的连接线的话,我们可以通过修改如下的文件,并最终使得显示的结果输出到HDMI的显示器中:



上面的cmdline.txt里面的原始的内容为:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty0 elevator=deadline

我们把cmdline.txt中的文件的内容,修改为:

dwc_otg.lpm_enable=0 console=tty1 elevator=deadline

这样,我们就可以在HDMI的显示器上看到输出的结果了.通过键盘的操作,我们第一次完成Network的设置后,就可以在电脑上通过刚ssh的方式来进行登陆了.记住,我们必须提供launchpad的账号信息来完成设置的动作.

等上面的操作完成后,拔出我们的SD卡,并插入到我们的树莓派的SD卡插槽中.然后启动我们的树莓派.第一次的启动的时间比较长,需要耐心等待.



注意:这里的image名字"all-snaps-pi2.img.xz"可能会跟着版本的变化而发生改变.请根据你下载的具体的文件来替换.这里的sdX需要换成我们卡的设备号,比如在我们的电脑的MMC插槽中就是mmcblk0:



在我们刷卡时,我们可以使用sudo fdisk -l,或lsblk来获取我们的设备的代码.注意在我们执行命令时,命令行中的"/dev/sdX"可以是/dev/sdb而不是/dev/sdb1,可能是 /dev/mmcblk0 而不是 /dev/mmcblk0p1.


2)连接我们的树莓派设备


如果大家有路由器的话,建议大家把树莓派和自己的电脑同时连接到同一个路由器上.我们可以参阅文章"如何在装上Snappy Ubuntu的树莓派上启动WiFi"来找到树莓派上的IP地址.

如果我们的树莓派中已经安装了snapweb应用,我们可以通过如下的方式看到:

liu-xiao-guo@localhost:~$ snap list
Name         Version       Rev  Developer  Notes
bluez        5.37-1        7    canonical  -
classic      16.04         14   canonical  devmode
lights-app   0.1           x1              devmode
pi2-kernel   4.4.0-1021-3  14   canonical  -
pi3          16.04-0.4     5    canonical  -
piglow-app   1.0           x2              devmode
sensortag    1.0           x3              devmode
snapweb      0.21.1        21   canonical  -
ubuntu-core  16.04.1       760  canonical  -
webcam-app   1.0           x1              devmode

如果在你的系统还没有发现snapweb已经安装,我们可以使用如下的命令来安装我们的snapweb:

$ sudo snap install snapweb

我们可以通过如下的方式找到它是否运行正常:

liu-xiao-guo@localhost:~$ systemctl status -l snap.snapweb.snapweb
● snap.snapweb.snapweb.service - Service for snap application snapweb.snapweb
   Loaded: loaded (/etc/systemd/system/snap.snapweb.snapweb.service; enabled; vendor preset: enabled
   Active: active (running) since Mon 2016-09-12 07:49:32 UTC; 1 months 5 days ago
 Main PID: 1793 (snapweb)
   CGroup: /system.slice/snap.snapweb.snapweb.service
           └─1793 /snap/snapweb/21/bin/arm-linux-gnueabihf/snapweb

我们可以看到它在正常运行.如果是这样的话,我们可以通过如下的方式来在我们的host电脑上打入如下的指令:

liuxg@liuxg:~$ ping snapweb.local
PING snapweb.local (10.42.0.140) 56(84) bytes of data.
64 bytes from 10.42.0.140: icmp_seq=1 ttl=64 time=0.539 ms
64 bytes from 10.42.0.140: icmp_seq=2 ttl=64 time=0.534 ms
64 bytes from 10.42.0.140: icmp_seq=3 ttl=64 time=0.580 ms
^C
--- snapweb.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.534/0.551/0.580/0.020 ms

我们可以从上面看到我们所连的设备的IP地址.

一旦得到树莓派的IP地址,我们就可以通过如下的命令来完成和树莓派的ssh连接.在电脑上打入如下的命令:

$ ssh <your-launchpad-account-name>@your_raspberry_pi_ip_address

特别值得注意的是,如果是使用最新的Ubuntu Core的软件的话,这里的ubuntu应改为自己的launchpad的用户名.对于我的情况是liu-xiao-guo@your_raspberry_pi_ip_address.



一旦我们连接上我们的树莓派,我们可以参照文章"安装snap应用到Ubuntu 16.4桌面系统"来安装和检查我们的snap系统,比如:





3)交叉编译我们的应用



在这一节中,我们来展示如何把我们的应用进行交叉编译,并最终形成可以在我们的树莓派上可以运行的snap包.

首先我们在树莓派中安装如下的叫做"classic"的应用:

$ sudo snap install classic --devmode --edge

然后,我们打入如下的命令:

$ sudo classic.create 
$ sudo classic.shell (or "sudo classic" depending on your version)



我们再打入如下的命令来更新我们的系统:

$ sudo apt-get update



我们可以把git安装到系统中:

$ sudo apt install snapcraft git-core build-essential

这样我们就安装好了我们的系统,我们可以用这里的环境来交叉编译我们的任何一个snap应用.编译后的snap包就可以直接在我们的树莓派上直接运行:




编译完我们的应以后,我们可以直接在我们的shell环境中安装我们的应用:




我们通过如下的方法来安装我们的应用:

$ sudo snap install webcam-webui_1_armhf.snap --devmode --dangerous

这里我们采用了--devmode,也就是说我们让我们的应不受任何的安全机制的限制,就像我们以前的Ubuntu桌面上的应用一样.在以后的章节中,我们必须通过interface来连接我们的plug及slot.camera的plug目前还没有在树莓派的image中.





至此,我们已经把我们的项目webcam-webui编译为我们树莓派可以使用的snap了.

作者:UbuntuTouch 发表于2016/8/25 11:45:03 原文链接
阅读:945 评论:2 查看评论

Read more
UbuntuTouch

[原]ubuntu core 开发介绍 (视频)

在这个视频里介绍了Ubuntu Core的基本知识.同时也介绍了Ubuntu Core上的应用开发基本流程.


视频地址:http://v.youku.com/v_show/id_XMTgyMjkwNzIwNA==.html

视频:Ubuntu Core introduction in English

作者:UbuntuTouch 发表于2016/11/17 16:54:05 原文链接
阅读:234 评论:0 查看评论

Read more
UbuntuTouch

在设计我们的snap应用时,很多的时候我们需要使用一个wrapper(一个脚本)来启动我们的应用而不是直接调用在bin目录下的可执行文件.这里的原因有:

  • 很多时候,我们可能需要在运行应用前把我们所需要的运行库的目录加载到我们的路径之中,比如LD_LIBRARY_PATH或LIBGL_DRIVERS_PATH
  • 在应用运行前,创建我们所需要的文件目录;把我们所需要的文件拷入到我们可以直接读写的文件路径之中,比如SNAP_DATA,SNAP_USER_DATA等.这里有很大的原因是因为我们的SNAP安装目录是不可以写的(只读),所以我们的设置文件都应该放入到我们可以读写的文件目录中
在今天的教程中,我们来通过shadowsocks来展示如何利用wrapper来启动我们的应用.

snapcraft.yaml

name: ssocks # you probably want to 'snapcraft register <name>'
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: shadowsocks # 79 char long summary
description: |
  This is a shadowsocks snap app

grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

apps:
  ssocks: 
    command: bin/wrapper
    plugs: [network,home]

parts:
  ss:
    plugin: go
    source: https://github.com/shadowsocks/shadowsocks-go
    source-type: git
  config:
    plugin: dump
    source: .
    organize:
      config.json: bin/config.json
      wrapper: bin/wrapper
      configure: meta/hooks/configure

从上面的例程我们可以看出来:我们的ssocks应用在运行的时候,调用了bin/wrapper而不是一个通常的binary可以执行的文件.这里的wrapper其实是一个Linux脚本:

wrapper

#!/bin/sh
set -e

config_file="$SNAP_DATA/config.json"  

if [ -f "$config_file" ]  

then  
    cat $config_file 
    $SNAP/bin/shadowsocks-local -c $config_file
else  
    echo "$config_file not found."  
    echo "Please run the following commmand to generate the file:"  
    echo "sudo snap set ssocks server=127.0.0.1 serverport=12255 localport=7777 password=123456 method=aes-128-cfb timeout=600"
    echo "you can set only the parts which the above default values do not work for you!"
    echo "Typically, you would use \"sudo snap set ssocks server=127.0.0.1 password=123456\""
fi


这里注意:wrapper这个文件是可以执行的.当我们创建这个文件后,我们必须使用如下的命令来使之是可以执行的:
$ chmod a+x wrapper
在这个脚本中,我们首先检查我们的config.json文件是否存在.如果不存在的话,我们将显示提醒让用户来配置所需要的设置文件.正对我们的情况,一个用户需要使用如下的命令:

$ sudo snap set ssocks server=127.0.0.1 serverport=12255 localport=7777 password=123456 method=aes-128-cfb timeout=600

这里的server是我们的shadowsocks服务器地址.当然,我们也可以直接使用如下的简单的命令来配置(如果上面的默认的参数是适合你的话,你就可以不配置)

$ sudo snap set ssocks server=127.0.0.1 password=123456

这里我们只配置我们需要的服务器地址和密码.通过上面的命令,它可以为我们在目录SNAP_DATA创建一个config.json文件.

实际上,当我们使用上面的命令时,我们已经调用了configure hook.通过它,我们生产了一个在SANP_DATA目录下的config.json文件:

congfigure

#!/bin/sh

server="127.0.0.1"
serverort="12255"
localport="7777"
password="123456"
method="aes-128-cfb"
timeout="600"

if server=$(snapctl get server); then
    echo "server is:$server"
fi

if serverport=$(snapctl get serverport); then
    echo "serverport is: $serverport"
fi

if localport=$(snapctl get localport); then
    echo "localport is: $localport"
fi

if password=$(snapctl get password); then
    echo "password is: $password"
fi

if method=$(snapctl get method); then
    echo "method is: $method"
fi

if timeout=$(snapctl get timeout); then
    echo "timeout is: $timeout"
fi

#now, lets create the file into a JSON file
printf '{"server":"%s","server_port":%s,"local_port":%s, "password":"%s", "method":"%s", "timeout":%s}\n' "$server" "$serverport" "$localport" "$password" "$method" "$timeout" > $SNAP_DATA/config.json

同样的情况,我们需要使这个文件变得可以执行:

$ chmod a+x configure

它可以帮我们生产位于SNAP_DATA像如下格式的一个config.json文件:

config.json

{
    "server":"127.0.0.1",
    "server_port":12255,
    "local_port":7777,
    "password":"123456",
    "method": "aes-128-cfb",
    "timeout":600
}

在wrapper中,如果config.json文件已经存在,那么它直接可以执行如下的命令:

$SNAP/bin/shadowsocks-local -c $config_file

从而完成我们的shadowsocks的命令的执行.通过这样的配置,我们就可以它的功能.



目前在Ubuntu Desktop上,由于有一个bug,所有我们不可以使用sudo snap set 命令来设置我们的config.json文件.我们需要在KVM或一个设备上进行测试或者在我们的SNAP_DATA目录中创建一个上面的config.json文件即可.

所有这个项目的源码在:https://github.com/liu-xiao-guo/shadowsocks_cli
你可以发现发布的应用在:https://uappexplorer.com/app/ssocks.xiaoguo

作者:UbuntuTouch 发表于2016/11/22 10:44:32 原文链接
阅读:101 评论:0 查看评论

Read more
UbuntuTouch

在今天的文章中,我们来介绍一下如何利用QEMU来编译打包我们的Ubuntu Core armhf/arm64格式的Snap应用.这里的armhf/arm64格式的snap包可以被安装到我们的ARM板子上,比如树莓派或高通的Snapdragon 410C板子上.


1)安装qemu-user-static


我们在Ubuntu 16.04的桌面系统上打入如下的命令:

$ sudo apt install qemu-user-static


2)制作armhf/amd64 rootfs


在我们的terminal中打入如下的命令:

- 32 bit的armhf rootfs

$ mkdir -p ~/rootfs/usr/bin
$ cp -a /usr/bin/qemu-arm-static ~/rootfs/usr/bin/
$ sudo debootstrap --arch=armhf --verbose xenial ~/rootfs/

- 64 bit的arm64 rootfs

$ mkdir -p ~/rootfs/usr/bin
$ cp -a /usr/bin/qemu-aarch64-static ~/rootfs/usr/bin/
$ sudo debootstrap --arch=arm64 --verbose xenial ~/rootfs/




通过上面的指令,我们创建了一个以xenial (Ubuntu 16.04)为基础的 armhf/arm64 rootfs.


3)进入chroot并编译我们的应用


我们在termnial中打入如下的指令:

$ sudo chroot ~/rootfs/

注意这里的rootfs是我们在上面创建的以rootfs命名的文件目录.一旦进入到chroot,我们可以利用如下的命令来安装我们的snapcraft及我们所需要的基本的打包工具:

# sudo apt update
# sudo apt-get upgrade

注意这里,我们已经是以root用户进入的,所有下面的命令可以省去sudo.

然后:

# sudo apt-get install software-properties-common
# sudo add-apt-repository universe
# sudo apt-get update
# sudo apt install snapcraft git-core build-essential 

如果这个时候,我们查看我们的snapcraft的版本的话,它显示的将是:

root@liuxg:/apps/vtop# snapcraft --version
2.8.4

显然这个版本不是我们最新的版本2.22.1,它不支持许多最新的snapcraft.yaml中的syntax:

root@liuxg:/etc/apt# snapcraft --version
2.22.1

为了能够得到最新的snapcraft版本,我们修改/etc/apt/sources.list中的内容如下:

root@liuxg:/etc/apt# cat sources.list
deb http://ports.ubuntu.com/ubuntu-ports xenial main universe
deb http://ports.ubuntu.com/ubuntu-ports xenial-updates main universe

这里,我们主要是加入了xenial-updates这一项.然后,我们再:

# sudo apt update && sudo apt-get upgrade

通过这样的方法,我们就可以得到最新的snapcraft的版本2.22.1了.

上面加入universe channel的目的是为了能够顺利地安装snapcraft.

对于有些Qt应用,我们可能需要安装最新的Qt 5.6.1版本,那么我们可以通过如下的方法:

# sudo add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay
# sudo apt-get update

这样就可以得到相应的Qt最新的版本.


作者:UbuntuTouch 发表于2016/12/6 8:15:57 原文链接
阅读:256 评论:0 查看评论

Read more
UbuntuTouch

每个Ubuntu Core设备都需要使用我们的Ubuntu One账号进行登陆.对于一个已经安装好的Ubuntu Core设备怎么加入新的账号,从而使得我们能够使用新的账号进行登陆呢?在今天的这篇文章中,我们将介绍如何创建一个Ubuntu One账号并把它加入到已有的Ubuntu Core设备中.


1)创建自己的Ubuntu One账号


对于还没有自己的Ubuntu One账号的开发者来说,请到如下的地址:


注册自己的Ubuntu One账号.



一旦我们有了自己的Ubuntu One账号,我们可以在https://launchpad.net/上进行登陆.




我们点击右上角的用户名上面的链接从而进入到我们的用户管理页面:



我们点击"SSH keys".紧接着,按照上面的提示,我们把我们Ubuntu Desktop里的id_rsa.pub里的内容拷贝并粘贴到相应的区域:



这样,我们就基本完成了对我们的Ubuntu One账号的设置了.我们创建的账号可以被成功应用于安装一个Ubuntu Core的设备中.具体安装步骤请参阅文章"安装Ubuntu Core系统".


2)为Ubuntu Core设备添加新的账号



一旦我们有了自己的Ubuntu Core账号,我们可以把这个账号加入到我们现有的Ubuntu Core的设置中.首先,我们先用已有Ubuntu Core的账号进行登陆:



我们可以看一下snap的命令:

liuxg@localhost:~$ snap --help
Usage:
  snap [OPTIONS] <command>

The snap tool interacts with the snapd daemon to control the snappy software platform.


Application Options:
      --version  Print the version and exit

Help Options:
  -h, --help     Show this help message

Available commands:
  abort        Abort a pending change
  ack          Adds an assertion to the system
  buy          Buys a snap
  change       List a change's tasks
  changes      List system changes
  connect      Connects a plug to a slot
  create-user  Creates a local system user
  disable      Disables a snap in the system
  disconnect   Disconnects a plug from a slot
  download     Download a given snap
  enable       Enables a snap in the system
  find         Finds packages to install
  get          Get snap configuration
  help         Help
  install      Installs a snap to the system
  interfaces   Lists interfaces in the system
  known        Shows known assertions of the provided type
  list         List installed snaps
  login        Authenticates on snapd and the store
  logout       Log out of the store
  refresh      Refreshes a snap in the system
  remove       Removes a snap from the system
  revert       Reverts the given snap to the previous state
  run          Run the given snap command
  set          Set snap configuration
  try          Tests a snap in the system

在上面的截图中,我们可以看到,有一个叫做create-user的命令.我们可以更一步了解这个命令的用法:

liuxg@localhost:~$ snap create-user -h
Usage:
  snap [OPTIONS] create-user [create-user-OPTIONS] [<email>]

The create-user command creates a local system user with the username and SSH
keys registered on the store account identified by the provided email address.

An account can be setup at https://login.ubuntu.com.

Application Options:
      --version      Print the version and exit

Help Options:
  -h, --help         Show this help message

[create-user command options]
          --json     Output results in JSON format
          --sudoer   Grant sudo access to the created user

[create-user command arguments]
  <email>:           An email of a user on login.ubuntu.com

我们打入如下的命令:

$ sudo snap create-user --sudoer xiaoguo.liu@gmail.com

在上面,我们使用了新的Ubuntu One账号xiaoguo.liu@gmail.com.通过这样的方法,我们就把一个新的Ubuntu One账号添加到我们的Ubuntu Core设备中.我们就可以用新的账号liuxg进行登陆.



由于一些原因,到目前为止在树莓派2的系统中没有提供create-user命令.在树莓派3中是可以的.
作者:UbuntuTouch 发表于2016/11/17 11:14:14 原文链接
阅读:285 评论:0 查看评论

Read more
UbuntuTouch

[原]Ubuntu Core 介绍(视频)

在这个视频里,我们介绍了什么是Ubuntu Core及Ubuntu Core的安全机制.我们也深入介绍了用于打包snap的snapcraft工具及其应用商店.


作者:UbuntuTouch 发表于2016/9/1 10:37:22 原文链接
阅读:585 评论:0 查看评论

Read more
UbuntuTouch

我在先前的文章"如何在装上Snappy Ubuntu的树莓派上启动WiFi"讲述了如何配置我们的Ubuntu Core上的WiFi.据目前的测试来看,那篇文章中的方法还是适用的.但是在Ubuntu Core的设计中,我们建议使用在/etc/netplan中的yaml文件配置的方式.在今天的教程中,我们将介绍如何配置Ubuntu Core上的WiFi.


当我们把Ubuntu Core系统第一次启动时,我们要进入到console-conf的设置中.在配置的过程中,我们可以安装提示的顺序,并选择WLAN来设置.具体的步骤如下:












等配置好我们的WiFi后,我们可以安装文章"如何在装上Snappy Ubuntu的树莓派上启动WiFi"中所介绍的那样来通过路由器来找到我们的Ubuntu Core设备地址.然后,再通过:

$ ssh your_launchpad_username@your_ubuntu_core_ip_address
具体的登陆步骤可以参阅我的文章"安装Ubuntu Core系统".

一旦进入到我们的Ubuntu Core系统,我们可以在目录/etc/netplan下找到一个配置的yaml文件:


比如在上面的00-snapd-config.yaml文件.我们可以打开看它里面的内容如下:

# This is the network config written by 'console-conf'
network:
  ethernets:
    eth0:
      addresses: []
  version: 2
  wifis:
    wlan0:
      access-points:
        Your-AP-Name: {mode: infrastructure, password: 'Your-Password'}
      addresses: []
      dhcp4: true



在我们实际配置我们自己的WiFi时,我们也可以直接修改这个文件,并保存.同时,我们需要使用下面的命令以使得这个新的配置起作用.

$ sudo netplan generate
$ sudo netplan apply


当然我们也可以在任何的时候重新启动console-conf来设置我们的用户及网路.我们可以打入如下的命令:

$ sudo console-conf

更多链接:

[1] https://lists.ubuntu.com/archives/ubuntu-devel/2016-July/039464.html
[2] https://git.launchpad.net/netplan/tree/doc/example-config


作者:UbuntuTouch 发表于2016/12/7 8:56:15 原文链接
阅读:46 评论:0 查看评论

Read more
Olivier Tilloy

Recently the ubuntu-app-platform snap has been made available in the store for application developers to build their snaps without bundling all their dependencies. The ubuntu-app-platform snap includes standard Qt libraries (version 5.6.1 as of this writing) and QML runtime, the ubuntu UI toolkit and related dependencies, and oxide (a web engine based on the chromium content API and its QML bindings).

This allows app developers to declare a dependency on this snap through the content sharing mechanism, thus reducing dramatically the size of the resulting app snaps.

 

I went through the exercise with the webbrowser-app snap. This proved surprisingly easy and the size of the snap (amd64 architecture) went down from 136MB to 22MB, a sizeable saving!

For those interested in the details, here are the actual changes in the snapcraft.yaml file: https://bazaar.launchpad.net/~phablet-team/webbrowser-app/staging/revision/1576.

Essentially they consist in:

  • Using the ‘platform’ plug (content interface) and specifying its default provider (‘ubuntu-app-platform’)

  • Removing pretty much all stage packages

  • Adding an implicit dependency on the ’desktop-ubuntu-app-platform’ wiki part

  • Adding an empty ‘ubuntu-app-platform’ directory in the snap where snapd will bind-mount the content shared by the ubuntu-app-platform snap

 

Note that the resulting snap could be made even smaller. There is a known bug in snapcraft where it uses ldd to crawl the dependencies, ignoring the fact that those dependencies are already present in the ubuntu-app-platform snap.

Also note that if your app depends on any Qt module that isn’t bundled with ubuntu-app-platform, you will need to add it to the stage packages of your snap, and this is likely to bring in all the Qt dependencies, thus duplicating them. The easy fix for this situation is to override snapcraft’s default behaviour by specifying which files the part should install, using the “snap” section (see what was done for e.g. address-book-app at https://code.launchpad.net/~renatofilho/address-book-app/ubuntu-app-platform/+merge/311351).

Read more
Colin Ian King

stress-ng 0.07.07 released

stress-ng is a tool that I have been developing on-and-off for a few years. It is designed to stress kernels to force out bugs, stress CPU and memory and also contains some performance benchmarking metrics too.

stress-ng is now entering the maturity part of the development phase, however, there is always scope to add new stressors and generally improve the tool.   I've just released version 0.07.07 for the Ubuntu Zesty 17.04 release and it contains a few additional features:

  • SIGUSR2 sent to stress-ng will dump out the current system load and memory statistics
  • Sched policy stress tests for different scheduler configurations
  • Add a missing --sockfd-port option
And various bug fixes:
  • Fixed up some minor memory leaks
  • Missing counter stats on bind-mount, fp-error, personality and resources stressors
  • Fix the --fiemap-bytes option
  • Fix up build warnings with various compilers and static analyzers
The major change to stress-ng over the past month was an internal re-working of system call and GNU features to abstract these into a shim layer to reduce the number build conditional #ifdef paths around code. This simplifies portability, so the code now builds more easily across a range of systems and with various versions of gcc and clang and fixes some issues on older kernels too.   This makes the code also faster to statically analyze with cppcheck.

For more details, visit the stress-ng project page or the quick help guide.

Read more
Alan Griffiths

Testing for Mir

Need a Mir server?

A couple of times in the last week I’ve been asked about a Mir server for testing. These requests have been from folks wanting to test their client-side work against Mir.

Most application developers will be using a toolkit or other graphics development library and not care if they are running on X11, Mir or even Windows. But the developers of those libraries will want to test with Mir.

For this purpose, the simplest Mir server to use is miral-shell. If you’re on Ubuntu Zesty Zapus then this is readily available:

$ sudo apt install miral-examples mir-graphics-drivers-desktop qtubuntu-desktop

If you’re on an earlier version of Ubuntu then you either need a ppa (such as the “stable phone overlay”) or, less risky to your system, just build and install it yourself. (If you’re not on Ubuntu this is still possible: there are some pointers here.)

What does miral-server provide?

Currently miral-server is the only Mir server to offer libmiral’s “basic window management”. That unique status is due to change real soon as this implementation is being merged into Unity8.

The simplest way way to run miral-shell is using Mir’s “Mir on X” support. From a terminal window just type:

$ miral-shell

Then you can connect your application from another terminal:

$ miral-run <application>

You should see your application appear in the “Mir on X” window.

A lot of the current work is focused on the placement of windows (menues, popup, etc.) and to help with this there’s a facility to trace the window management calls. Start miral-shell like this:

$ miral-shell --window-management-trace

And all the window management events and decisions are logged.

Another interesting option is to use a “tiling” window manager:

$ miral-shell --window-manager tiling

Which has a completely different approach to laying out the application windows.

For a full list of the option:

$ miral-shell --help

Documentation of the Mir “toolkit”API

A related question I’ve been asked is for documentation of the libmirclient API. You can find the documentation like this:

$ sudo apt install mir-doc
$ xdg-open /usr/share/doc/mir-doc/html/group__mir__toolkit.htm

This will open the default browser on the relevant page.

Read more
Daniel Holbach

ucaday-64pxIt’s 20th November 2016, so today marks another Ubuntu Community Appreciation Day. The idea for the event was put together by Ahmed Shams in 2011 and it’s simple but brilliant: once a year (at least), take the time to thank some specific people for their work in Ubuntu.

As I’m at UbuCon Europe this weekend, it’s incredibly easy to pick somebody whose work I’m grateful for. Today I’d like to thank all the event organisers in the Ubuntu world. Without people like Sujeevan Vijayakumaran (in the case of UbuCon Europe), we as a community, wouldn’t be able to get together, learn from each other and have fun together. It takes a set of special skills to organise big and small events, plan ahead, talk to various people and companies, organise sponsors and helpers and it’s something we often take too much for granted.

Thank you everyone who organised the Ubuntu events I’ve been to over the years, no matter if it’s the small meetings in a bar or the crazy big events, like UDSes (thanks Claire, Marianna and Michelle!). You are incredible rockstars and I had some of my best times thanks to you!

Read more
Daniel Holbach

Ubuntu Online SummitEarlier this week the Ubuntu community was busy with the Ubuntu Online Summit. If you head to the schedule page, you can watch all the sessions which happened.

As I’m interested in snaps a lot, I’d like to highlight some of the sessions which happened there, so if you missed them, you can go back and see what happened there:

  • Intro and keynote by Gustavo Niemeyer
    Gustavo (amongst others projects he is involved with) is one of the lead developers of snapd. During his keynote he gives an overview over what the team has been working on in the last time and explains which features all landed in the snap world recently. It quickly gives you an idea of the pace of development and the breadth of new features which landed.
  • Creating your first snap
    This is a session I gave. Unfortunately Didier couldn’t make it as he had lost his voice in the days before. We both worked together on the content for this. Basically, if you’re new to using and creating snaps, watch this. It’s a series of very simple steps you can follow along and gives you enough background to see the bigger picture.
  • Snap roadmap and Q&A
    This was a fun session with Michael Vogt and Zygmunt Krynicki. They are also both lead developers of snapd and they share a lot of their thoughts in their own very fun and very interesting way. After some discussion of the roadmap, they dived right into the almost endless stream of questions. If you want to get an idea of what’s coming up and some of the more general decisions behind snaps, watch this one.
  • Building snaps in Launchpad
    Colin Watson gave this demo of a beautiful new feature in Launchpad. Starting from a github repo (the source could live elsewhere too), the source is pulled into Launchpad, snaps are built for selected releases of Ubuntu and selected architectures and directly pushed to the store. It’s incredibly easy to set up, complements your CI process and makes building on various architectures and publishing the snaps trivial. Thanks a lot for everybody’s work on this!

The other sessions were great too, this is just what I picked up from the world of snaps.

Enjoy watching the videos and share them please!

Thanks a lot to all the session leads as well!

Read more
facundo


¿Cómo? ¿Qué el año no está terminando todavía? Bueno... el año termina durante octubre y noviembre, diciembre siempre está perdido (?).

Las últimas semanas fueron intensas, lo cual se traduce en tener mil cosas atrasadas, incluyendo este blog.

Pasaron varias cosas que ameritan un par de lineas.

A principios de octubre fue el cumple de Felu, y siendo el primero con él en la primaria, cambió un poco la dinámica de siempre. Hicimos un salón compartido con otro compañero suyo que cumplía esos días, y obviamente fueron todos los compañeros de grado (y algunos de otros grados!). Luego, hicimos un asado en casa para toda la familia y amigos con niños más grandes.

Siete

A mitad de octubre tuve un viaje de laburo, pero este fue más largo que la típica semana de siempre. Fue de una semana y media, no es tanto, pero se nota al extrañar a la familia. Por suerte los chicos ya están más grandes y se bancan mejor mi ausencia, pero igual sufren un poquito :/. La vez anterior que tuve un viaje de más de una semana fue hace mucho, mucho tiempo. Fue en Holanda, que yo ya conocía... pero fue en La Haya, a donde nunca había ido :). Fotos.

Típica callecita de La Haya

Casita en un canal de Amsterdam

Otro tema que me tuvo bastante ocupado hace unas semanas, pero que voy a dedicar otro post, es que armé "una nube en casa". O sea, compré un hardware, le instalé Magicicada, y tengo mi propio server de sincronización de archivos :)

Noviembre viene movidito, también. En un par de semanas está la PyCon Argentina, esta vez en Bahía Blanca. Ya reportaré sobre eso.

Tengo que terminar de armar el reemplazo de mi muy usufructuado WDTV. Me compré una Raspi 3 y le voy a poner Kodi.

También estos días le regalé a mi viejo el regalo de los 70 (que cumplió hace un par de años ya), un vuelo "de bautismo" en una avioneta, que era algo que él siempre quiso hacer. Lo disfrutó un montón, y yo también. Felipe, el tercer pasajero, disfrutó bastante el despegue, el paseo inicial, y el aterrizaje... en el medio se clavó una siesta, el atorrante.

Antes de salir a volar

En fin, pequeñas cosas, grandes cosas, muchas. El día tendría que tener 36 horas (e igual no alcanzaría :/ ).

Read more
Benjamin Zeller

Ubuntu SDK meets snapcraft

Everyone who has followed Ubuntu lately for sure stumbled across the snappy technology, which does not only bring the new cross-distro packaging format “snap” but also a sandboxing technology for apps, as well as transactional updates that can be rolled back in case of an update going wrong and a new way of installing and upgrading Ubuntu called “Ubuntu Core”.

Together with all those new technologies came new tools that make it possible for app developers to build and pack their applications to target Snappy and Core. The central tool for that is snapcraft and it aims to unite a lot of tasks that were separate before. It can set up your build environment, build your projects and even package it with just one call in the project directory: “snapcraft”.

We took the last few weeks to start the work on supporting those new tools and now we have the first release of the IDE with direct support for building with snapcraft, as well as a basic template to get you started.

New technologies usually come with certain limitations. This one is not an exception and we hope that these issues will be eliminated in the near future.:

  • Snapcraft uses sudo when it needs to install build packages, however that does not work when run from the QtCreator, simply because sudo does not have a console to ask the password on. So make sure build dependencies are installed before building.

  • “Out of source” builds are not yet implemented in snapcraft, but since QtCreator always uses a extra build directory we had to work around that problem. So for now we rsync the full project into a build directory and run the build there.

  • Also incremental builds are yet not supported, so every build is a complete rebuild.

Snapcraft projects are described in a snapcraft.yaml file, so it made sense for us to use it as the project file in the IDE as well, so instead of opening a .pro or CMakeList.txt file the snapcraft.yaml is opened directly. Naturally implementing a completely new project type manager is not a trivial task, so many key features are still missing.

  • Code model support: while completion does work in the file scope, it does not for the full project.

  • Debugging mode: currently the profiling and debugging run modes do not work, so snap projects can only be executed normally.

Those limitations aside it can be already used to create snap packaged applications.

With this new release we consider the IDE as feature complete for the time being. Since the development of snapcraft is moving in a very fast pace we need to let it evolve to a certain degree to be sure new features added to the IDE represent the future way of building with snapcraft.

Read more
Tim Peeters

Introduction

One of the advantages of snap packages is that they are self-contained. When you install a snap, you know that you don’t need to install additional dependencies (besides the automatically-installed core snap that provides the basic operating system layer), and it will simply work on every Linux distribution that supports snaps.

Here, we show how to create self-contained snap packages for Qt-based applications, and we show an additional approach where some of the app dependencies are provided by a separate snap: the Ubuntu app platform snap. The platform snap provides an (optional) approach for the software provider, and can save disk space in some cases. Below we will explain the two approaches to building a snap for Qt-based software: a snap that is self-contained and includes Qt, and one that uses the platform snap, and we show the advantages of each approach. However, before showing these two approaches that you can apply to your own QML code, we demonstrate how to create a snap from deb packages in the Ubuntu archive so that you can get started right away even before you write any code.

We assume that before reading this blog post, you have acquired knowledge about how to use Snapcraft. So if you haven’t, we recommend reading the documentation on snapcraft.io and the snap-codelabs tutorials.

All the commands that are listed below are executed on an Ubuntu 16.04 LTS machine with the stable-phone-overlay PPA enabled. Some of the snapcraft commands may run on other configurations, but for the “Ubuntu App Platform Snap” section it is a hard requirement because the version of Qt - upstream 5.6 long term support version - and other libraries used to build the snap need to match the versions in the ubuntu-app-platform snap. Installing the snap packages works on different versions of Ubuntu and even different Linux distributions. The examples were tested on amd64 architecture with Intel graphics. If you are running this on a different CPU architecture, naturally the architecture in the directory and snap file names listed below must be modified. If you have an Nvidia GPU and use the Nvidia proprietary drivers there can be problems when running some snapped applications, so in that case we currently recommend to use the open source Nouveau drivers.

The examples are also available in a repository linked to from the Evaluation section.

Qt cloud parts - a simple use case

We will demonstrate how to build a simple app snap that includes the Qt release and Ubuntu UI Toolkit (UITK) from the Ubuntu archives. For this example, we use the UITK gallery which is part of the ubuntu-ui-toolkit-examples deb package on classic Ubuntu systems, so no additional code is needed. Because of that, we can simply use the nil plugin and pull in the examples as stage-packages. We create a directory called uitk-gallery which contains only a snapcraft.yaml file with the following contents:

name: uitk-gallery
version: '0.1'
summary: Showcase gallery that demonstrates the components in the Ubuntu UI Toolkit.
description: |
  See https://developer.ubuntu.com/api/qml/ for the API documentation of the components.

grade: devel
confinement: strict

parts:
  ubuntu-ui-toolkit-examples:
    plugin: nil
    stage-packages:
      - qmlscene
      - qml-module-qtqml-models2
      - ubuntu-ui-toolkit-examples
    after: [desktop-qt5]

apps:
  uitk-gallery:
    command: desktop-launch "qmlscene $SNAP/usr/lib/*/qt5/examples/ubuntu-ui-toolkit/examples/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml"
    plugs: [unity7, opengl]

(notes: the command line assumes you are on and targeting amd64 system. the plugs line is needed so that you have access to graphical subsystem from your confined app)

Under stage-packages we listed all the packages that need to be pulled from the Ubuntu archive, including their dependencies. ubuntu-ui-toolkit-examples contains all the QML code for the UITK gallery that we want to run using qmlscene. We also included qml-module-qtqml-models2 because some pages of the UITK gallery import QtQml.Models. The line after: [desktop-qt5] fetches the desktop-qt5 part from the remote parts repository. It will automatically pull in Qt 5 from the Ubuntu archive, set-up environment variables, and provide the desktop-launch script that is called to start the app. The snap file can be created simply by going to the uitk-gallery directory which contains the snapcraft.yaml file, and running:

snapcraft

Note that Snapcraft will ask for the sudo password to install the Qt5 dev packages that are required to compile Qt apps, but can be left out if all the dependencies are already present. Running snapcraft will create (on an amd64 machine) the file uitk-gallery_0.1_amd64.snap which can then be installed by:

snap install --dangerous uitk-gallery_0.1_amd64.snap

where the dangerous parameter is required because we are installing an unsigned snap that does not come from the Ubuntu store. Note that you do not need to use sudo if you have logged in with snap login. The UITK gallery can now be launched using:

uitk-gallery

The desktop-qt5 cloud part pulls in the current stable version of Qt of the Ubuntu 16.04 LTS release - 5.5.1 normally or 5.6.1 in the case of stable overlay PPA. To uninstall the UITK gallery snap before going to the next section, run:

snap remove uitk-gallery

QML project using parts from the cloud

If your existing QML code is not available as a deb package, then obviously you cannot pull it in from the archive when creating the snap using stage-packages. To show how to include your own QML code, we copy the UITK gallery code to the ubuntu-ui-toolkit-gallery directory inside the snapcraft (uitk-gallery) directory. Go to the parent directory of the uitk-gallery of the previous section, and run:

bzr branch lp:ubuntu-ui-toolkit
cp -R ubuntu-ui-toolkit/examples/ubuntu-ui-toolkit-gallery uitk-gallery/

Alternatively, if you have the ubuntu-ui-toolkit-examples package installed, you can run:

cp -R /usr/lib/*/qt5/examples/ubuntu-ui-toolkit/examples/ubuntu-ui-toolkit-gallery/ uitk-gallery/

You should now have both the snapcraft.yaml and the copied ubuntu-ui-toolkit-gallery directory that contains the source code of the UITK gallery under the uitk-gallery. We can now remove the ubuntu-ui-toolkit-examples from the stage-packages in the snapcraft.yaml file. Because that line is removed, the dependencies of the UITK gallery are no longer pulled in automatically, and we must add them to the YAML file, which then becomes:

name: uitk-gallery
version: '0.2'
summary: Showcase gallery that demonstrates the components in the Ubuntu UI Toolkit.
description: |
  See https://developer.ubuntu.com/api/qml/ for the API documentation of the components.

grade: devel
confinement: strict

parts:
  ubuntu-ui-toolkit-gallery:
    plugin: dump
    source: .
    stage-packages:
      - qmlscene
      - qml-module-qtqml-models2
      - qml-module-qt-labs-folderlistmodel
      - qml-module-qtquick-xmllistmodel
      - qml-module-ubuntu-components
      - ubuntu-ui-toolkit-theme
      - ubuntu-ui-toolkit-tools
    after: [desktop-qt5]

apps:
  uitk-gallery:
    command: desktop-launch "qmlscene $SNAP/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml"
    plugs: [unity7, opengl]

Note that besides the changes in stage-packages, also the location of ubuntu-ui-toolkit-gallery.qml was updated in the uitk-gallery command because the QML files are no longer installed in usr/lib inside the snap, but copied in the root of the snap filesystem. As before, the snap package can be created by executing:

snapcraft

inside the uitk-gallery directory. The UITK gallery can then be installed and started using:

snap install --dangerous uitk-gallery_0.2_amd64.snap
uitk-gallery

and uninstalled by:

snap remove uitk-gallery

Now that you have seen how to package the UITK gallery from source into a snap, you can do the same for your own QML application by using the dump plugin with the dependencies as stage-packages. If your application includes C++ code as well, you need to use another plugin, for example the qmake plugin. For that we refer to the Snapcraft tutorials mentioned in the introduction.

For those who like to experiment with newer versions of upstream Qt, we provide qt57 and qt58 cloud parts in the parts repository for Qt 5.7.1 and 5.8 (in development). However, the qt57 and qt58 cloud parts do not yet include a wrapper script similar to desktop-launch, so one must be included with with snap configuration, see for example timostestapp2. When using these cloud parts, you should usually omit any Qt/QML package from stage-packages, as the ones compiled from newer Qt are used directly, and you should also omit the after: [desktop-qt5].

Ubuntu app platform snap

The snap files we created in the previous sections contain everything that is needed in order to run the UITK gallery application, resulting in a snap file of 86MB. Here we will explain how to use the Ubuntu app platform snap when you have multiple app snaps that all use the same Qt version.

Benefits of this approach include disk space saving, download time and bandwidth usage if metered.

When your snap uses the ubuntu-app-platform snap for Qt and other platform libraries, we can remove the stage-packages from the snapcraft.yaml file because (in this case), all the needed libraries are included in ubuntu-app-platform. We must also replace after: [desktop-qt5] by after: [desktop-ubuntu-app-platform]. This will set-up your snap to use the global desktop theme, icon theme, gsettings integration, etc. A more elaborate description of the desktop-ubuntu-app-platform is given in the parts list on the Ubuntu wiki. In the uitk-gallery directory we must currently create a directory where the files from the platform snap can be mounted using the content interface:

mkdir ubuntu-app-platform

and this empty directory (mount point) must be added in the YAML file as well. At this point the directory structure is as follows:

uitk-gallery/
 .. snapcraft.yaml
 .. ubuntu-ui-toolkit-gallery/
    .. [gallery contents]
 .. ubuntu-app-platform/

The whole YAML is:

name: uitk-gallery
version: '0.3'
summary: Showcase gallery that demonstrates the components in the Ubuntu UI Toolkit.
description: |
  See https://developer.ubuntu.com/api/qml/ for the API documentation of the components. ubuntu-app-platform snap must be installed for this snap to work.

grade: devel
confinement: strict

plugs:
    platform: # plug name, to be used later
        interface: content
        content: ubuntu-app-platform1 # content being mounted and the version, currently 1
        target: ubuntu-app-platform # the mount directory created
        default-provider: ubuntu-app-platform # default content source snap, currently the only provider too

parts:
  ubuntu-ui-toolkit-gallery:
    plugin: dump
    source: .
    after: [desktop-ubuntu-app-platform]
    snap: [ubuntu-ui-toolkit-gallery, ubuntu-app-platform]

apps:
  uitk-gallery:
    command: desktop-launch "qmlscene $SNAP/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml"
    plugs: [platform, unity7, opengl]

Again, the new snap file can be created using:

snapcraft

This time, before we can use the snap, the ubuntu-app-platform snap must be installed and connected to the new uitk-gallery snap. So, execute the following commands:

snap install ubuntu-app-platform
snap install --dangerous uitk-gallery_0.3_amd64.snap
snap connect uitk-gallery:platform ubuntu-app-platform:platform
uitk-gallery

Note that the snaps must be connected before running uitk-gallery for the first time. If uitk-gallery has been executed before the snap connect you will see an error message. To fix the problem, uninstall the uitk-gallery snap, then re-install it and run the snap connect command before executing uitk-gallery. This is a known limitation in snapd which will be resolved soon.

Another note: once support for the default-provider, already defined above, will correctly be implemented in snap, there will no longer be a need to install the platform snap separately - it will be pulled from the store automatically and the interface connects automatically.

Evaluation

We demonstrated three different approaches to creating a UITK gallery snap, which we gave the version numbers 0.1, 0.2 and 0.3. For each of the approaches, the table below lists the time needed for the different stages of a snapcraft run, but the pull and build stages have been combined because when doing pull, some of the prerequisites need to be built already. The all stages row shows the total time when running the snapcraft command in a clean directory, so that all stages are executed sequentially, so the value is less than the sum of the previous rows in the table because in each stage it is not necessary to check completion of the previous stages.

Version (bzr revision)

0.1 (r1)

0.2 (r2)

0.3 (r3)

build (includes pull)

1m49s

1m48s

3.6s

stage

7s

7s

1.5s

prime

33s

34s

1.8s

snap

1m11s

1m13s

1.7s

all stages

3m32s

3m20s

4.0s

install

2.2s

2.4s

1.2s

snap file size

86 MB

86 MB

1.3 MB

The measurements were done on a laptop with an Intel Core i5-6200U CPU with 8 GB RAM and an solid-state drive by running each command three times and listing the average execution time. All build-dependencies were pre-installed so their installation time is not included in the measurements. Note that this table only serves as an illustration, and execution times will vary greatly depending on your system configuration and internet connection, but it can easily be tested on your own hardware by bzr branching revisions r1, r2 and r3 of lp:~tpeeters/+junk/blog-snapping-qt-apps.

The times and file size listed in the last column (version 0.3) do not include downloading and installing the ubuntu-app-platform snap, which is 135 MB (it includes more than just the minimal Qt and UITK dependencies of the UITK gallery). It can be seen that (depending on the internet connection speed, and which files were downloaded already), using the ubuntu-app-platform can speed up the pull and build time when creating a new snap file. However, the most important advantage is the reduction of the sum of the file sizes when installing multiple app snaps that all depend on Qt or other libraries that are part of the platform snap, because the libraries need to be installed only once. The disadvantage of this approach is that the app snap must be built using the exact same Qt (and other libraries) version as the ubuntu-app-platform snap, so the choice whether the snap should be fully self-contained or depend on the platform snap must be made individually for each use case.

Future work

The UITK gallery snap is not yet available in the Ubuntu store, so our next step will be to publish a UITK examples snap that includes the UITK gallery, and to set-up automatic publishing of that snap to different channels when we update the UITK or the examples. We will also evaluate what is the best way to make newer versions of Qt available and determine whether we need to provide prebuilt binaries to replace the qt57 and qt58 cloud parts.

Finally, we will determine which libraries need to be included in the ubuntu-app-platform snap. The plan is to include all APIs that are listed on https://developer.ubuntu.com/api/qml/ and if APIs are missing we will add them to that webpage as well as to the platform snap. Of course, if you think we are forgetting a library that is useful and used in many different applications, please leave a comment below.

Read more
Colin Watson

Launchpad has had Git-to-Bazaar code imports since 2009, along with imports from a few other systems.  These form part of Launchpad’s original mission to keep track of free software, regardless of where it’s hosted.  They’re also very useful for automatically building other artifacts, such as source package recipes or snap packages, from code hosted elsewhere.  Unfortunately they’re quite complicated: they need to be able to do a full round-trip conversion of every revision from the other version control system, which has made it difficult to add support for Git features such as signed commits or submodules.  Once one of these features is present anywhere in the history of a branch, importing it to Bazaar becomes impossible.  This has been a headache for many users.

We can do better nowadays.  As of last year, we have direct Git hosting support in Launchpad, and we can already build snaps and recipes straight from Git, so we can fulfil our basic goal more robustly now with a lot less code.  So, Launchpad now supports Git-to-Git code imports, also known as Git mirroring.  You can use this to replace many uses of Git-to-Bazaar imports (note that there’s no translations integration yet, and of course you won’t be able to branch the resulting import using bzr).

See our Git documentation for more details.

Read more
kevin gunn

more sample client updates

I can’t even remotely take credit for this. Alberto from the Mir team took the mir-client snap and updated to utilize the mir-libs snap through the content interface. This is helpful as a guide for others who want to avoid making useless copies of libraries in a mir-client app snap. He also added some additional example client applications to run on the mir-kiosk, along with using the snap set command to dynamically change those from the command line. I’ve updated the mir-snaps wiki on how to utilize this. enjoy! If you wanna discuss or have issues, find me (kgunn) on freenode #ubuntu-mir

Read more