如何利用LXD来在不同的环境中编译我们的snap

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/UbuntuTouch/article/details/54016760

LXD作为一容器的hypervisor,它对LXC提供了更多的新的用户体验.在今天的教程中,我们来介绍如何利用LXD来在不同的Ubuntu Desktop版本下编译我们的snap应用.

 

1)安装LXD及命令行工具

 

我们可以参照链接来安装我们的LXD:https://linuxcontainers.org/lxd/getting-started-cli/.为了方便,我们可以利用已经做好的Ubuntu Image:

 

liuxg@liuxg:~$ lxc launch ubuntu:yakkety
Creating flying-snake
Starting flying-snake


在这里,我们创建了一个叫做flying-snake的容器.我们可以利用如下的命令来查看:

 

liuxg@liuxg:~$ lxc list
+----------------------+---------+-------------------+------+------------+-----------+
|         NAME         |  STATE  |       IPV4        | IPV6 |    TYPE    | SNAPSHOTS |
+----------------------+---------+-------------------+------+------------+-----------+
| flying-snake         | RUNNING | 10.0.1.143 (eth0) |      | PERSISTENT | 0         |
+----------------------+---------+-------------------+------+------------+-----------+
| immortal-feline      | STOPPED |                   |      | PERSISTENT | 0         |
+----------------------+---------+-------------------+------+------------+-----------+
| vivid-x86-armhf      | STOPPED |                   |      | PERSISTENT | 0         |
+----------------------+---------+-------------------+------+------------+-----------+
| xenial-desktop-amd64 | STOPPED |                   |      | PERSISTENT | 0         |
+----------------------+---------+-------------------+------+------------+-----------+

 

2)创建一个用户

 

我们可以利用如下的命令来创建一个属于自己的用户:

 

liuxg@liuxg:~$ lxc exec flying-snake -- adduser liuxg
Adding user `liuxg' ...
Adding new group `liuxg' (1001) ...
Adding new user `liuxg' (1001) with group `liuxg' ...
Creating home directory `/home/liuxg' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for liuxg
Enter the new value, or press ENTER for the default
	Full Name []: liuxg
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y


为用户添加管理员权限:

 

liuxg@liuxg:~$ lxc exec flying-snake -- adduser liuxg sudo
Adding user `liuxg' to group `sudo' ...
Adding user liuxg to group sudo
Done.

 

更新系统并安装所需要的工具:

 

$ lxc exec flying-snake -- apt update -qq
$ lxc exec flying-snake -- apt upgrade -qq
$ lxc exec flying-snake -- apt install -qq -y snapcraft build-essential

 

3)登陆并编译我们的应用

 

我们可以通过如下的命令来登陆:

 

$ lxc exec flying-snake -- sudo -iu liuxg

 

注意这里的liuxg是我们之前创建的用户.

 

liuxg@liuxg:~$ lxc exec flying-snake -- sudo -iu liuxg
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

liuxg@flying-snake:~$ 
liuxg@flying-snake:~$ ls -al
total 20
drwxr-xr-x 2 liuxg liuxg 4096 Jan  4 02:52 .
drwxr-xr-x 4 root  root  4096 Jan  4 02:52 ..
-rw-r--r-- 1 liuxg liuxg  220 Jan  4 02:52 .bash_logout
-rw-r--r-- 1 liuxg liuxg 3771 Jan  4 02:52 .bashrc
-rw-r--r-- 1 liuxg liuxg  655 Jan  4 02:52 .profile
liuxg@flying-snake:~$ mkdir apps
liuxg@flying-snake:~$ cd apps/
liuxg@flying-snake:~/apps$ git clone https://github.com/liu-xiao-guo/alias
Cloning into 'alias'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
Checking connectivity... done.
liuxg@flying-snake:~/apps$ ls
alias
liuxg@flying-snake:~/apps$ cd alias/
liuxg@flying-snake:~/apps/alias$ ls
hello.sh  snapcraft.yaml
liuxg@flying-snake:~/apps/alias$ snapcraft 
Preparing to pull aliases 
Pulling aliases 
Preparing to build aliases 
Building aliases 
Staging aliases 
Priming aliases 
Snapping 'my-alias' |                                                                
Snapped my-alias_0.1_amd64.snap

 

我们可以看到我们已经在yakkety (16.10)的环境中把我们的应用打包为一个snap.

 

 


 

 

 

 

展开阅读全文

没有更多推荐了,返回首页