This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
snap: cross-build snap images #99
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Cross-build snap images | ||
|
||
Build Kata Containers snap images for all supported architectures using virtual machines. | ||
|
||
## Usage | ||
|
||
Run following command to build the snap images for all supported images. | ||
|
||
``` | ||
./xbuild.sh -a all | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
local arch_qemu="x86_64" | ||
local arch_image="bionic-server-cloudimg-amd64.img" | ||
local arch_image_url="https://cloud-images.ubuntu.com/bionic/current/${arch_image}" | ||
local arch_bios="" | ||
local arch_bios_url="" | ||
local arch_qemu_cpu="qemu64" | ||
local arch_qemu_machine="pc" | ||
local arch_qemu_extra_opts="" | ||
if [ "$(arch)" == "x86_64" ];then | ||
arch_qemu_cpu="host" | ||
arch_qemu_machine="pc,accel=kvm" | ||
arch_qemu_extra_opts="-enable-kvm" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
local arch_qemu="aarch64" | ||
local arch_image="bionic-server-cloudimg-arm64.img" | ||
local arch_image_url="https://cloud-images.ubuntu.com/bionic/current/${arch_image}" | ||
local arch_bios="QEMU_EFI.fd" | ||
local arch_bios_url="https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/${arch_bios}" | ||
local arch_qemu_cpu="cortex-a57" | ||
local arch_qemu_machine="virt,usb=off" | ||
local arch_qemu_extra_opts="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
local arch_qemu="ppc64" | ||
local arch_image="bionic-server-cloudimg-ppc64el.img" | ||
local arch_image_url="https://cloud-images.ubuntu.com/bionic/current/${arch_image}" | ||
local arch_bios="QEMU_EFI.fd" | ||
local arch_bios_url="https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/${arch_bios}" | ||
local arch_qemu_cpu="POWER8" | ||
local arch_qemu_machine="pseries,usb=off" | ||
local arch_qemu_extra_opts="-echr 0x05 -boot c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
error(){ | ||
msg="$*" | ||
echo "ERROR: $msg" >&2 | ||
} | ||
|
||
die(){ | ||
error "$*" | ||
exit 1 | ||
} | ||
|
||
make_random_ip_addr() { | ||
echo "127.$((1 + RANDOM % 240)).$((1 + RANDOM % 240)).$((1 + RANDOM % 240))" | ||
} | ||
|
||
make_random_port() { | ||
echo "$((11060 + RANDOM % 1000))" | ||
} | ||
|
||
get_dnssearch() { | ||
echo "$(grep search /etc/resolv.conf | cut -d' ' -f 2)" | ||
} | ||
|
||
get_dns() { | ||
v="$(grep nameserver /etc/resolv.conf | cut -d' ' -f2 | sed -e 's/^/"/g' -e 's/$/",/g')" | ||
echo ${v} | sed -e 's|,$||g' | ||
} | ||
|
||
download() { | ||
url="$1" | ||
outdir="$2" | ||
pushd "${outdir}" | ||
curl -LO ${url} | ||
ret=$? | ||
popd | ||
return ${ret} | ||
} | ||
|
||
setup_image() { | ||
img_url=$1 | ||
img=$2 | ||
[ -f "${img}" ] && return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be fragile - if the download fails and the script is re-run, the full image will never be downloaded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if download fails, output file is removed |
||
{ download "${img_url}" "$(dirname ${img})"; ret=$?; } || true | ||
[ ${ret} != 0 ] && rm -f "${img}" && return | ||
qemu-img resize "${img}" +5G | ||
} | ||
|
||
# arg1: ip | ||
# arg2: port | ||
# arg3: ssh key | ||
# arg4: timeout in minutes | ||
# return: 0 on success, 1 otherwise | ||
ping_vm() { | ||
ip="$1" | ||
port="$2" | ||
sshkeyfile="$3" | ||
timeout=$4 | ||
minute=60 | ||
sleeptime=10 | ||
timeoutsec=$((timeout*minute)) | ||
tries=$((timeoutsec/sleeptime)) | ||
|
||
for i in $(seq 1 ${tries}); do | ||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i "${sshkeyfile}" "${ip}" -p "${port}" true && return 0 | ||
sleep ${sleeptime} | ||
done | ||
|
||
return 1 | ||
} | ||
|
||
# arg1: qemu system: ppc64, aarch64 or x86_64 | ||
# arg2: cpu model | ||
# arg3: machine type | ||
# arg4: ip | ||
# arg5: port | ||
# arg6: image path | ||
# arg7: seed image path | ||
# arg8: extra options | ||
run_qemu() { | ||
local arch="${1}" | ||
local cpu="${2}" | ||
local machine="${3}" | ||
local ip="${4}" | ||
local port="${5}" | ||
local image="${6}" | ||
local seed_img="${7}" | ||
local extra_opts="${8}" | ||
local ssh_key_file="id_rsa" | ||
local ping_timeout=15 | ||
|
||
local img_opts="-drive file=${image},if=virtio,format=qcow2,aio=threads" | ||
local seed_opts="-drive file=${seed_img},if=virtio,media=cdrom" | ||
if [ "${arch}" == "aarch64" ]; then | ||
img_opts="-device virtio-blk-device,drive=image -drive file=${image},if=none,id=image,aio=threads" | ||
seed_opts="-device virtio-blk-device,drive=cloud -drive file=${seed_img},if=none,id=cloud,format=raw" | ||
fi | ||
|
||
qemu-system-${arch} -cpu "${cpu}" -machine "${machine}" -smp cpus=4 -m 2048M \ | ||
-net nic,model=virtio -device virtio-rng-pci -net user,hostfwd=tcp:${ip}:${port}-:22,dnssearch="$(get_dnssearch)" \ | ||
${img_opts} ${seed_opts} \ | ||
-display none -vga none -daemonize ${extra_opts} | ||
[ $? != 0 ] && return 1 | ||
|
||
# depending of the host's hw, it takes for around ~15 minutes | ||
ping_vm "${ip}" "${port}" "${ssh_key_file}" ${ping_timeout} | ||
[ $? != 0 ] && return 1 | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
instance-id: snapid | ||
local-hostname: snap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#cloud-config | ||
@APT_PROXY@ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. |
||
package_upgrade: false | ||
users: | ||
- lock-passwd: true | ||
name: @USER@ | ||
shell: /bin/bash | ||
ssh-authorized-keys: | ||
- @SSH_KEY@ | ||
sudo: ALL=(ALL) NOPASSWD:ALL | ||
write_files: | ||
- content: | | ||
[Service] | ||
Environment=@DOCKER_ENV@ | ||
path: /etc/systemd/system/docker.service.d/http-proxy.conf | ||
- content: | | ||
@ENV@ | ||
path: /etc/environment | ||
- content: | | ||
{"dns": [@DOCKER_DNS@]} | ||
path: /etc/docker/daemon.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# Setup the environment and build the snap image. | ||
# This script runs in the VM. | ||
|
||
set -x -e | ||
|
||
sudo apt-get update -y | ||
sudo apt-get install -y \ | ||
build-essential \ | ||
cpio \ | ||
docker.io \ | ||
golang-go \ | ||
libattr1-dev \ | ||
libcap-dev \ | ||
libcap-ng-dev \ | ||
libdw-dev \ | ||
libelf-dev \ | ||
libfdt-dev \ | ||
libglib2.0-dev \ | ||
libiberty-dev \ | ||
libnewt-dev \ | ||
libpci-dev \ | ||
libpixman-1-dev \ | ||
librbd-dev \ | ||
libssl-dev \ | ||
libz-dev \ | ||
openssl \ | ||
python \ | ||
snapcraft \ | ||
snapd | ||
|
||
# start docker | ||
sudo systemctl start docker | ||
|
||
# clone packaging reposiory and make snap | ||
packaging_repo_url=https://github.com/kata-containers/packaging | ||
packaging_dir=~/packaging | ||
sudo rm -rf ${packaging_dir} | ||
git clone ${packaging_repo_url} ${packaging_dir} | ||
pushd ${packaging_dir} | ||
sudo -E PATH=$PATH make snap | ||
sudo chown ${USER}:${USER} *.snap |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you can use
local
here as these are globals andlocal
is for functions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can if you source it inside a function 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh - that's clever! I hadn't spotted that ;)