Created
May 15, 2019 07:28
-
-
Save rchatsiri/d81b4a03d3a19f2ab5f83192e2c4a955 to your computer and use it in GitHub Desktop.
Build small operating system in binary format.
This file contains hidden or 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
# https://github.com/solo-io/unik/blob/master/containers/compilers/firecracker/build-image | |
#!/bin/bash | |
# run this container like so | |
# docker run --rm --privileged -v /path/to/code:/go/src/gopath/to/code firecracker-builder | |
set -ex | |
dd if=/dev/zero of=/tmp/rootfs bs=1M count=50 | |
mkfs.ext4 /tmp/rootfs | |
mkdir /tmp/tmp | |
# mknod /dev/loop0 b 7 0 | |
mount /tmp/rootfs /tmp/tmp -o loop | |
tar xzf /tmp/alpine-minirootfs-3.8.1-x86_64.tar.gz -C /tmp/tmp | |
CODEDIR=${CODEDIR:-/opt/code} | |
cp -r /tmp/overlay/* /tmp/tmp/ | |
cd $CODEDIR | |
go get -d -v ./... | |
CGO_ENABLED=0 go build -o /tmp/tmp/usr/local/bin/program | |
# not using gopath.. so no need for: cp /go/bin/* /tmp/tmp/usr/local/bin/program | |
cat > /tmp/tmp/prepare.sh <<EOF | |
passwd root -d root | |
apk add -u openrc ca-certificates | |
exit | |
EOF | |
chroot /tmp/tmp/ /bin/sh /prepare.sh | |
rm /tmp/tmp/prepare.sh | |
umount /tmp/tmp | |
OUTDIR=${OUTDIR:-$CODEDIR} | |
mkdir -p $OUTDIR || : | |
cp /tmp/rootfs $OUTDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment