Skip to content

Commit

Permalink
feat: revert to raw terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbl committed Mar 17, 2024
1 parent 6510660 commit 5464927
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 89 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pxe/
node_modules
cdktf.out
cdktf.log
*terraform.*.tfstate*
**/*.tfstate
**/*.backup
**/*.hcl
.gen
.terraform
tsconfig.tsbuildinfo
Expand Down
7 changes: 5 additions & 2 deletions build/bootstrap/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ services:
- 8081:8081
command: ['-address=0.0.0.0:8080', '-rpc-address=0.0.0.0:8081', '-log-level=trace', '-assets-path=/var/lib/matchbox/assets']
volumes:
- ./matchbox:/var/lib/matchbox:Z
- ../../pki/:/etc/matchbox:Z
- ./matchbox:/var/lib/matchbox
- ./../../pki/server.key:/etc/matchbox/server.key:Z
- ./../../pki/server.crt:/etc/matchbox/server.crt:Z
- ./../../pki/ca.crt:/etc/matchbox/ca.crt:Z
- ./../../pki/client.crt:/etc/matchbox/client.crt:Z

# docker run --name dnsmasq --cap-add=NET_ADMIN -v $PWD/contrib/dnsmasq/docker0.conf:/etc/dnsmasq.conf:Z quay.io/poseidon/dnsmasq -d
proxydhcp:
Expand Down
6 changes: 6 additions & 0 deletions infra/cdktf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unused

I have decided not to use CDKTF for the time being since it's pretty cumbersome
working with modules and does not grant much and doesn't grant much benefit yet.

I will probably consider using it once my infra needs justify it.
2 changes: 1 addition & 1 deletion infra/cdktf.json → infra/cdktf/cdktf.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"terraformModules": [
{
"name": "typhoon",
"source": "./terraform/typhoon/bare-metal/fedora-coreos/kubernetes"
"source": "./../../../github.com/alxbl/typhoon/bare-metal/fedora-coreos/kubernetes"
}
],
"context": {}
Expand Down
File renamed without changes.
53 changes: 53 additions & 0 deletions infra/cdktf/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// import { Construct } from "constructs";
// import { App, TerraformStack } from "cdktf";
// import { readFileSync } from 'node:fs';

// import * as nodes from './nodes.json';

// import { MatchboxProvider } from "./.gen/providers/matchbox/provider";
// import { Typhoon } from "./.gen/modules/typhoon";

// let PKI_ROOT = process.env.EASYRSA_PKI || '../pki';
// console.log(process.env.PWD);

// function readPemCert(path: string): string {
// let f = readFileSync(path).toString();
// return f;
// }

// function getLanAddress(): string
// {
// // HACK: Because Ubiquiti is set to use `.lan` as a domain, it will
// // resolve `$HOST.lan` as the device's IP. This should remove the need
// // for a self-hosted DNS and tinkering with the network DNS
// let hostname = readFileSync("/etc/hostname").toString().replace('\n', '');
// return `${hostname}.lan`;
// }

// class LabStack extends TerraformStack {
// constructor(scope: Construct, id: string) {
// super(scope, id);

// new MatchboxProvider(this, "matchbox", {
// ca: readPemCert(PKI_ROOT + '/ca.crt'),
// clientCert: readPemCert(PKI_ROOT + '/client.crt'),
// clientKey: readPemCert(PKI_ROOT + "/client.key"),
// endpoint: '127.0.0.1:8081' // bootstrap is local.
// });

// new Typhoon(this, "typhoon-module", <any>{ // FIXME: strong typing?
// clusterName: "h0me",
// k8SDomainName: "lab.segfault.me", // FIXME: How will this work?
// cachedInstall: true,
// matchboxHttpEndpoint: `http://${getLanAddress()}:8080`,
// osVersion: "39.20240112.3.0",
// osStream: "stable",
// arch: "x86_64", // controllers
// ...nodes
// });
// }
// }

// const app = new App();
// new LabStack(app, "segv-lab");
// app.synth();
10 changes: 10 additions & 0 deletions infra/cdktf/nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"sshAuthorizedKey": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO+M9LUT9LQWQFTxz7SR2jXhxyZs6rS5CLN2aFS6HMB5",

"controllers": [
{"name": "tachyon", "mac": "ac:16:2d:a7:ae:90", "domain": "tachyon.lan"}
],

"workers": [
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 0 additions & 58 deletions infra/main.ts

This file was deleted.

1 change: 0 additions & 1 deletion infra/terraform/typhoon
Submodule typhoon deleted from 301f46
Empty file added scripts/bin/az
Empty file.
38 changes: 12 additions & 26 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -e

DNS_SERVICES=(dnsmasq@qemu0 systemd-resolved)

# FIXME: Pull the docker and firewall rules so that they clean up regardless of script success.
# TODO: Check requirements.
# echo "Checking requirements"
# required=(git iptables docker docker-compose jq)
Expand All @@ -17,20 +16,6 @@ SCRIPT_DIR=${0:a:h}
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
source "$REPO_ROOT/.env"

echo "[*] Restoring git submodules"
git submodule update --init --recursive


if [[ ! -v BOOTSTRAP_QUICK ]]; then
pushd "$REPO_ROOT/infra" >/dev/null
echo "[*] Installing CDKTF dependencies"
npm install

echo "[*] Compiling CDKTF providers"
npm run get
popd >/dev/null
fi

# SETUP
#############################################################################################
if [[ ! -v BOOTSTRAP_NOSECRETS ]]; then
Expand Down Expand Up @@ -69,6 +54,11 @@ sudo iptables -A UDP -m udp -p udp --dport 4011 -j ACCEPT
sudo iptables -A TCP -m tcp -p tcp --dport 8080 -j ACCEPT

#############################################################################################
if [[ ! -v BOOTSTRAP_QUICK ]]; then
echo "[*] Generating bootstrapping PKI..."
"$REPO_ROOT/scripts/bootstrap-pki" >/dev/null
fi

echo "[*] Starting matchbox and DHCP PXE server"
docker-compose -f "$REPO_ROOT/build/bootstrap/docker-compose.yml" up -d

Expand All @@ -80,21 +70,17 @@ docker-compose -f "$REPO_ROOT/build/bootstrap/docker-compose.yml" up -d
# Actual bootstap happens in this function.
function do_bootstrap {

echo "[*] Generating bootstrapping PKI..."

if [[ ! -v BOOTSTRAP_QUICK ]]; then
if "$REPO_ROOT/scripts/bootstrap-pki"; then :; else return 1; fi
fi

#############################################################################################
# echo "Creating symlinks for RPI4 nodes"
# TODO

#############################################################################################
echo "[*] Bootstrapping cluster..."
pushd "$REPO_ROOT/infra" >/dev/null

if EASYRSA_PKI="$REPO_ROOT/pki" npm run apply; then :; else return 1; fi
pushd "$REPO_ROOT/infra/terraform/invoke-typhoon" >/dev/null

if terraform init; then :; else return 1; fi
if terraform apply; then :; else return 1; fi

popd >/dev/null
}

Expand Down Expand Up @@ -130,9 +116,9 @@ if [[ ! -v BOOTSTRAP_NOSECRETS ]]; then
fi

#############################################################################################
if [[ $fail ]]; then
if [[ $fail -ne 0 ]]; then
echo "[!] ERROR: Bootstrapping failed. check output for details."
exit 1
else
echo "[+] Done!"
fi
fi

0 comments on commit 5464927

Please sign in to comment.