8d27f191bf
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>
204 lines
5.9 KiB
YAML
204 lines
5.9 KiB
YAML
---
|
|
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
|