/
snapcraft.yaml
366 lines (318 loc) · 11.2 KB
/
snapcraft.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
name: kata-containers
version: "master"
summary: Build lightweight VMs that seamlessly plug into the containers ecosystem
description: |
Kata Containers is an open source project and community working to build a
standard implementation of lightweight Virtual Machines (VMs) that feel and
perform like containers, but provide the workload isolation and security
advantages of VMs
grade: stable
confinement: classic
parts:
yq:
plugin: nil
prime:
- -*
build-packages:
- curl
override-build: |
yq_path="yq"
yq_pkg="github.com/mikefarah/yq"
goos="linux"
case "$(uname -m)" in
aarch64) goarch="arm64";;
ppc64le) goarch="ppc64le";;
x86_64) goarch="amd64";;
s390x) goarch="s390x";;
*) echo "unsupported architecture: $(uname -m)"; exit 1;;
esac
# Workaround to get latest release from github (to not use github token).
# Get the redirection to latest release on github.
yq_latest_url=$(curl -Ls -o /dev/null -w %{url_effective} "https://${yq_pkg}/releases/latest")
# The redirected url should include the latest release version
# https://github.com/mikefarah/yq/releases/tag/<VERSION-HERE>
yq_version=$(basename "${yq_latest_url}")
yq_url="https://${yq_pkg}/releases/download/${yq_version}/yq_${goos}_${goarch}"
curl -o "${yq_path}" -LSsf ${yq_url}
chmod +x ${yq_path}
go:
after: [yq]
override-build: |
yq=$(realpath ../../yq/build/yq)
versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml
version="$(curl -sSL ${versions_url} | ${yq} r - languages.golang.version)"
curl -LO https://dl.google.com/go/go${version}.src.tar.gz
tar -xf go${version}.src.tar.gz --strip-components=1
cd src && env GOROOT_BOOTSTRAP=$(go env GOROOT | tr -d '\n') ./make.bash
build-packages:
- golang-go
- g++
- curl
plugin: nil
prime:
- -*
runtime:
after: [go]
plugin: nil
build-attributes: [no-patchelf]
override-build: |
pkg_name=runtime
# set GOPATH
export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
git clone -b ${SNAPCRAFT_PROJECT_VERSION} https://github.com/kata-containers/${pkg_name} ${pkg_gopath}
cd ${pkg_gopath}
# build and install
arch=$(uname -m)
if [ ${arch} = "ppc64le" ]; then
arch="ppc64"
fi
make \
PREFIX=/snap/${SNAPCRAFT_PROJECT_NAME}/current/usr \
SKIP_GO_VERSION_CHECK=1 \
QEMUCMD=qemu-system-$arch
make install \
PREFIX=/usr \
DESTDIR=${SNAPCRAFT_PART_INSTALL} \
SKIP_GO_VERSION_CHECK=1 \
QEMUCMD=qemu-system-$arch
# A snap is read-only squashfs, unfourtunately it's not possible to use the rootfs image with DAX
# since rw access is required therefore initrd image must be used instead.
sed -i -e '/^image =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml
proxy:
after: [go]
plugin: nil
build-attributes: [no-patchelf]
override-build: |
pkg_name=proxy
# set GOPATH
export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
git clone -b ${SNAPCRAFT_PROJECT_VERSION} https://github.com/kata-containers/${pkg_name} ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make
make install DESTDIR=${SNAPCRAFT_PART_INSTALL}
shim:
after: [go]
plugin: nil
build-attributes: [no-patchelf]
override-build: |
pkg_name=shim
# set GOPATH
export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
git clone -b ${SNAPCRAFT_PROJECT_VERSION} https://github.com/kata-containers/${pkg_name} ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make
make install LIBEXECDIR=${SNAPCRAFT_PART_INSTALL}/usr/libexec
image:
after: [go]
plugin: nil
build-packages:
- docker.io
- cpio
override-build: |
yq=$(realpath ../../yq/build/yq)
pkg_name=osbuilder
# set GOPATH
export GOPATH=$(realpath go)
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
if [ -n "$http_proxy" ]; then
echo "Setting proxy $http_proxy"
sudo -E systemctl set-environment http_proxy=$http_proxy || true
sudo -E systemctl set-environment https_proxy=$https_proxy || true
fi
# Copy yq binary. It's used in the container
mkdir -p "${GOPATH}/bin/"
cp -a "${yq}" "${GOPATH}/bin/"
echo "Unmasking docker service"
sudo -E systemctl unmask docker.service || true
sudo -E systemctl unmask docker.socket || true
echo "Adding $USER into docker group"
sudo -E gpasswd -a $USER docker
echo "Starting docker"
sudo -E systemctl start docker || true
# download source
git clone -b ${SNAPCRAFT_PROJECT_VERSION} https://github.com/kata-containers/${pkg_name} ${pkg_gopath}
cd ${pkg_gopath}
sudo -E PATH=$PATH make AGENT_VERSION=${SNAPCRAFT_PROJECT_VERSION} DISTRO=alpine AGENT_INIT=yes USE_DOCKER=1 initrd
kata_image_dir=${SNAPCRAFT_PART_INSTALL}/usr/share/kata-containers
mkdir -p ${kata_image_dir}
cp kata-containers-initrd.img ${kata_image_dir}
ksm-throttler:
after: [go]
plugin: nil
build-attributes: [no-patchelf]
override-build: |
pkg_name=ksm-throttler
# set GOPATH
export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
git clone -b ${SNAPCRAFT_PROJECT_VERSION} https://github.com/kata-containers/${pkg_name} ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make TARGET=kata-ksm-throttler
make install \
DESTDIR=${SNAPCRAFT_PART_INSTALL} \
TARGET=kata-ksm-throttler
kernel:
after: [kernel-dump, scripts-dump, yq]
plugin: nil
build-packages:
- libelf-dev
- curl
- build-essential
- bison
- flex
override-build: |
yq=$(realpath ../../yq/build/yq)
# Say 'no' to everithing, fix issues with incomplete .config files
yes "n" | ${SNAPCRAFT_STAGE}/kernel/build-kernel.sh setup
kernel_dir_prefix="kata-linux-"
cd ${kernel_dir_prefix}*
version=$(basename ${PWD} | sed 's|'"${kernel_dir_prefix}"'||' | cut -d- -f1)
make -j $(($(nproc)-1)) EXTRAVERSION=".container"
kernel_suffix=${version}.container
kata_kernel_dir=${SNAPCRAFT_PART_INSTALL}/usr/share/kata-containers
mkdir -p ${kata_kernel_dir}
# Install bz kernel
make install INSTALL_PATH=${kata_kernel_dir} EXTRAVERSION=".container" || true
vmlinuz_name=vmlinuz-${kernel_suffix}
ln -sf ${vmlinuz_name} ${kata_kernel_dir}/vmlinuz.container
# Install raw kernel
vmlinux_name=vmlinux-${kernel_suffix}
cp vmlinux ${kata_kernel_dir}/${vmlinux_name}
ln -sf ${vmlinux_name} ${kata_kernel_dir}/vmlinux.container
kernel-dump:
source: kernel
plugin: dump
organize:
'*' : kernel/
prime:
- -*
scripts-dump:
source: scripts
plugin: dump
organize:
'*' : scripts/
prime:
- -*
qemu:
plugin: make
after: [scripts-dump, qemu-patches-dump, qemu-aarch64-patches-dump, yq]
build-packages:
- gcc
- python
- zlib1g-dev
- libcap-ng-dev
- libglib2.0-dev
- libpixman-1-dev
- libnuma-dev
- libltdl-dev
- libcap-dev
- libattr1-dev
- libfdt-dev
- curl
- libcapstone-dev
- bc
override-build: |
yq=$(realpath ../../yq/build/yq)
pkg_name="qemu"
versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml
# arch-specific definition
case "$(uname -m)" in
"aarch64")
branch="$(curl -sSL ${versions_url} | ${yq} r - assets.hypervisor.qemu.architecture.aarch64.branch)"
url="$(curl -sSL ${versions_url} | ${yq} r - assets.hypervisor.qemu.url)"
commit="$(curl -sSL ${versions_url} | ${yq} r - assets.hypervisor.qemu.architecture.aarch64.commit)"
patch_dir="${SNAPCRAFT_STAGE}/qemu-aarch64/patches/"
;;
*)
branch="$(curl -sSL ${versions_url} | ${yq} r - assets.hypervisor.qemu.tag)"
url="$(curl -sSL ${versions_url} | ${yq} r - assets.hypervisor.qemu.url)"
patch_dir="${SNAPCRAFT_STAGE}/qemu/patches/4.0.x"
commit=""
;;
esac
# download source
pkg_repo_dir="${pkg_name}-repo"
git clone --branch ${branch} --single-branch ${url} "${pkg_repo_dir}"
cd ${pkg_repo_dir}
[ -z "${commit}" ] || git checkout ${commit}
[ -n "$(ls -A ui/keycodemapdb)" ] || git clone https://github.com/qemu/keycodemapdb ui/keycodemapdb/
[ -n "$(ls -A capstone)" ] || git clone https://github.com/qemu/capstone capstone
# Apply patches
for patch in ${patch_dir}/*.patch; do
echo "Applying $(basename "$patch") ..."
patch \
--batch \
--forward \
--strip 1 \
--input "$patch"
done
chmod +x ${SNAPCRAFT_STAGE}/scripts/configure-hypervisor.sh
# static build
echo "$(${SNAPCRAFT_STAGE}/scripts/configure-hypervisor.sh -s qemu) \
--disable-rbd
--prefix=/snap/${SNAPCRAFT_PROJECT_NAME}/current/usr \
--datadir=/snap/${SNAPCRAFT_PROJECT_NAME}/current/usr/share \
--libexecdir=/snap/${SNAPCRAFT_PROJECT_NAME}/current/usr/libexec/qemu" \
| xargs ./configure
# build and install
make -j $(($(nproc)-1))
make install DESTDIR=${SNAPCRAFT_PART_INSTALL}
prime:
- -snap/
- -usr/var/
- -usr/libexec/
- -usr/bin/qemu-ga
- -usr/bin/qemu-pr-helper
- -usr/bin/virtfs-proxy-helper
- usr/*
- lib/*
organize:
# Hack: move qemu to /
"snap/kata-containers/current/": "./"
qemu-patches-dump:
source: qemu/patches/
plugin: dump
organize:
'*' : qemu/patches/
prime:
- -*
qemu-aarch64-patches-dump:
source: obs-packaging/qemu-aarch64/patches/
plugin: dump
organize:
'*' : qemu-aarch64/patches/
prime:
- -*
apps:
runtime:
command: usr/bin/kata-runtime