Last active
July 22, 2021 15:00
-
-
Save jepio/b037710cc51f7d802654573f2a4980bf to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| KUBE_VERSION=1.21.0 | |
| TF_VERSION=0.13.7 | |
| # only amd64 is supported due to terraform-libvirt | |
| ARCH=amd64 | |
| POOL=/mnt/pool | |
| apps=( qemu-system-x86_64 virsh curl jq wget lbzip2 unzip ) | |
| pkgs=( libvirt-daemon-system qemu-system-x86 curl jq wget lbzip2 unzip ) | |
| for cmd in "${apps[@]}"; do | |
| if ! command -v $cmd; then | |
| sudo apt-get install "${pkgs[@]}" | |
| break | |
| fi | |
| done | |
| if [ ! -f /usr/local/bin/kubectl ]; then | |
| curl -LO https://dl.k8s.io/release/v${KUBE_VERSION}/bin/linux/${ARCH}/kubectl | |
| sudo mv kubectl /usr/local/bin/kubectl | |
| sudo chmod +x /usr/local/bin/kubectl | |
| fi | |
| if [ ! -f /usr/local/bin/terraform ]; then | |
| curl -LO https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_${ARCH}.zip | |
| sudo unzip -d /usr/local/bin/ terraform_${TF_VERSION}_linux_${ARCH}.zip | |
| fi | |
| if [ ! -f main.tf ]; then | |
| wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.2/terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz | |
| dir=~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64 | |
| mkdir -p $dir | |
| tar xf terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz -C $dir | |
| cat <<EOF >main.tf | |
| terraform { | |
| required_providers { | |
| libvirt = { | |
| source = "dmacvicar/libvirt" | |
| version = "0.6.2" | |
| } | |
| } | |
| } | |
| provider "libvirt" { | |
| # Configuration options | |
| } | |
| EOF | |
| terraform init | |
| fi | |
| if [ ! -f /usr/local/bin/lokoctl ]; then | |
| os=linux | |
| release=$(curl -s https://api.github.com/repos/kinvolk/lokomotive/releases | jq -r '.[0].name') | |
| curl -LO "https://github.com/kinvolk/lokomotive/releases/download/${release}/lokoctl_${release}_${os}_${ARCH}.tar.gz" | |
| sudo tar xf lokoctl_${release}_${os}_${ARCH}.tar.gz -C /usr/local/bin --no-same-owner --strip-components 1 lokoctl_${release}_${os}_${ARCH}/lokoctl | |
| fi | |
| if [ ! -f flatcar_production_qemu_image.img ]; then | |
| wget https://stable.release.flatcar-linux.net/amd64-usr/current/flatcar_production_qemu_image.img.bz2 | |
| lbunzip2 flatcar_production_qemu_image.img.bz2 | |
| fi | |
| if [ ! -f ~/.ssh/id_ed25519 ]; then | |
| ssh-keygen -t ed25519 | |
| fi | |
| read SSHKEY <~/.ssh/id_ed25519.pub | |
| if [ ! -f cluster.lokocfg ]; then | |
| cat <<EOF >cluster.lokocfg | |
| cluster "tinkerbell" { | |
| asset_dir = "./assets" | |
| name = "demo" | |
| dns_zone = "example.com" | |
| ssh_public_keys = ["$SSHKEY"] | |
| controller_ip_addresses = ["10.17.3.4"] | |
| //os_channel = "stable" | |
| //os_version = "current" | |
| experimental_sandbox { | |
| pool_path = "$POOL" | |
| flatcar_image_path = "$PWD/flatcar_production_qemu_image.img" | |
| hosts_cidr = "10.17.3.0/24" | |
| } | |
| worker_pool "pool1" { | |
| ip_addresses = ["10.17.3.5"] | |
| //os_channel = "stable" | |
| //os_version = "current" | |
| } | |
| } | |
| # A demo application. | |
| component "httpbin" { | |
| ingress_host = "httpbin.example.com" | |
| } | |
| EOF | |
| fi | |
| if ! grep $POOL /etc/apparmor.d/local/abstractions/libvirt-qemu ; then | |
| echo "$POOL/* rwk," | sudo tee -a /etc/apparmor.d/local/abstractions/libvirt-qemu | |
| fi | |
| virsh undefine tinkerbell-sandbox-demo-provisioner || true | |
| echo 'You can now run:' | |
| echo '' | |
| echo ' eval $(ssh-agent)' | |
| echo ' ssh-add ~/.ssh/id_ed25519' | |
| echo ' lokoctl cluster apply -v' | |
| echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment