Skip to content

Commit

Permalink
quark: Implement build command
Browse files Browse the repository at this point in the history
- fetches `kaps` from GitHub (https://github.com/virt-do/kaps), builds it with `cargo`.
- clones Cloud Hypervisor repository (https://github.com/cloud-hypervisor/linux), builds a Linux kernel using a specific configuration (https://github.com/virt-do/lumper/blob/main/kernel/linux-config-x86_64).
- if offline mode is selected, fetches a `.tar.gz` archive from an URL an builds a container bundle containing the rootfs of the container and a `runc` config file.
- creates an initrootfs image (`lzma` format) from an `alpine` image, containing the container bundle, the `kaps` binary and an init file to launch `kaps` using the bundle.
- wraps the kernel, the initrootfs image and a `quark.json` config file inside a `quardle`.

Signed-off-by: Julian Labatut <[email protected]>
  • Loading branch information
jlabatut committed May 1, 2022
1 parent 915d73b commit 3b3af74
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 13 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ Cargo.lock
.idea
*.tar.gz
.vscode
ctr-bundle

# Generated on quark build
ctr-bundle
kaps
linux-cloud-hypervisor
alpine-minirootfs
initramfs.img
quark.json
*.qrk
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.0.5", features = ["derive"] }
clap = { version = "3.0.5", features = ["derive"] }
git2 = "0.14.2"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
tar = "0.4.38"
flate2 = "1.0.23"
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Lumper
# Quark

<img src="https://img.shields.io/github/workflow/status/virt-do/quark/quark%20build%20and%20unit%20tests?style=for-the-badge" />

## Build a quardle

Building a `quardle` with the container image bundled into the initramfs image :

```bash
quark build --image <container_image_url> --offline --quardle <quardle_name>
```

Building a `quardle` with the container image to be pulled from within the guest:

```bash
quark build --image <container_image_url> --quardle <quardle_name>
```

## Run a quardle

```bash
quark run --quardle <quardle> --output <output_file>
```
24 changes: 24 additions & 0 deletions scripts/mkbundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# From https://github.com/virt-do/kaps/blob/main/hack/mkbundle.sh

# The URL of a container image archive should be supplied in parameter
# Example with alpine : https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-minirootfs-3.14.2-x86_64.tar.gz
if [[ $# -ne 1 ]]; then
echo "Missing container image URL"
exit 1
fi

DEST="ctr-bundle"
IMAGE_ARCHIVE_URL=$1
IMAGE_ARCHIVE_NAME="imageArchive"

rm -rf $DEST $IMAGE_ARCHIVE_NAME && mkdir -p "$DEST"/rootfs

# Download and untar the image
curl -sSL $IMAGE_ARCHIVE_URL -o $IMAGE_ARCHIVE_NAME
tar xf $IMAGE_ARCHIVE_NAME -C "$DEST"/rootfs
rm $IMAGE_ARCHIVE_NAME

pushd "$DEST" > /dev/null
# Generate a runtime spec
runc spec --rootless
popd > /dev/null
16 changes: 16 additions & 0 deletions scripts/mkkernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# From https://github.com/virt-do/lumper/blob/main/kernel/mkkernel.sh

CONFIG_URL="https://raw.githubusercontent.com/virt-do/lumper/main/kernel/linux-config-x86_64"
LINUX_REPO=linux-cloud-hypervisor

if [ ! -d $LINUX_REPO ]
then
echo "Cloning linux-cloud-hypervisor git repository..."
git clone --depth 1 "https://github.com/cloud-hypervisor/linux.git" -b "ch-5.14" $LINUX_REPO
fi

pushd $LINUX_REPO > /dev/null
pwd
wget -qO .config $CONFIG_URL
make bzImage -j `nproc`
popd > /dev/null
34 changes: 34 additions & 0 deletions scripts/mkrootfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# From https://github.com/virt-do/lumper/blob/main/rootfs/mkrootfs.sh

DEST="alpine-minirootfs"
IMAGE_ARCHIVE_URL="https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-minirootfs-3.14.2-x86_64.tar.gz"
IMAGE_ARCHIVE_NAME="imageArchive"

rm -rf $DEST $IMAGE_ARCHIVE_NAME && mkdir $DEST

# Download and untar the image
curl -sSL $IMAGE_ARCHIVE_URL -o $IMAGE_ARCHIVE_NAME
tar xf $IMAGE_ARCHIVE_NAME -C $DEST
rm $IMAGE_ARCHIVE_NAME

pushd "$DEST" > /dev/null
# Create an init file in the rootfs
cat > init <<EOF
#! /bin/sh
#
# /init executable file in the initramfs
#
mount -t devtmpfs dev /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys
ip link set up dev lo
exec /opt/kaps run --bundle /ctr-bundle
poweroff -f
EOF

chmod +x init

popd > /dev/null

# Here we do not create the rootfs image because we need to add some files in it later
Loading

0 comments on commit 3b3af74

Please sign in to comment.