184 lines
4.8 KiB
HCL
184 lines
4.8 KiB
HCL
job "navidrome-litefs" {
|
|
datacenters = ["dc1"]
|
|
type = "service"
|
|
|
|
# We pin to Linux because LiteFS requires FUSE
|
|
constraint {
|
|
attribute = "${attr.kernel.name}"
|
|
value = "linux"
|
|
}
|
|
|
|
group "navidrome" {
|
|
count = 2
|
|
|
|
constraint {
|
|
distinct_hosts = true
|
|
}
|
|
|
|
network {
|
|
mode = "host"
|
|
port "http" {}
|
|
}
|
|
|
|
# --- Setup Task ---
|
|
task "setup" {
|
|
driver = "docker"
|
|
lifecycle {
|
|
hook = "prestart"
|
|
sidecar = false
|
|
}
|
|
config {
|
|
image = "busybox"
|
|
command = "mkdir"
|
|
args = ["-p", "/alloc/sqlite"]
|
|
network_mode = "host"
|
|
}
|
|
}
|
|
|
|
# --- LiteFS Task ---
|
|
task "litefs" {
|
|
driver = "docker"
|
|
|
|
config {
|
|
image = "flyio/litefs:0.5"
|
|
privileged = true # Needed for FUSE
|
|
ports = ["http"]
|
|
network_mode = "host"
|
|
|
|
# 1. Bind mount for LiteFS internal data (chunks/WAL)
|
|
# 2. Bind mount for the config
|
|
# 3. Mount the shared alloc dir so we can mount FUSE on it
|
|
volumes = [
|
|
"/mnt/configs/navidrome_litefs:/var/lib/litefs",
|
|
"local/litefs.yml:/etc/litefs.yml"
|
|
]
|
|
|
|
mounts = [
|
|
{
|
|
type = "bind"
|
|
source = "../alloc/sqlite"
|
|
target = "/mnt/sqlite"
|
|
bind_options = {
|
|
propagation = "shared"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
|
|
# Create the config file
|
|
template {
|
|
left_delimiter = "[["
|
|
right_delimiter = "]]"
|
|
data = <<EOF
|
|
fuse:
|
|
# This matches the internal mount point in the container
|
|
dir: "/mnt/sqlite"
|
|
|
|
data:
|
|
# Internal data storage
|
|
dir: "/var/lib/litefs"
|
|
|
|
# Use Consul for leader election
|
|
lease:
|
|
type: "consul"
|
|
consul:
|
|
url: "http://[[ env `attr.unique.network.ip-address` ]]:8500"
|
|
key: "litefs/navidrome"
|
|
|
|
# The HTTP Proxy routes traffic
|
|
proxy:
|
|
addr: ":[[ env `NOMAD_PORT_http` ]]"
|
|
target: "127.0.0.1:4533" # Navidrome's internal port
|
|
db: "navidrome.db" # The DB to track for transaction consistency
|
|
passthrough: # Paths that don't need write-forwarding (optional optimizations)
|
|
- "*.js"
|
|
- "*.css"
|
|
- "*.png"
|
|
EOF
|
|
destination = "local/litefs.yml"
|
|
}
|
|
|
|
resources {
|
|
cpu = 200
|
|
memory = 256
|
|
}
|
|
}
|
|
|
|
# --- Navidrome Task (The App) ---
|
|
task "navidrome" {
|
|
driver = "docker"
|
|
|
|
config {
|
|
image = "ghcr.io/navidrome/navidrome:latest"
|
|
memory_hard_limit = "2048"
|
|
ports = [] # No ports exposed directly!
|
|
network_mode = "host"
|
|
|
|
# We mount the sqlite dir from the allocation directory
|
|
mounts = [
|
|
{
|
|
type = "bind"
|
|
source = "../alloc/sqlite"
|
|
target = "/data"
|
|
bind_options = {
|
|
propagation = "shared"
|
|
}
|
|
}
|
|
]
|
|
|
|
# Shared Music and Configs
|
|
volumes = [
|
|
"/mnt/Public/Downloads/Clean_Music:/music/CleanMusic:ro",
|
|
"/mnt/Public/Downloads/news/slskd/downloads:/music/slskd:ro",
|
|
"/mnt/Public/Downloads/incoming_music:/music/incomingmusic:ro",
|
|
"/mnt/Public/configs/navidrome:/shared_data"
|
|
]
|
|
}
|
|
|
|
env {
|
|
ND_DATAFOLDER = "/local/data"
|
|
ND_CACHEFOLDER = "/shared_data/cache"
|
|
ND_CONFIGFILE= "/local/data/navidrome.toml"
|
|
|
|
# Important: LiteFS handles locking, but we still want WAL mode.
|
|
ND_DBPATH = "/data/navidrome.db?_busy_timeout=30000&_journal_mode=WAL&_foreign_keys=on&synchronous=NORMAL"
|
|
|
|
# Disable internal scheduling to prevent redundant scans on secondary nodes.
|
|
ND_SCANSCHEDULE = "0"
|
|
ND_SCANNER_FSWATCHER_ENABLED = "false"
|
|
|
|
ND_LOGLEVEL = "info"
|
|
ND_REVERSEPROXYWHITELIST = "0.0.0.0/0"
|
|
ND_REVERSEPROXYUSERHEADER = "X-Forwarded-User"
|
|
}
|
|
|
|
service {
|
|
name = "navidrome"
|
|
tags = [
|
|
"navidrome",
|
|
"web",
|
|
"traefik.enable=true",
|
|
"urlprefix-/navidrome",
|
|
"tools",
|
|
"traefik.http.routers.navidromelan.rule=Host(`navidrome.service.dc1.consul`)",
|
|
"traefik.http.routers.navidromewan.rule=Host(`m.fbleagh.duckdns.org`)",
|
|
"traefik.http.routers.navidromewan.middlewares=dex@consulcatalog",
|
|
"traefik.http.routers.navidromewan.tls=true",
|
|
]
|
|
port = "http" # This maps to the LiteFS proxy port defined in network block
|
|
|
|
check {
|
|
type = "http"
|
|
path = "/app" # LiteFS proxy passes this through
|
|
interval = "10s"
|
|
timeout = "2s"
|
|
}
|
|
}
|
|
|
|
resources {
|
|
cpu = 500
|
|
memory = 512
|
|
}
|
|
}
|
|
}
|
|
} |