Add autocraft app (#595)
AutoCraft (IUCLabs/autocraft) needs a home in the cluster: one SQLite-backed pod running dashboard, runner and sync, signing in through the iuclabs-coder GitHub App. - add autocraft StatefulSet (1 replica, data/config PVCs) with bwrap runner settings - render secrets.json from kv/service/github/iuclabs/coder via VSO; init container installs it 0600 with a persistent session key - restart the StatefulSet when the Vault secret changes - serve autocraft.unkin.net from traefik-external with the reflected wildcard cert - register autocraft in the aitooling ApplicationSet/AppProject Requires IUCLabs/terraform-vault #11 applied first. Reviewed-on: #595 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
This commit was merged in pull request #595.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
---
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
labels:
|
||||
traefik.io/instance: external
|
||||
name: autocraft-external
|
||||
namespace: autocraft
|
||||
spec:
|
||||
gatewayClassName: traefik-external
|
||||
listeners:
|
||||
- allowedRoutes:
|
||||
namespaces:
|
||||
from: Same
|
||||
hostname: autocraft.unkin.net
|
||||
name: http
|
||||
port: 80
|
||||
protocol: HTTP
|
||||
- allowedRoutes:
|
||||
namespaces:
|
||||
from: Same
|
||||
hostname: autocraft.unkin.net
|
||||
name: https
|
||||
port: 443
|
||||
protocol: HTTPS
|
||||
tls:
|
||||
certificateRefs:
|
||||
- group: ""
|
||||
kind: Secret
|
||||
name: wildcard-unkin-net-tls
|
||||
mode: Terminate
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: HTTPRoute
|
||||
metadata:
|
||||
name: autocraft-external-http-redirect
|
||||
namespace: autocraft
|
||||
spec:
|
||||
hostnames:
|
||||
- autocraft.unkin.net
|
||||
parentRefs:
|
||||
- group: gateway.networking.k8s.io
|
||||
kind: Gateway
|
||||
name: autocraft-external
|
||||
sectionName: http
|
||||
rules:
|
||||
- filters:
|
||||
- type: RequestRedirect
|
||||
requestRedirect:
|
||||
scheme: https
|
||||
statusCode: 301
|
||||
matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
value: /
|
||||
---
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: HTTPRoute
|
||||
metadata:
|
||||
name: autocraft-external
|
||||
namespace: autocraft
|
||||
spec:
|
||||
hostnames:
|
||||
- autocraft.unkin.net
|
||||
parentRefs:
|
||||
- group: gateway.networking.k8s.io
|
||||
kind: Gateway
|
||||
name: autocraft-external
|
||||
sectionName: https
|
||||
rules:
|
||||
- backendRefs:
|
||||
- group: ""
|
||||
kind: Service
|
||||
name: autocraft-dashboard
|
||||
port: 3005
|
||||
weight: 1
|
||||
matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
value: /
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- serviceaccount.yaml
|
||||
- vaultauth.yaml
|
||||
- vaultstaticsecret.yaml
|
||||
- service.yaml
|
||||
- statefulset.yaml
|
||||
- gateway.yaml
|
||||
- httproute.yaml
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: autocraft
|
||||
name: autocraft
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: autocraft-dashboard
|
||||
namespace: autocraft
|
||||
labels:
|
||||
app.kubernetes.io/name: autocraft
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/name: autocraft
|
||||
ports:
|
||||
- name: http
|
||||
port: 3005
|
||||
targetPort: dashboard
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: autocraft-worker-api
|
||||
namespace: autocraft
|
||||
labels:
|
||||
app.kubernetes.io/name: autocraft
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/name: autocraft
|
||||
ports:
|
||||
- name: http
|
||||
port: 8981
|
||||
targetPort: worker-api
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: autocraft
|
||||
namespace: autocraft
|
||||
automountServiceAccountToken: false
|
||||
@@ -0,0 +1,203 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: autocraft
|
||||
namespace: autocraft
|
||||
labels:
|
||||
app.kubernetes.io/name: autocraft
|
||||
spec:
|
||||
serviceName: autocraft-dashboard
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: autocraft
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: autocraft
|
||||
spec:
|
||||
serviceAccountName: autocraft
|
||||
automountServiceAccountToken: false
|
||||
hostUsers: false
|
||||
terminationGracePeriodSeconds: 30
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 10001
|
||||
runAsGroup: 10001
|
||||
fsGroup: 10001
|
||||
initContainers:
|
||||
- name: secrets
|
||||
image: ghcr.io/iuclabs/autocraft:v0.1.0
|
||||
command:
|
||||
- node
|
||||
- -e
|
||||
- |
|
||||
const fs = require("fs"), crypto = require("crypto");
|
||||
const out = "/config/secrets.json", tmp = out + ".tmp";
|
||||
const s = JSON.parse(fs.readFileSync("/vault/secrets.json", "utf8"));
|
||||
let key;
|
||||
try { key = JSON.parse(fs.readFileSync(out, "utf8")).session_key; } catch {}
|
||||
s.session_key = typeof key === "string" && key.length >= 32 ? key : crypto.randomBytes(32).toString("hex");
|
||||
fs.writeFileSync(tmp, JSON.stringify(s), { mode: 0o600 });
|
||||
fs.chmodSync(tmp, 0o600);
|
||||
fs.renameSync(tmp, out);
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /config
|
||||
- name: vault-secrets
|
||||
mountPath: /vault
|
||||
readOnly: true
|
||||
containers:
|
||||
- name: dashboard
|
||||
image: ghcr.io/iuclabs/autocraft:v0.1.0
|
||||
args: ["dashboard"]
|
||||
env:
|
||||
- name: AUTOCRAFT_BASE_URL
|
||||
value: https://autocraft.unkin.net
|
||||
- name: AUTOCRAFT_TRUST_PROXY
|
||||
value: "1"
|
||||
- name: AUTOCRAFT_DEFAULT_OWNER
|
||||
value: IUCLabs
|
||||
ports:
|
||||
- name: dashboard
|
||||
containerPort: 3005
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: dashboard
|
||||
periodSeconds: 10
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /readyz
|
||||
port: dashboard
|
||||
periodSeconds: 5
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 1Gi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
- name: config
|
||||
mountPath: /config
|
||||
- name: runner
|
||||
image: ghcr.io/iuclabs/autocraft:v0.1.0
|
||||
args: ["runner"]
|
||||
env:
|
||||
- name: AUTOCRAFT_BASE_URL
|
||||
value: https://autocraft.unkin.net
|
||||
- name: AUTOCRAFT_DEFAULT_OWNER
|
||||
value: IUCLabs
|
||||
ports:
|
||||
- name: worker-api
|
||||
containerPort: 8981
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: worker-api
|
||||
periodSeconds: 10
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /readyz
|
||||
port: worker-api
|
||||
periodSeconds: 5
|
||||
resources:
|
||||
requests:
|
||||
cpu: 500m
|
||||
memory: 1Gi
|
||||
limits:
|
||||
cpu: "2"
|
||||
memory: 4Gi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
procMount: Unmasked
|
||||
seccompProfile:
|
||||
type: Unconfined
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
- name: config
|
||||
mountPath: /config
|
||||
- name: periodic
|
||||
image: ghcr.io/iuclabs/autocraft:v0.1.0
|
||||
command:
|
||||
- /usr/bin/tini
|
||||
- --
|
||||
- /bin/bash
|
||||
- -c
|
||||
- |
|
||||
trap 'exit 0' TERM INT
|
||||
last_backup() {
|
||||
f=$(ls -1t /data/backups/daily-*.db.* 2>/dev/null | head -n 1)
|
||||
if [ -n "$f" ]; then stat -c %Y "$f"; else echo 0; fi
|
||||
}
|
||||
while true; do
|
||||
/app/deploy/entrypoint.sh sync || echo "sync exited $?" >&2
|
||||
if [ $(( $(date +%s) - $(last_backup) )) -ge 86400 ]; then
|
||||
/app/deploy/entrypoint.sh backup daily 7 || echo "backup exited $?" >&2
|
||||
fi
|
||||
sleep 60 & wait $!
|
||||
done
|
||||
env:
|
||||
- name: AUTOCRAFT_DEFAULT_OWNER
|
||||
value: IUCLabs
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: "1"
|
||||
memory: 1Gi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
- name: config
|
||||
mountPath: /config
|
||||
volumes:
|
||||
- name: vault-secrets
|
||||
secret:
|
||||
secretName: autocraft-secrets
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
storageClassName: cephrbd-fast-delete
|
||||
resources:
|
||||
requests:
|
||||
storage: 20Gi
|
||||
- metadata:
|
||||
name: config
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
storageClassName: cephrbd-fast-delete
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
apiVersion: secrets.hashicorp.com/v1beta1
|
||||
kind: VaultAuth
|
||||
metadata:
|
||||
name: default
|
||||
namespace: autocraft
|
||||
spec:
|
||||
allowedNamespaces:
|
||||
- autocraft
|
||||
kubernetes:
|
||||
audiences:
|
||||
- vault
|
||||
role: autocraft
|
||||
serviceAccount: autocraft
|
||||
tokenExpirationSeconds: 600
|
||||
method: kubernetes
|
||||
mount: k8s/au/syd1
|
||||
vaultConnectionRef: vso-system/default
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
# Renders secrets.json without session_key; the init container adds a persistent one.
|
||||
apiVersion: secrets.hashicorp.com/v1beta1
|
||||
kind: VaultStaticSecret
|
||||
metadata:
|
||||
name: autocraft-secrets
|
||||
namespace: autocraft
|
||||
spec:
|
||||
destination:
|
||||
create: true
|
||||
name: autocraft-secrets
|
||||
overwrite: true
|
||||
transformation:
|
||||
excludes:
|
||||
- .*
|
||||
templates:
|
||||
secrets.json:
|
||||
text: |-
|
||||
{{- $s := .Secrets -}}
|
||||
{{- dict
|
||||
"github_client_id" (get $s "client_id" | toString)
|
||||
"github_client_secret" (get $s "client_secret" | toString)
|
||||
"github_app_id" (get $s "app_id" | int64 | toString)
|
||||
"github_app_slug" "iuclabs-coder"
|
||||
"github_app_private_key" (get $s "private_key" | toString)
|
||||
"github_app_client_id" (get $s "client_id" | toString)
|
||||
"github_app_client_secret" (get $s "client_secret" | toString)
|
||||
"github_app_webhook_secret" ""
|
||||
"github_app_owner" (dict "login" "IUCLabs" "type" "Organization")
|
||||
| toJson -}}
|
||||
hmacSecretData: true
|
||||
mount: kv
|
||||
path: service/github/iuclabs/coder
|
||||
refreshAfter: 5m
|
||||
rolloutRestartTargets:
|
||||
- kind: StatefulSet
|
||||
name: autocraft
|
||||
type: kv-v2
|
||||
vaultAuthRef: default
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
apiVersion: bind.unkin.net/v1alpha1
|
||||
kind: DNSRecord
|
||||
metadata:
|
||||
name: autocraft-dns-internal
|
||||
namespace: bind-internal
|
||||
spec:
|
||||
zoneRef: unkin-net
|
||||
name: autocraft
|
||||
type: A
|
||||
ttl: 600
|
||||
values:
|
||||
# traefik-EXTERNAL (DMZ) gateway VIP; the autocraft-external Gateway serves
|
||||
# autocraft.unkin.net there.
|
||||
- 198.18.199.0
|
||||
@@ -4,6 +4,7 @@ kind: Kustomization
|
||||
|
||||
resources:
|
||||
- arrstack.yaml
|
||||
- autocraft.yaml
|
||||
- auth.yaml
|
||||
- cheeztv.yaml
|
||||
- fafflix.yaml
|
||||
|
||||
@@ -14,9 +14,9 @@ spec:
|
||||
secretTemplate:
|
||||
annotations:
|
||||
reflector.v1.k8s.emberstack.com/reflection-allowed: "true"
|
||||
reflector.v1.k8s.emberstack.com/reflection-allowed-namespaces: "cheeztv,arrstack,authentik,gitea,watchstate,mediamark,repospawner,haproxy,vlogs,grafana,mail"
|
||||
reflector.v1.k8s.emberstack.com/reflection-allowed-namespaces: "cheeztv,arrstack,authentik,gitea,watchstate,mediamark,repospawner,haproxy,vlogs,grafana,mail,autocraft"
|
||||
reflector.v1.k8s.emberstack.com/reflection-auto-enabled: "true"
|
||||
reflector.v1.k8s.emberstack.com/reflection-auto-namespaces: "cheeztv,arrstack,authentik,gitea,watchstate,mediamark,repospawner,haproxy,vlogs,grafana,mail"
|
||||
reflector.v1.k8s.emberstack.com/reflection-auto-namespaces: "cheeztv,arrstack,authentik,gitea,watchstate,mediamark,repospawner,haproxy,vlogs,grafana,mail,autocraft"
|
||||
privateKey:
|
||||
size: 4096
|
||||
dnsNames:
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- ../../../base/autocraft
|
||||
@@ -10,6 +10,7 @@ spec:
|
||||
repoURL: https://git.unkin.net/unkin/argocd-apps
|
||||
revision: HEAD
|
||||
directories:
|
||||
- path: apps/overlays/*/autocraft
|
||||
- path: apps/overlays/*/litellm
|
||||
- path: apps/overlays/*/paperclip
|
||||
template:
|
||||
|
||||
@@ -9,6 +9,8 @@ spec:
|
||||
sourceRepos:
|
||||
- https://git.unkin.net/unkin/argocd-apps
|
||||
destinations:
|
||||
- namespace: 'autocraft'
|
||||
server: https://kubernetes.default.svc
|
||||
- namespace: 'litellm'
|
||||
server: https://kubernetes.default.svc
|
||||
- namespace: 'paperclip'
|
||||
|
||||
Reference in New Issue
Block a user