feat(deploy): run the dashboard as its own workload behind path routing

This commit is contained in:
sam committed 2026-11-28 14:12:17 +11:00
1 parent 378560175f
commit 099ce3fcaa
10 files changed
+296 -13

No files matched your search

+28 -2
View File
@@ -39,12 +39,38 @@ services:
- ./extensions:/archie/extensions:ro
- ./state:/archie/state
- ./catalogue:/archie/catalogue:ro
ports:
- "${ARCHIE_BIND:?}:8080"
networks: [internal]
depends_on:
archie-db:
condition: service_healthy
archie-frontend:
image: ${ARCHIE_FRONTEND_IMAGE:-ghcr.io/archie-platform/archie-frontend:v0.1.0}
restart: unless-stopped
read_only: true
tmpfs:
- /tmp
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
networks: [internal]
# The ingress: one host, routed by path to the backend or the dashboard.
edge:
image: nginxinc/nginx-unprivileged:1.29-alpine
restart: unless-stopped
read_only: true
tmpfs:
- /tmp
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
volumes:
- ./edge.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- "${ARCHIE_BIND:?}:8080"
networks: [internal]
depends_on: [archie, archie-frontend]
networks:
internal: {}
+17 -5
View File
@@ -1,28 +1,36 @@
#!/usr/bin/env bash
# Deploys the single binary's stack to a host over ssh: deploy.sh root@staging-host.
# The first run creates the secrets on the host; they never leave it.
# The first run creates the secrets on the host; they never leave it. The
# dashboard image is built from an archie-frontend checkout beside this one, or
# from ARCHIE_FRONTEND.
set -euo pipefail
target=${1:?usage: deploy.sh user@host [bind-address:port]}
bind=${2:-}
here=$(cd "$(dirname "$0")" && pwd)
repo=$(cd "$here/../.." && pwd)
frontend=${ARCHIE_FRONTEND:-"$(cd "$repo/.." && pwd)/archie-frontend"}
dir=/root/archie
version=$(git -C "$repo" describe --tags --always --dirty)
# The dashboard is embedded in the binary; never build from a stale ui/dist.
(cd "$repo" && task ui)
frontend_version=$(git -C "$frontend" describe --tags --always --dirty)
frontend_image="archie-frontend:$frontend_version"
docker build -q --build-arg VERSION="$frontend_version" \
--build-arg REVISION="$(git -C "$frontend" rev-parse HEAD)" \
-t "$frontend_image" "$frontend" >/dev/null
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C "$repo" -trimpath \
-ldflags "-X github.com/samcharles93/archie-core/internal/buildinfo.Version=$version" \
-o "$here/.build/archie" ./cmd/archie
ssh "$target" "mkdir -p $dir/bin $dir/initdb $dir/extensions $dir/catalogue $dir/state && chown 65532:65532 $dir/state"
scp -q "$here/compose.yml" "$target:$dir/compose.yml"
scp -q "$here/edge.conf" "$target:$dir/edge.conf"
docker save "$frontend_image" | ssh "$target" docker load -q
scp -q "$here/seccomp.json" "$target:$dir/seccomp.json"
scp -q "$here/initdb/01-roles.sh" "$target:$dir/initdb/01-roles.sh"
scp -q "$here/.build/archie" "$target:$dir/bin/archie.new"
ssh "$target" BIND="$bind" DIR="$dir" bash -s <<'REMOTE'
ssh "$target" BIND="$bind" DIR="$dir" FRONTEND_IMAGE="$frontend_image" bash -s <<'REMOTE'
set -euo pipefail
cd "$DIR"
chmod 755 initdb/01-roles.sh
@@ -77,7 +85,11 @@ if [ ! -f state/age/identity.txt ] && command -v age-keygen >/dev/null; then
chown -R 65532:65532 state/age
echo "age secret engine recipient: $(age-keygen -y state/age/identity.txt)"
fi
sed -i '/^ARCHIE_FRONTEND_IMAGE=/d' .env
echo "ARCHIE_FRONTEND_IMAGE=$FRONTEND_IMAGE" >> .env
docker compose up -d --remove-orphans
docker compose up -d --force-recreate archie
# edge.conf is a bind mount, so a changed route table needs a restart.
docker compose restart edge
REMOTE
echo "deployed $version to $target"
echo "deployed $version and dashboard $frontend_version to $target"
+33
View File
@@ -0,0 +1,33 @@
# The Compose stack's ingress: API, sign-in and webhook paths go to the
# backend, every other path to the dashboard, all on one host.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8080;
server_name _;
server_tokens off;
client_max_body_size 64m;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# TLS ends at the proxy in front of this one, so keep the scheme it saw.
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
location ~ ^/(api|oauth2|hooks)(/|$) {
# The dashboard's live stream is a long-lived response; buffering it
# would hold every update back.
proxy_buffering off;
proxy_read_timeout 1h;
proxy_pass http://archie:8080;
}
location / {
proxy_pass http://archie-frontend:8080;
}
}
@@ -99,3 +99,31 @@ restricted-v2 overlays can unset runAsUser, runAsGroup, and fsGroup cleanly).
{{- toYaml $out -}}
{{- end -}}
{{- end }}
{{/*
Dashboard name and selector labels. The name differs from the API's, so the
API's Service and NetworkPolicy never select dashboard pods.
*/}}
{{- define "archie.frontendFullname" -}}
{{- printf "%s-frontend" (include "archie.fullname" .) | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- define "archie.frontendSelectorLabels" -}}
app.kubernetes.io/name: {{ printf "%s-frontend" (include "archie.name" .) | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- define "archie.frontendLabels" -}}
helm.sh/chart: {{ include "archie.chart" . }}
{{ include "archie.frontendSelectorLabels" . }}
app.kubernetes.io/component: frontend
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- define "archie.frontendImage" -}}
{{- if .Values.frontend.image.digest }}
{{- printf "%s@%s" .Values.frontend.image.repository .Values.frontend.image.digest }}
{{- else }}
{{- printf "%s:%s" .Values.frontend.image.repository .Values.frontend.image.tag }}
{{- end }}
{{- end }}
@@ -0,0 +1,128 @@
{{- if .Values.frontend.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "archie.frontendFullname" . }}
labels:
{{- include "archie.frontendLabels" . | nindent 4 }}
spec:
{{- if not .Values.frontend.autoscaling.enabled }}
replicas: {{ .Values.frontend.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "archie.frontendSelectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "archie.frontendLabels" . | nindent 8 }}
spec:
automountServiceAccountToken: false
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- include "archie.compactYaml" .Values.frontend.podSecurityContext | nindent 8 }}
containers:
- name: frontend
image: {{ include "archie.frontendImage" . }}
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
securityContext:
{{- include "archie.compactYaml" .Values.frontend.securityContext | nindent 12 }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: http
readinessProbe:
httpGet:
path: /healthz
port: http
resources:
{{- toYaml .Values.frontend.resources | nindent 12 }}
volumeMounts:
# nginx keeps its pid file and temporary files here; the root
# filesystem is read-only.
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir:
sizeLimit: 64Mi
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "archie.frontendFullname" . }}
labels:
{{- include "archie.frontendLabels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- name: http
port: {{ .Values.frontend.service.port }}
targetPort: http
protocol: TCP
selector:
{{- include "archie.frontendSelectorLabels" . | nindent 4 }}
{{- if .Values.frontend.autoscaling.enabled }}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "archie.frontendFullname" . }}
labels:
{{- include "archie.frontendLabels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "archie.frontendFullname" . }}
minReplicas: {{ .Values.frontend.autoscaling.minReplicas }}
maxReplicas: {{ .Values.frontend.autoscaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.frontend.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.networkPolicy.enabled }}
---
# The dashboard only answers the internal ingress and calls nothing.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "archie.frontendFullname" . }}
labels:
{{- include "archie.frontendLabels" . | nindent 4 }}
spec:
podSelector:
matchLabels:
{{- include "archie.frontendSelectorLabels" . | nindent 6 }}
policyTypes:
- Ingress
- Egress
ingress:
- ports:
- protocol: TCP
port: 8080
{{- if or .Values.networkPolicy.ingress.internal.namespaceSelector .Values.networkPolicy.ingress.internal.podSelector }}
from:
- {{- if .Values.networkPolicy.ingress.internal.namespaceSelector }}
namespaceSelector:
{{- toYaml .Values.networkPolicy.ingress.internal.namespaceSelector | nindent 12 }}
{{- end }}
{{- if .Values.networkPolicy.ingress.internal.podSelector }}
podSelector:
{{- toYaml .Values.networkPolicy.ingress.internal.podSelector | nindent 12 }}
{{- end }}
{{- end }}
egress: []
{{- end }}
{{- end }}
+10 -1
View File
@@ -60,7 +60,7 @@ spec:
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
{{- range $.Values.ingress.internal.backendPaths }}
- path: {{ . }}
pathType: Prefix
backend:
@@ -69,5 +69,14 @@ spec:
port:
name: http
{{- end }}
{{- if $.Values.frontend.enabled }}
- path: /
pathType: Prefix
backend:
service:
name: {{ include "archie.frontendFullname" $ }}
port:
name: http
{{- end }}
{{- end }}
{{- end }}
@@ -22,3 +22,11 @@ securityContext:
capabilities:
drop:
- ALL
frontend:
podSecurityContext:
runAsNonRoot: true
runAsUser: null
runAsGroup: null
seccompProfile:
type: RuntimeDefault
-2
View File
@@ -51,8 +51,6 @@ ingress:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
hosts:
- host: archie.internal.example.com
paths:
- /
tls:
- secretName: archie-prod-internal-tls
hosts:
@@ -39,8 +39,6 @@ ingress:
className: "internal-nginx"
hosts:
- host: archie.staging.internal.example.com
paths:
- /
tls:
- secretName: archie-staging-internal-tls
hosts:
+44 -1
View File
@@ -212,6 +212,44 @@ metrics:
scrapeTimeout: "10s"
labels: {}
# The dashboard: static files served by its own image, routed by the internal
# ingress on the same host as the API.
frontend:
enabled: true
replicaCount: 2
image:
repository: ghcr.io/archie-platform/archie-frontend
tag: "v0.1.0"
digest: ""
pullPolicy: IfNotPresent
podSecurityContext:
runAsNonRoot: true
runAsUser: 101
runAsGroup: 101
seccompProfile:
type: RuntimeDefault
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- ALL
resources:
requests:
cpu: "25m"
memory: "32Mi"
limits:
cpu: "250m"
memory: "128Mi"
autoscaling:
enabled: false
minReplicas: 2
maxReplicas: 6
targetCPUUtilizationPercentage: 70
service:
port: 8080
ingress:
# External edge ingress admitting webhook intake (/hooks/ and /webhooks/) only.
perimeter:
@@ -220,12 +258,17 @@ ingress:
annotations: {}
hosts: []
tls: []
# Internal corporate VPN / SSO ingress serving Dashboard, /api/, and OIDC routes.
# Internal corporate VPN / SSO ingress. On each host, backendPaths go to the
# API and every other path to the dashboard.
internal:
enabled: false
className: ""
annotations: {}
hosts: []
backendPaths:
- /api
- /oauth2
- /hooks
tls: []
networkPolicy: