Stage 1 of moving private images off the registry:2 container at registry.viktorbarzin.me:5050 (which has hit distribution#3324 corruption 3x in 3 weeks) onto Forgejo's built-in OCI registry. No cutover risk — pods still pull from the existing registry until Phase 3. What changes: * Forgejo deployment: memory 384Mi→1Gi, PVC 5Gi→15Gi (cap 50Gi). Explicit FORGEJO__packages__ENABLED + CHUNKED_UPLOAD_PATH (defensive, v11 default-on). * ingress_factory: max_body_size variable was declared but never wired in after the nginx→Traefik migration. Now creates a per-ingress Buffering middleware when set; default null = no limit (preserves existing behavior). Forgejo ingress sets max_body_size=5g to allow multi-GB layer pushes. * Cluster-wide registry-credentials Secret: 4th auths entry for forgejo.viktorbarzin.me, populated from Vault secret/viktor/ forgejo_pull_token (cluster-puller PAT, read:package). Existing Kyverno ClusterPolicy syncs cluster-wide — no policy edits. * Containerd hosts.toml redirect: forgejo.viktorbarzin.me → in-cluster Traefik LB 10.0.20.200 (avoids hairpin NAT for in-cluster pulls). Cloud-init for new VMs + scripts/setup-forgejo-containerd-mirror.sh for existing nodes. * Forgejo retention CronJob (0 4 * * *): keeps newest 10 versions per package + always :latest. First 7 days dry-run (DRY_RUN=true); flip the local in cleanup.tf after log review. * Forgejo integrity probe CronJob (*/15): same algorithm as the existing registry-integrity-probe. Existing Prometheus alerts (RegistryManifestIntegrityFailure et al) made instance-aware so they cover both registries during the bake. * Docs: design+plan in docs/plans/, setup runbook in docs/runbooks/. Operational note — the apply order is non-trivial because the new Vault keys (forgejo_pull_token, forgejo_cleanup_token, secret/ci/global/forgejo_*) must exist BEFORE terragrunt apply in the kyverno + monitoring + forgejo stacks. The setup runbook documents the bootstrap sequence. Phase 1 (per-project dual-push pipelines) follows in subsequent commits. Bake clock starts when the last project goes dual-push. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
192 lines
5.3 KiB
HCL
192 lines
5.3 KiB
HCL
variable "tls_secret_name" {
|
|
type = string
|
|
sensitive = true
|
|
}
|
|
variable "nfs_server" { type = string }
|
|
|
|
resource "kubernetes_namespace" "forgejo" {
|
|
metadata {
|
|
name = "forgejo"
|
|
labels = {
|
|
"istio-injection" : "disabled"
|
|
tier = local.tiers.edge
|
|
}
|
|
}
|
|
lifecycle {
|
|
# KYVERNO_LIFECYCLE_V1: goldilocks-vpa-auto-mode ClusterPolicy stamps this label on every namespace
|
|
ignore_changes = [metadata[0].labels["goldilocks.fairwinds.com/vpa-update-mode"]]
|
|
}
|
|
}
|
|
|
|
module "tls_secret" {
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
tls_secret_name = var.tls_secret_name
|
|
}
|
|
|
|
resource "kubernetes_persistent_volume_claim" "data_encrypted" {
|
|
wait_until_bound = false
|
|
metadata {
|
|
name = "forgejo-data-encrypted"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
annotations = {
|
|
"resize.topolvm.io/threshold" = "80%"
|
|
"resize.topolvm.io/increase" = "50%"
|
|
"resize.topolvm.io/storage_limit" = "50Gi"
|
|
}
|
|
}
|
|
spec {
|
|
access_modes = ["ReadWriteOnce"]
|
|
storage_class_name = "proxmox-lvm-encrypted"
|
|
resources {
|
|
requests = {
|
|
storage = "15Gi"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_deployment" "forgejo" {
|
|
metadata {
|
|
name = "forgejo"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
labels = {
|
|
app = "forgejo"
|
|
tier = local.tiers.edge
|
|
}
|
|
}
|
|
spec {
|
|
replicas = 1
|
|
strategy {
|
|
type = "Recreate"
|
|
}
|
|
selector {
|
|
match_labels = {
|
|
app = "forgejo"
|
|
}
|
|
}
|
|
template {
|
|
metadata {
|
|
labels = {
|
|
app = "forgejo"
|
|
}
|
|
}
|
|
spec {
|
|
container {
|
|
name = "forgejo"
|
|
image = "codeberg.org/forgejo/forgejo:11"
|
|
env {
|
|
name = "USER_UID"
|
|
value = 1000
|
|
}
|
|
env {
|
|
name = "USER_GID"
|
|
value = 1000
|
|
}
|
|
# Root URL for OAuth2 redirect callbacks
|
|
env {
|
|
name = "FORGEJO__server__ROOT_URL"
|
|
value = "https://forgejo.viktorbarzin.me"
|
|
}
|
|
# Disable local registration — only allow OAuth2 (Authentik)
|
|
env {
|
|
name = "FORGEJO__service__DISABLE_REGISTRATION"
|
|
value = "false"
|
|
}
|
|
env {
|
|
name = "FORGEJO__service__ALLOW_ONLY_EXTERNAL_REGISTRATION"
|
|
value = "true"
|
|
}
|
|
env {
|
|
name = "FORGEJO__openid__ENABLE_OPENID_SIGNIN"
|
|
value = "false"
|
|
}
|
|
# Allow webhook delivery to internal k8s services
|
|
env {
|
|
name = "FORGEJO__webhook__ALLOWED_HOST_LIST"
|
|
value = "*.svc.cluster.local"
|
|
}
|
|
# OCI registry (container packages). Default-on in Forgejo v11 but
|
|
# explicit so it can't be silently disabled by an upstream config
|
|
# change. Chunked-upload path needs a directory inside /data so it
|
|
# survives pod restarts and shares the same PVC as the registry blobs.
|
|
env {
|
|
name = "FORGEJO__packages__ENABLED"
|
|
value = "true"
|
|
}
|
|
env {
|
|
name = "FORGEJO__packages__CHUNKED_UPLOAD_PATH"
|
|
value = "/data/tmp/package-upload"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/data"
|
|
}
|
|
resources {
|
|
requests = {
|
|
cpu = "15m"
|
|
memory = "1Gi"
|
|
}
|
|
limits = {
|
|
memory = "1Gi"
|
|
}
|
|
}
|
|
port {
|
|
name = "http"
|
|
container_port = 3000
|
|
protocol = "TCP"
|
|
}
|
|
}
|
|
volume {
|
|
name = "data"
|
|
persistent_volume_claim {
|
|
claim_name = kubernetes_persistent_volume_claim.data_encrypted.metadata[0].name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
lifecycle {
|
|
# KYVERNO_LIFECYCLE_V1: Kyverno admission webhook mutates dns_config with ndots=2
|
|
ignore_changes = [spec[0].template[0].spec[0].dns_config]
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_service" "forgejo" {
|
|
metadata {
|
|
name = "forgejo"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
labels = {
|
|
"app" = "forgejo"
|
|
}
|
|
}
|
|
|
|
spec {
|
|
selector = {
|
|
app = "forgejo"
|
|
}
|
|
port {
|
|
port = 80
|
|
target_port = 3000
|
|
}
|
|
}
|
|
}
|
|
module "ingress" {
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
dns_type = "non-proxied"
|
|
namespace = kubernetes_namespace.forgejo.metadata[0].name
|
|
name = "forgejo"
|
|
tls_secret_name = var.tls_secret_name
|
|
# OCI registry pushes ship full image layer blobs in one request; default
|
|
# Traefik buffering chokes on anything past a few hundred MB.
|
|
max_body_size = "5g"
|
|
extra_annotations = {
|
|
"gethomepage.dev/enabled" = "true"
|
|
"gethomepage.dev/name" = "Forgejo"
|
|
"gethomepage.dev/description" = "Git hosting"
|
|
"gethomepage.dev/icon" = "forgejo.png"
|
|
"gethomepage.dev/group" = "Development & CI"
|
|
"gethomepage.dev/pod-selector" = ""
|
|
"uptime.viktorbarzin.me/external-monitor-path" = "/api/healthz"
|
|
}
|
|
}
|