diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-06-08 10:49:18 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-06-08 10:49:28 -0400 |
| commit | 2f9125d0cbe232dbb0dcd64eab33af356d5d615c (patch) | |
| tree | c9cbe2476e939d41db0319e23e2205f7b7a02960 /cmd/within.website | |
| parent | 92a2b4a91b9d57f5c54673f1228278ee21f5e4b1 (diff) | |
| download | x-2f9125d0cbe232dbb0dcd64eab33af356d5d615c.tar.xz x-2f9125d0cbe232dbb0dcd64eab33af356d5d615c.zip | |
cmd/within.website: fix use of http servemux, deploy to k8s
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/within.website')
| -rw-r--r-- | cmd/within.website/main.go | 16 | ||||
| -rw-r--r-- | cmd/within.website/manifest.yaml | 150 | ||||
| -rw-r--r-- | cmd/within.website/yeetfile.js | 37 |
3 files changed, 163 insertions, 40 deletions
diff --git a/cmd/within.website/main.go b/cmd/within.website/main.go index f7d20c5..8bb5c75 100644 --- a/cmd/within.website/main.go +++ b/cmd/within.website/main.go @@ -51,14 +51,14 @@ func (r Repo) LogValue() slog.Value { ) } -func (r Repo) RegisterHandlers(lg *slog.Logger) { +func (r Repo) RegisterHandlers(mux *http.ServeMux, lg *slog.Logger) { switch r.Kind { case "gitea": - http.Handle("/"+r.Repo, vanity.GogsHandler(*domain+"/"+r.Repo, r.Domain, r.User, r.Repo, "https")) - http.Handle("/"+r.Repo+"/", vanity.GogsHandler(*domain+"/"+r.Repo, r.Domain, r.User, r.Repo, "https")) + mux.Handle("/"+r.Repo, vanity.GogsHandler(*domain+"/"+r.Repo, r.Domain, r.User, r.Repo, "https")) + mux.Handle("/"+r.Repo+"/", vanity.GogsHandler(*domain+"/"+r.Repo, r.Domain, r.User, r.Repo, "https")) case "github": - http.Handle("/"+r.Repo, vanity.GitHubHandler(*domain+"/"+r.Repo, r.User, r.Repo, "https")) - http.Handle("/"+r.Repo+"/", vanity.GitHubHandler(*domain+"/"+r.Repo, r.User, r.Repo, "https")) + mux.Handle("/"+r.Repo, vanity.GitHubHandler(*domain+"/"+r.Repo, r.User, r.Repo, "https")) + mux.Handle("/"+r.Repo+"/", vanity.GitHubHandler(*domain+"/"+r.Repo, r.User, r.Repo, "https")) } lg.Debug("registered repo handler", "repo", r) } @@ -76,12 +76,12 @@ func main() { os.Exit(1) } + mux := http.NewServeMux() + for _, repo := range repos { - repo.RegisterHandlers(lg) + repo.RegisterHandlers(mux, lg) } - mux := http.NewServeMux() - xess.Mount(mux) mux.HandleFunc("/debug/varz", tsweb.VarzHandler) diff --git a/cmd/within.website/manifest.yaml b/cmd/within.website/manifest.yaml new file mode 100644 index 0000000..e0e915f --- /dev/null +++ b/cmd/within.website/manifest.yaml @@ -0,0 +1,150 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: within-website +data: + "config.ts": | + export interface Repo { + kind: "gitea" | "github"; + domain: string; + user: string; + repo: string; + description: string; + } + + const githubRepo = (name: string, description: string): Repo => { + return { + kind: "github", + domain: "github.com", + user: "Xe", + repo: name, + description, + }; + }; + + const giteaRepo = (name: string, description: string): Repo => { + return { + kind: "gitea", + domain: "tulpa.dev", + user: "cadey", + repo: name, + description, + }; + }; + + const repos: Repo[] = [ + githubRepo("derpigo", "A Derpibooru/Furbooru API client in Go. This is used to monitor Derpibooru/Furbooru for images by artists I care about and archive them."), + githubRepo("eclier", "A command router for Go programs that implements every command in Lua. This was an experiment for making extensible command-line applications with Lua for extending them."), + githubRepo("gcss", "A CSS preprocessor for Go. This is a legacy Go package that I am bringing forward to modern Go standards."), + giteaRepo("gopher", "A Gopher (RFC 1436) client/server stack for Go applications. This allows users to write custom Gopher clients and servers."), + githubRepo("ln", "The natural log function for Go: an easy package for structured logging. This is the logging stack that I use for most of my personal projects."), + githubRepo("x", "Various experimental things. /x/ is my monorepo of side projects, hobby programming, and other explorations of how programming in Go can be."), + ]; + + export default repos; +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: within-website + labels: + app.kubernetes.io/name: within-website +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: within-website + template: + metadata: + labels: + app.kubernetes.io/name: within-website + spec: + securityContext: + fsGroup: 1000 + volumes: + - name: tyson + configMap: + name: within-website + containers: + - name: main + image: ghcr.io/xe/x/within-website:latest + imagePullPolicy: "Always" + resources: + limits: + cpu: "500m" + memory: "256Mi" + requests: + cpu: "250m" + memory: "128Mi" + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + runAsNonRoot: true + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + livenessProbe: + httpGet: + path: / + port: 8080 + httpHeaders: + - name: X-Kubernetes + value: "is kinda okay" + initialDelaySeconds: 3 + periodSeconds: 3 + env: + - name: TYSON_CONFIG + value: "/etc/within.website/config.ts" + - name: PORT + value: "8080" + - name: SLOG_LEVEL + value: DEBUG + volumeMounts: + - name: tyson + mountPath: /etc/within.website + readOnly: true +--- +apiVersion: v1 +kind: Service +metadata: + name: within-website + labels: + app.kubernetes.io/name: within-website +spec: + selector: + app.kubernetes.io/name: within-website + ports: + - port: 80 + targetPort: 8080 + name: http + type: ClusterIP +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: within-website + labels: + app.kubernetes.io/name: within-website + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" +spec: + ingressClassName: nginx + tls: + - hosts: + - within.website + secretName: within-website-public-tls + rules: + - host: within.website + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: within-website + port: + name: http diff --git a/cmd/within.website/yeetfile.js b/cmd/within.website/yeetfile.js index b79868c..85abcf1 100644 --- a/cmd/within.website/yeetfile.js +++ b/cmd/within.website/yeetfile.js @@ -1,33 +1,6 @@ -yeet.setenv("GOOS", "linux"); -yeet.setenv("GOARCH", "amd64"); -yeet.setenv("CGO_ENABLED", "0"); +nix.build(".#docker.within-website"); +docker.load("./result"); +docker.push(`ghcr.io/xe/x/within-website`); +yeet.run("kubectl", "apply", "-f=manifest.yaml"); +yeet.run("sh", "-c", "kubectl rollout restart deployments/within-website"); -go.build(); -const fname = slug.build("within.website", { - "config.ts": "config.ts" -}); - -const url = slug.push(fname); -const hash = nix.hashURL(url); - -const expr = nix.expr`{ stdenv }: - -stdenv.mkDerivation { - name = "within.website"; - src = builtins.fetchurl { - url = ${url}; - sha256 = ${hash}; - }; - - phases = "installPhase"; - - installPhase = '' - tar xf $src - mkdir -p $out/bin - cp bin/main $out/bin/withinwebsite - cp config.ts $out/config.ts - ''; -} -`; - -file.write("/home/cadey/code/nixos-configs/pkgs/x/withinwebsite.nix", expr); |
