Skip to content

Commit

Permalink
make booty slightly-stateful, add web ui, lots of minor changes. this…
Browse files Browse the repository at this point in the history
… commit is way too big, i'm ashamed lol
  • Loading branch information
jeefy committed Apr 5, 2023
1 parent 3498dc9 commit 68228ae
Show file tree
Hide file tree
Showing 53 changed files with 15,203 additions and 50 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
bin/*
data/*
examples/*
old/*
old/*
Makefile
README.md
10 changes: 8 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ on:
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main ]
release:
types: [published]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
# Map current release tag to the version of booty
BOOTY_VERSION: ${{ github.event.release.tag_name }}
# Map last repo update to the build timestamp
BOOTY_TIMESTAMP: ${{ github.event.repository.updated_at}}


jobs:
Expand Down Expand Up @@ -81,7 +87,7 @@ jobs:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}
run: cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}

- name: Output image
id: image
Expand Down Expand Up @@ -128,5 +134,5 @@ jobs:
IMAGE_NAME: ${{ needs.build.outputs.image }}
IMAGE_DIGEST: ${{ needs.build.outputs.digest }}
run: |
COSIGN_EXPERIMENTAL=1 cosign verify-attestation --type slsaprovenance "${IMAGE_NAME}@${IMAGE_DIGEST}"
COSIGN_EXPERIMENTAL=1 cosign verify-attestation --certificate-identity-regexp=".*" --certificate-oidc-issuer-regexp=".*" --type slsaprovenance "${IMAGE_NAME}@${IMAGE_DIGEST}"
# TODO(github.com/slsa-framework/slsa-verifier/issues/92): Add step to verify using slsa-verifier
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin/
data/
.vscode/*
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
FROM golang:1.16-alpine
### Stage One
FROM golang:1.19-alpine

WORKDIR /app

COPY . .

RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o bin/booty cmd/main.go
RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o bin/booty -ldflags "-X main.version=$BOOTY_VERSION -X main.timestamp=$BOOTY_TIMESTAMP" cmd/main.go

FROM node:lts-alpine as build-stage
WORKDIR /app
COPY web/package*.json ./
RUN npm install
COPY web/ .
RUN npm run build

### Final Stage
FROM gcr.io/distroless/base-debian10

COPY --from=0 /app/bin/booty /
COPY --from=1 /app/dist/ /web/dist/

ENTRYPOINT [ "/booty" ]
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
TOPDIR=$(PWD)
WHOAMI=$(shell whoami)

build:
go build -o bin/booty cmd/main.go

run:
go run cmd/main.go
cd web && npm run build && cd ..
go run cmd/main.go --dataDir=data/

image:
docker build -t jeefy/booty .
docker build -t ${WHOAMI}/booty .

image-push: image
docker push ${WHOAMI}/booty

image-push:
docker push jeefy/booty
image-run: image
docker run -ti -v ${TOPDIR}/data:/data -p 8080:8080 -p 69:69/udp ${WHOAMI}/booty --debug=true --dataDir=/data
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Flags:
* JSON "Hardware Database" (right now just a MAC-to-hostname mapping)
* Automatic updates retrieved from Flatcar-Linux
* Automatic drain/reboot of nodes (in conjunction with [Kured](https://github.com/weaveworks/kured))
* Web UI to add/edit/remove hosts
* Unrecognized MAC addresses go into the brig (boot loop till the MAC is registered)


## Examples
Expand Down
35 changes: 25 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"time"

"github.com/jeefy/booty/pkg/config"
bootyHTTP "github.com/jeefy/booty/pkg/http"
Expand All @@ -20,18 +21,23 @@ var Cmd = &cobra.Command{
}

var args struct {
debug bool
dataDir string
maxCacheAge int
cronSchedule string
httpPort int
architecture string
serverIP string
serverHttpPort int
joinString string
channel string
debug bool
dataDir string
maxCacheAge int
cronSchedule string
httpPort int
architecture string
serverIP string
serverHttpPort int
joinString string
channel string
}

var (
version string
timestamp string
)

func init() {
flags := Cmd.Flags()

Expand Down Expand Up @@ -99,6 +105,15 @@ func init() {
return []string{"json", "prom"}, cobra.ShellCompDirectiveDefault
})
viper.BindPFlags(flags)

viper.SetDefault("version", "dev")
if version != "" {
viper.Set("version", version)
}
viper.SetDefault("timestamp", time.Now().Format("2006-01-02 15:04:05.000000"))
if timestamp != "" {
viper.Set("timestamp", timestamp)
}
}

func main() {
Expand Down
32 changes: 18 additions & 14 deletions examples/k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ kind: ConfigMap
metadata:
name: booty-config
data:
# Update Hardware with your MAC/Hostname mapping. Here's mine for an example
hardware.json: |
{
"40:a8:f0:af:39:8d":
{"hostname": "aren"},
"40:a8:f0:b1:8d:e1":
{"hostname":"yghitan"},
"d4:c9:ef:dc:10:72":
{"hostname":"ehrlitan"},
"d4:be:d9:11:d0:bf":
{"hostname":"kartool"},
"74:d0:2b:33:4d:5d":
{"hostname":"lether"}
}
ignition.yaml: |
passwd:
users:
Expand Down Expand Up @@ -266,6 +252,8 @@ spec:
- containerPort: 69
- containerPort: 8080
volumeMounts:
- name: booty-data
mountPath: /data/
- name: booty-config
mountPath: /data/config/
resources:
Expand All @@ -276,6 +264,20 @@ spec:
- name: booty-config
configMap:
name: booty-config
- name: booty-data
persistentVolumeClaim:
claimName: booty-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: booty-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
Expand All @@ -286,6 +288,7 @@ metadata:
app: booty
name: booty-tcp
spec:
externalTrafficPolicy: Local
ports:
- name: http
port: 80
Expand All @@ -305,6 +308,7 @@ metadata:
app: booty
name: booty-udp
spec:
externalTrafficPolicy: Local
ports:
- name: tftp
port: 69
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ replace (
require (
github.com/flatcar-linux/container-linux-config-transpiler v0.9.2
github.com/go-co-op/gocron v1.11.0
github.com/j-keck/arping v1.0.3
github.com/joho/godotenv v1.4.0
github.com/pin/tftp v2.2.0+incompatible
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.10.1
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/j-keck/arping v1.0.3 h1:aeVk5WnsK6xPaRsFt5wV6W2x5l/n5XBNp0MMr/FEv2k=
github.com/j-keck/arping v1.0.3/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
Expand Down Expand Up @@ -583,8 +585,8 @@ golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func LoadConfig(cmd *cobra.Command) {
viper.SetDefault(IgnitionFile, "config/ignition.yaml")

viper.BindEnv(HardwareMap, "HARDWARE_MAP")
viper.SetDefault(HardwareMap, "config/hardware.json")
viper.SetDefault(HardwareMap, "hardware.json")
}

func DownloadFile(url string) error {
Expand Down
Loading

0 comments on commit 68228ae

Please sign in to comment.