Skip to content

Instantly share code, notes, and snippets.

@kakposoe
Last active June 21, 2023 10:18
Show Gist options
  • Save kakposoe/cf81fe11c0f55fbdf56bcc8bbfc21046 to your computer and use it in GitHub Desktop.
Save kakposoe/cf81fe11c0f55fbdf56bcc8bbfc21046 to your computer and use it in GitHub Desktop.
firecracker ignite setup
#!/bin/bash
# Set up droplet to use firecracker
apt-get update && apt-get install -y --no-install-recommends \
dmsetup openssh-client git binutils golang-go
which containerd || apt-get install -y --no-install-recommends containerd
# Install cni plugins
export CNI_VERSION=v0.9.1
export ARCH=$([ $(uname -m) = "x86_64" ] && echo amd64 || echo arm64)
sudo mkdir -p /opt/cni/bin
curl -sSL https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz | sudo tar -xz -C /opt/cni/bin
# Install firecracker
export VERSION=v0.10.0
export GOARCH=$(go env GOARCH 2>/dev/null || echo "amd64")
for binary in ignite ignited; do
echo "Installing ${binary}..."
curl -sfLo ${binary} https://github.com/weaveworks/ignite/releases/download/${VERSION}/${binary}-${GOARCH}
chmod +x ${binary}
sudo mv ${binary} /usr/local/bin
done
# docker installation
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt install docker-ce
# Install caddy
# sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
# sudo apt update
# sudo apt install caddy
# sudo systemctl enable --now caddy
# Create new ip address
sudo ip tuntap add tap0 mode tap
IP=172.16.0.1
sudo ip addr add $IP/24 dev tap0
sudo ip link set tap0 up
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i tap0 -o eth0 -j ACCEPT
DOCKER_IMAGE=oscarrrenalias/golang-http-server
docker pull $DOCKER_IMAGE
DIST_DIR=/etc/firecracker/manifests/
VMFILE=smoke-test.yml
tee "${VMFILE}" > /dev/null <<EOF
apiVersion: ignite.weave.works/v1alpha4
kind: VM
metadata:
name: smoke-test
uid: e4820437-516b-4d21-918e-be6ef5c69460
spec:
image:
oci: ${DOCKER_IMAGE}:latest
cpus: 1
diskSize: 2GB
memory: 500MB
network:
ports:
- hostPort: 80
vmPort: 80
bindAddress: ${IP}
protocol: udp
status:
running: true
EOF
screen -d -m ignited daemon --log-level debug
mv $VMFILE $DIST_DIR
echo "Setup completed!!!"
screen -r
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment