feat(comfyui): add Dockerfile, playbook, and Terraform configurations for ComfyUI setup

This commit is contained in:
2025-06-08 21:18:53 +02:00
parent d969525b58
commit 359b6d47aa
18 changed files with 400 additions and 170 deletions
+6
View File
@@ -17,3 +17,9 @@ module "dns" {
forward_dns_servers = local.dns_nameservers
zones = local.zones
}
module "reverse_proxy" {
source = "../../modules/apps/nginx-reverse-proxy"
services = local.reverse_proxy_services
}
+30
View File
@@ -50,6 +50,16 @@ locals {
type = "CNAME"
content = "dev-01.${local.lab_domain}."
},
{
name = "comfyui-backend"
type = "CNAME"
content = "gpu-01.${local.lab_domain}."
},
{
name = "comfyui"
type = "CNAME"
content = "dev-01.${local.lab_domain}."
},
{
name = "smb"
type = "CNAME"
@@ -58,4 +68,24 @@ locals {
]
}
]
reverse_proxy_services = {
"comfyui" = {
http_port = 8080
https_port = 8443
tls = true
fqdn = ["comfyui.lab.alexpires.me"]
upstream = "http://comfyui-backend.lab.alexpires.me:8188"
resolver = "10.19.4.136"
locations = [
{
path = "/"
"Upgrade" = "$http_upgrade"
"Connection" = "upgrade"
},
]
}
}
}
+4
View File
@@ -0,0 +1,4 @@
locals {
comfyui_version = "frontend${var.tag}"
}
+98
View File
@@ -0,0 +1,98 @@
resource "kubernetes_namespace" "comfyui" {
metadata {
name = "comfyui"
}
}
resource "kubernetes_service_account" "comfyui" {
metadata {
name = "comfyui-sa"
namespace = kubernetes_namespace.comfyui.metadata[0].name
}
automount_service_account_token = false
}
resource "kubernetes_deployment" "comfyui" {
metadata {
name = "comfyui"
namespace = kubernetes_namespace.comfyui.metadata[0].name
labels = {
comfyui = "comfyui"
}
}
spec {
replicas = 1
selector {
match_labels = {
comfyui = "comfyui"
}
}
strategy {
type = "RollingUpdate"
}
template {
metadata {
labels = {
comfyui = "comfyui"
}
}
spec {
service_account_name = kubernetes_service_account.comfyui.metadata[0].name
automount_service_account_token = false
container {
name = "comfyui"
image = "a13labs/comfyui:${local.comfyui_version}"
security_context {
allow_privilege_escalation = false
}
port {
name = "frontend"
container_port = 5173
protocol = "TCP"
}
env {
name = "DEV_SERVER_COMFYUI_URL"
value = coalesce(var.backend, "http://localhost:8188")
}
}
}
}
}
}
resource "kubernetes_service" "comfyui" {
metadata {
name = "frontend"
namespace = kubernetes_namespace.comfyui.metadata[0].name
}
spec {
selector = {
comfyui = "comfyui"
}
port {
name = "frontend"
port = 5173
target_port = 5173
}
}
lifecycle {
ignore_changes = [
metadata[0].annotations
]
}
}
@@ -0,0 +1,9 @@
terraform {
required_version = "~>1.8"
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.36.0"
}
}
}
@@ -0,0 +1,11 @@
variable "tag" {
description = "The version of app to install"
type = string
default = "v0.0.1"
}
variable "backend" {
description = "The backend to use for ComfyUI"
type = string
default = ""
}
@@ -170,6 +170,7 @@ resource "kubernetes_ingress_v1" "reverse-proxy_ingress" {
}
resource "kubernetes_secret" "auth_token" {
count = var.auth_token != "" ? 1 : 0
metadata {
name = "auth-token-secret"
namespace = kubernetes_namespace.reverse_proxy.metadata[0].name
@@ -281,31 +282,34 @@ resource "kubernetes_deployment" "reverse_proxy" {
}
}
container {
name = "auth-sidecar"
image = "python:3.11-slim"
dynamic "container" {
for_each = var.auth_token != "" ? [1] : []
content {
name = "auth-sidecar"
image = "python:3.11-slim"
command = ["python", "/app/auth_server.py"]
command = ["python", "/app/auth_server.py"]
env {
name = "AUTH_TOKEN"
value_from {
secret_key_ref {
name = "auth-token-secret"
key = "token"
env {
name = "AUTH_TOKEN"
value_from {
secret_key_ref {
name = kubernetes_secret.auth_token[0].metadata[0].name
key = "token"
}
}
}
}
volume_mount {
name = "auth-script"
mount_path = "/app"
read_only = true
}
volume_mount {
name = "auth-script"
mount_path = "/app"
read_only = true
}
port {
container_port = 5000
name = "auth"
port {
container_port = 5000
name = "auth"
}
}
}
@@ -39,10 +39,10 @@ location = /auth {
%{ if l.private ~}
auth_request /auth<;
%{ endif ~}
set $upstream "%{ if l.upstream != "" ~}${l.upstream}%{ else ~}${upstream}%{ endif ~}";
%{ if l.rewrite != "" ~}
rewrite ${l.rewrite};
%{ endif ~}
set $upstream "%{ if l.upstream != "" ~}${l.upstream}%{ else ~}${upstream}%{ endif ~}";
proxy_pass $upstream;
proxy_http_version 1.1;
%{ for k,v in l.headers ~}
@@ -30,7 +30,7 @@ variable "services" {
description = "A list of services to be deployed"
type = map(object({
fqdn = list(string)
upstream = string
upstream = optional(string, "")
resolver = optional(string, "")
default_headers = optional(map(string), {}),
http_port = optional(number, 80)
@@ -53,4 +53,5 @@ variable "auth_token" {
description = "The authentication token to use for the reverse proxy"
type = string
sensitive = true
default = ""
}