Skip to content

Instantly share code, notes, and snippets.

@knadh
Created November 10, 2025 18:18
Show Gist options
  • Select an option

  • Save knadh/9b4583f14f58835e61fc6f89ffc3353c to your computer and use it in GitHub Desktop.

Select an option

Save knadh/9b4583f14f58835e61fc6f89ffc3353c to your computer and use it in GitHub Desktop.
Discourse forum Nomad deployment
# Self-contained Nomad job file for deploying a Discourse instance. Uses Postgres, Redis, and Discourse Docker containers. SSL-enabled.
# Create a vars.hcl file and set values for the below variable names (one per line), eg: hostname=yoursite.com
# Then run `nomad run -var-file=vars.hcl discourse-forum.hcl`
# Global database configuration variables.
variable "hostname" {}
variable "developer_emails" {}
variable "db_name" {}
variable "db_username" {}
variable "db_password" {}
variable "smtp_address" {}
variable "smtp_port" {}
variable "smtp_user_name" {}
variable "smtp_password" {}
# SSL/HTTPS configuration variables.
variable "enable_https" {
type = bool
default = true
}
variable "letsencrypt_account_email" {
type = string
default = "[email protected]"
}
# Nomad job for Discourse forum.
job "forum" {
datacenters = ["dc1"]
type = "service"
# Main group.
group "discourse" {
network {
mode = "host"
port "http" {
static = 80
}
port "https" {
static = 443
}
port "postgres" {
to = 5432
}
port "redis" {
to = 6379
}
}
# Register Discourse service for discovery.
service {
name = "discourse"
port = "http"
provider = "nomad"
}
service {
name = "discourse-https"
port = "https"
provider = "nomad"
}
# Define persistent volumes for Discourse data and Postgres data.
volume "discourse_data" {
type = "host"
source = "discourse_data"
read_only = false
}
volume "discourse_pg_data" {
type = "host"
source = "discourse_pg_data"
read_only = false
}
volume "discourse_ssl" {
type = "host"
source = "discourse_ssl"
read_only = false
}
# Main Postgres database task.
task "postgres" {
driver = "docker"
volume_mount {
volume = "discourse_pg_data"
destination = "/var/lib/postgresql/data"
}
config {
# Discourse's official Postgres image (with pgvector and other exts).
image = "discourse/postgres:latest"
ports = ["postgres"]
network_mode = "host"
}
# Postgres DB credentials using global variables.
env {
POSTGRES_DB = var.db_name
DB_USER = var.db_username
DB_PASSWORD = var.db_password
}
resources {
cpu = 1024
memory = 2048
}
}
# Redis for Discourse caching.
task "redis" {
driver = "docker"
config {
image = "redis:8-alpine"
ports = ["redis"]
network_mode = "host"
}
resources {
cpu = 1024
memory = 2048
}
}
# Discourse application.
task "discourse" {
driver = "docker"
volume_mount {
volume = "discourse_data"
destination = "/shared"
}
volume_mount {
volume = "discourse_ssl"
destination = "/shared/ssl"
}
config {
image = "discourse/discourse:latest"
ports = ["http", "https"]
network_mode = "host"
}
# Discourse configuration via environment variables.
env {
DISCOURSE_HOSTNAME = var.hostname
DISCOURSE_DEVELOPER_EMAILS = var.developer_emails
DISCOURSE_SMTP_ADDRESS = var.smtp_address
DISCOURSE_SMTP_PORT = var.smtp_port
DISCOURSE_SMTP_USER_NAME = var.smtp_user_name
DISCOURSE_SMTP_PASSWORD = var.smtp_password
DISCOURSE_DB_NAME = var.db_name
DISCOURSE_DB_USERNAME = var.db_username
DISCOURSE_DB_PASSWORD = var.db_password
DISCOURSE_DB_HOST = "${NOMAD_IP_postgres}"
DISCOURSE_DB_PORT = "${NOMAD_PORT_postgres}"
DISCOURSE_REDIS_HOST = "${NOMAD_IP_redis}"
DISCOURSE_REDIS_PORT = "${NOMAD_PORT_redis}"
# SSL/HTTPS configuration.
DISCOURSE_ENABLE_HTTPS = var.enable_https
LETSENCRYPT_ACCOUNT_EMAIL = var.letsencrypt_account_email
}
resources {
cpu = 1024
memory = 2048
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment