Skip to content

Commit

Permalink
add firecracker platform feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nkraetzschmar committed Jul 4, 2022
1 parent fa23d49 commit a90da1d
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
architecture: [ amd64, arm64 ]
target: [ kvm, metal, gcp, aws, azure, ali, openstack, vmware, pxe ]
target: [ kvm, metal, gcp, aws, azure, ali, openstack, vmware, pxe, firecracker ]
modifier: [ "", "-dev" ]
steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ kvm: build-environment $(SECUREBOOT_CRT)
kvm-dev: build-environment $(SECUREBOOT_CRT)
./build.sh $(BUILD_OPTS) --skip-build --features server,cloud,kvm,_dev $(BUILDDIR) $(VERSION)

firecracker: build-environment $(SECUREBOOT_CRT)
./build.sh $(BUILD_OPTS) --skip-build --features firecracker $(BUILDDIR) $(VERSION)

firecracker-dev: build-environment $(SECUREBOOT_CRT)
./build.sh $(BUILD_OPTS) --skip-build --features firecracker,_dev $(BUILDDIR) $(VERSION)

pxe: build-environment $(SECUREBOOT_CRT)
./build.sh $(BUILD_OPTS) --skip-build --features metal,server,_pxe $(BUILDDIR) $(VERSION)

Expand Down
2 changes: 2 additions & 0 deletions bin/garden-build
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ gpg --batch --no-default-keyring --keyring "$keyring" --import "$keyringPlain"
printf " found new fstab in $i\n"
currentfstab="$(cat $featureDir/$i/fstab)"
fi
done
for i in $(tr ',' '\n' <<< "$fullfeatures"); do
if [ -x "$featureDir/$i/fstab.mod" ]; then
printf " modifying fstab with %s\n" "$i"
currentfstab=$("$featureDir/$i/fstab.mod" <<< "$currentfstab")
Expand Down
2 changes: 2 additions & 0 deletions bin/make_reproducible_ext4
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ shift 2
[ -d "$source" ]
[ -f "$target" ]

export E2FSPROGS_FAKE_TIME=$timestamp

# set uuid and HTREE hash_seed to reproducible values instead of default random generated ones
uuid=${uuid:-$(echo -n "$hash_prefix:uuid" | uuid_hash)}
hash_seed=$(echo -n "$hash_prefix:hash_seed" | uuid_hash)
Expand Down
2 changes: 0 additions & 2 deletions bin/makepart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ partitions="$(mktemp)"
overlay_partitions="$(mktemp)"
secureboot_partitions="$(mktemp)"

export E2FSPROGS_FAKE_TIME=$timestamp

# strip comments and blank lines and sort by path depth (deepest first)
sed 's/#.*//;/^[[:blank:]]*$/d' \
| while IFS= read -r line; do
Expand Down
1 change: 1 addition & 0 deletions features/firecracker/file.exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/repart.d/root.conf
5 changes: 5 additions & 0 deletions features/firecracker/fstab.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -Eeufo pipefail

cat > /dev/null
30 changes: 30 additions & 0 deletions features/firecracker/image
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -Eexuo pipefail

rootfs="$1"
targetBase="$2"

rootfs_work="$(mktemp -d)"
cp -a "$rootfs/." "$rootfs_work"

find "$rootfs_work/var/log/" -type f -delete

chcon -R system_u:object_r:unlabeled_t:s0 "$rootfs_work"
#chroot "$rootfs_work" /usr/bin/env -i /sbin/setfiles /etc/selinux/default/contexts/files/file_contexts /
rm "$rootfs_work/.autorelabel"

file="$(mktemp)"

size="${size:-$(du -sb "$rootfs_work" | awk '{ min_size_bytes = min_size * MB; size = $1 * 1.5; padded_size = size + (MB - (size % MB) % MB); if (padded_size < min_size_bytes) padded_size = min_size_bytes; print (padded_size / MB) "MiB" }' "MB=1048576" "min_size=64")}"
truncate -s "$size" "$file"

timestamp=$(garden-version --epoch "$version")
make_reproducible_ext4 -t "$timestamp" -h "gardenlinux:$version:firecracker:rootfs" -m -p 16 "$rootfs_work" "$file"

rm -rf "$rootfs_work"

cp "$rootfs/boot/vmlinu"*"-firecracker-${arch}" "$targetBase.vmlinux"
cp "$file" "$targetBase.ext4"

rm "$file"
5 changes: 5 additions & 0 deletions features/firecracker/info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: firecracker
type: platform
features:
include:
- server
1 change: 1 addition & 0 deletions features/firecracker/pkg.exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nvme-cli
2 changes: 2 additions & 0 deletions features/firecracker/pkg.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
linux-image-5.15-firecracker-${arch}
rng-tools5
4 changes: 3 additions & 1 deletion features/server/exec.post
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set -Eeuo pipefail
# remove python's __pycache__
$thisDir/garden-chroot $targetDir find /usr/lib -type d -name __pycache__ -exec rm -rf {} +

rm $targetDir/etc/nvme/hostid $targetDir/etc/nvme/hostnqn
if [ -d "$targetDir/etc/nvme" ]; then
rm "$targetDir/etc/nvme/hostid" "$targetDir/etc/nvme/hostnqn"
fi

0 comments on commit a90da1d

Please sign in to comment.