diff --git a/kubernetes/apps/selfhosted/resume/app/blog-builder.yaml b/kubernetes/apps/selfhosted/resume/app/blog-builder.yaml new file mode 100644 index 0000000000..5deeddf0d6 --- /dev/null +++ b/kubernetes/apps/selfhosted/resume/app/blog-builder.yaml @@ -0,0 +1,78 @@ +--- +# Builds derekmackley.com/blog from pushed articles. Every few minutes it hashes +# blog-content/articles; when they (or the builder image) changed it runs `astro build` +# in scratch space, copies the result to blog-content/site/releases/- and +# switches site/current to it with one rename, keeping the newest three releases. When +# nothing changed it exits in about a second. +# +# It never sees the Obsidian vault: the only volume is blog-content. Articles arrive +# there from the private-side push; the resume pod serves site/current read-only. +# Image: developer-portfolio's blog/Dockerfile (ghcr.io/dapperdivers/developer-portfolio-blog). +# yaml-language-server: $schema=https://raw.githubusercontent.com/bjw-s/helm-charts/main/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: blog-builder +spec: + interval: 30m + chartRef: + kind: OCIRepository + name: app-template + install: + remediation: + retries: 3 + upgrade: + cleanupOnFail: true + remediation: + strategy: rollback + retries: 3 + values: + defaultPodOptions: + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + runAsNonRoot: true + fsGroup: 1000 + fsGroupChangePolicy: OnRootMismatch + seccompProfile: + type: RuntimeDefault + controllers: + blog-builder: + type: cronjob + cronjob: + schedule: "*/5 * * * *" + concurrencyPolicy: Forbid + activeDeadlineSeconds: 900 + successfulJobsHistory: 1 + failedJobsHistory: 2 + containers: + app: + image: + repository: ghcr.io/dapperdivers/developer-portfolio-blog + # Pin to the first published image's tag@digest before merging (see the PR) + tag: latest + env: + ARTICLES_DIR: /content/articles + SITE_DIR: /content/site + KEEP_RELEASES: "3" + resources: + requests: + cpu: 50m + memory: 256Mi + limits: + memory: 1Gi + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] + persistence: + content: + existingClaim: blog-content + globalMounts: + - path: /content + tmp: + type: emptyDir + sizeLimit: 1Gi + globalMounts: + - path: /tmp diff --git a/kubernetes/apps/selfhosted/resume/app/helmrelease.yaml b/kubernetes/apps/selfhosted/resume/app/helmrelease.yaml index 6a9b668621..a5c24a8ec6 100644 --- a/kubernetes/apps/selfhosted/resume/app/helmrelease.yaml +++ b/kubernetes/apps/selfhosted/resume/app/helmrelease.yaml @@ -34,6 +34,9 @@ spec: # would put every visitor in one bucket. Rate limit at the # Cloudflare edge instead. RATE_LIMIT_MAX: "0" + # The live blog release: blog-builder points site/current at the newest + # build with an atomic symlink switch, so no restart is needed + BLOG_PATH: /app/blog-static/site/current securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: false @@ -89,6 +92,15 @@ spec: app: - path: /tmp readOnly: false + # The blog volume (PVC from ../ks.yaml), read-only. The app serves only site/current + # (BLOG_PATH); articles/ is the builder's input and is never served. + blog: + existingClaim: blog-content + advancedMounts: + resume: + app: + - path: /app/blog-static + readOnly: true service: app: controller: *app diff --git a/kubernetes/apps/selfhosted/resume/app/kustomization.yaml b/kubernetes/apps/selfhosted/resume/app/kustomization.yaml index 17cbc72b25..f2b3362ab2 100644 --- a/kubernetes/apps/selfhosted/resume/app/kustomization.yaml +++ b/kubernetes/apps/selfhosted/resume/app/kustomization.yaml @@ -4,3 +4,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ./helmrelease.yaml + - ./blog-builder.yaml diff --git a/kubernetes/apps/selfhosted/resume/blog/kustomization.yaml b/kubernetes/apps/selfhosted/resume/blog/kustomization.yaml new file mode 100644 index 0000000000..d617c290c2 --- /dev/null +++ b/kubernetes/apps/selfhosted/resume/blog/kustomization.yaml @@ -0,0 +1,7 @@ +--- +# Intentionally empty: the Flux Kustomization injects the volsync components, which +# create the blog-content PVC and its backup/restore resources. +# yaml-language-server: $schema=https://json.schemastore.org/kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: [] diff --git a/kubernetes/apps/selfhosted/resume/ks.yaml b/kubernetes/apps/selfhosted/resume/ks.yaml index 20751b6a48..bc329114bc 100644 --- a/kubernetes/apps/selfhosted/resume/ks.yaml +++ b/kubernetes/apps/selfhosted/resume/ks.yaml @@ -13,6 +13,8 @@ spec: dependsOn: - name: volsync namespace: storage + - name: blog-content + namespace: selfhosted path: "./kubernetes/apps/selfhosted/resume/app" prune: true sourceRef: @@ -26,3 +28,45 @@ spec: postBuild: substitute: APP: *app +--- +# The built blog served at derekmackley.com/blog. A publisher job writes the static +# site here; the resume pod mounts it read-only. Content is rebuilt from the vault, so +# a daily backup is plenty; it restores itself if the PVC is ever recreated. +# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/kustomize.toolkit.fluxcd.io/kustomization_v1.json +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: &app blog-content + namespace: &namespace selfhosted +spec: + targetNamespace: *namespace + components: + - ../../../../flux/components/volsync/repository + - ../../../../flux/components/volsync/operations + commonMetadata: + labels: + app.kubernetes.io/name: *app + dependsOn: + - name: volsync + namespace: storage + path: ./kubernetes/apps/selfhosted/resume/blog + prune: true + sourceRef: + kind: GitRepository + name: flux-system + namespace: flux-system + wait: true + interval: 30m + retryInterval: 1m + timeout: 10m + postBuild: + substitute: + APP: *app + VOLSYNC_CAPACITY: 2Gi + VOLSYNC_CACHE_CAPACITY: 1Gi + VOLSYNC_STORAGECLASS: cephfs-shared + VOLSYNC_SNAPSHOTCLASS: cephfs-snapshot + VOLSYNC_ACCESSMODES: ReadWriteMany # publisher job writes, resume pods read + VOLSYNC_SCHEDULE: "0 3 * * *" + VOLSYNC_PUID: "1000" + VOLSYNC_PGID: "1000"