Advertisement
Guest User

Untitled

a guest
Feb 8th, 2024
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 4.80 KB | Software | 0 0
  1. job "netbox" {
  2.  
  3.   datacenters = ["dc1"]
  4.   type = "service"
  5.  
  6.   group "app" {
  7.  
  8.     count = 1
  9.  
  10.     network {
  11.       port "http"        { to = 8080 }
  12.       port "psql"        { to = 5432 }
  13.       port "redis"       { to = 6379 }
  14.       port "redis-cache" { to = 6379 }
  15.     }
  16.  
  17.     # Service discovery
  18.     service {
  19.       name = "netbox"
  20.       port = "http"
  21.       provider = "consul"
  22.       check {
  23.         name = "netbox-app"
  24.         type = "http"
  25.         port = "http"
  26.         path = "/api"
  27.         interval = "60s"
  28.         timeout  = "3s"
  29.       }
  30.       check {
  31.         name = "netbox-postgres"
  32.         type = "tcp"
  33.         port = "psql"
  34.         interval = "10s"
  35.         timeout = "2s"
  36.       }
  37.       check {
  38.         name = "netbox-redis"
  39.         type = "tcp"
  40.         port = "redis"
  41.         interval = "10s"
  42.         timeout = "2s"
  43.       }
  44.       check {
  45.         name = "netbox-redis-cache"
  46.         type = "tcp"
  47.         port = "redis-cache"
  48.         interval = "10s"
  49.         timeout = "2s"
  50.       }
  51.     }
  52.  
  53.     # Netbox
  54.     task "netbox-app" {
  55.  
  56.       driver = "docker"
  57.       user = "unit:root"
  58.  
  59.       config {
  60.         image = "docker.io/netboxcommunity/netbox:v3.6-2.7.0"
  61.         ports = ["http"]
  62.         mount {
  63.           source = "/srv/containers/netbox/configuration"
  64.           target = "/etc/netbox/config"
  65.           type = "bind"
  66.           readonly = true
  67.         }
  68.         mount {
  69.           source = "/srv/containers/netbox/data/media"
  70.           target = "/opt/netbox/netbox/media"
  71.           type = "bind"
  72.           readonly = false
  73.         }
  74.         mount {
  75.           source = "/srv/containers/netbox/data/reports"
  76.           target = "/opt/netbox/netbox/reports"
  77.           type = "bind"
  78.           readonly = false
  79.         }
  80.         mount {
  81.           source = "/srv/containers/netbox/data/scripts"
  82.           target = "/opt/netbox/netbox/scripts"
  83.           type = "bind"
  84.           readonly = false
  85.         }
  86.       }
  87.  
  88.       template {
  89.         data = <<EOF
  90. DB_HOST={{ env "NOMAD_HOST_IP_psql" }}
  91. DB_PORT={{ env "NOMAD_HOST_PORT_psql" }}
  92. REDIS_CACHE_HOST={{ env "NOMAD_HOST_IP_redis-cache" }}
  93. REDIS_CACHE_PORT={{ env "NOMAD_HOST_PORT_redis_cache" }}
  94. REDIS_HOST={{ env "NOMAD_HOST_IP_redis" }}
  95. REDIS_PORT={{ env "NOMAD_HOST_PORT_redis" }}
  96. {{ key "nomad/prod/tasks/netbox" }}
  97. {{ with secret (print "kv/data/nomad/netbox") }}
  98. {{ range $k, $v := .Data.data }}
  99. {{ $k }}="{{ $v }}"{{ end }}
  100. {{ end }}
  101. EOF
  102.         destination = "local/env"
  103.         env = true
  104.       }
  105.       vault { policies = ["nomad-server"] }
  106.       resources {
  107.         cpu    = 2000
  108.         memory = 1024
  109.       }
  110.     }
  111.  
  112.     # PostgreSQL
  113.     task "netbox-postgres" {
  114.       driver = "docker"
  115.       config {
  116.         image = "docker.io/postgres:14-alpine"
  117.         mount {
  118.           type = "bind"
  119.           source = "/srv/containers/netbox/data/postgres/data"
  120.           target = "/var/lib/postgresql/data"
  121.           readonly = false
  122.         }
  123.         ports = ["psql"]
  124.       }
  125.       template {
  126.         data = <<EOF
  127. {{ key "nomad/netbox-postgres" }}
  128. {{ with secret "kv/data/nomad/netbox-postgres" }}
  129. POSTGRES_PASSWORD={{ .Data.data.POSTGRES_PASSWORD }}
  130. {{ end }}
  131. EOF
  132.         destination = "local/env"
  133.         env = true
  134.       }
  135.       vault {
  136.         policies = ["nomad-server"]
  137.       }
  138.       resources {
  139.         cpu    = 1000
  140.         memory = 1024
  141.       }
  142.     }
  143.  
  144.     # Netbox Redis
  145.     task "netbox-redis" {
  146.       driver = "docker"
  147.       config {
  148.         image = "docker.io/redis:6-alpine"
  149.         command = "redis-server"
  150.         args = ["--appendonly","yes","--requirepass","${REDIS_PASSWORD}",]
  151.         ports = ["redis"]
  152.         mount {
  153.           type = "bind"
  154.           source = "/srv/containers/netbox/data/redis/data"
  155.           target = "/data"
  156.           readonly = false
  157.         }
  158.       }
  159.       template {
  160.         data = <<EOF
  161. REDIS_PASSWORD={{ with secret "kv/nomad/netbox-redis" }}{{ .Data.data.REDIS_PASSWORD }}{{ end }}
  162. EOF
  163.         destination = "local/env"
  164.         env = true
  165.       }
  166.       vault {
  167.         policies = ["nomad-server"]
  168.       }
  169.     }
  170.  
  171.     # Netbox Redis Cache
  172.     task "netbox-redis-cache" {
  173.       driver = "docker"
  174.       config {
  175.         image = "docker.io/redis:6-alpine"
  176.         command = "redis-server"
  177.         args = ["--requirepass","${REDIS_PASSWORD}"]
  178.         mount {
  179.           type = "bind"
  180.           source = "/srv/containers/netbox/data/redis-cache/data"
  181.           target = "/data"
  182.           readonly = false
  183.         }
  184.         ports = ["redis-cache"]
  185.       }
  186.       template {
  187.         data = <<EOF
  188. REDIS_PASSWORD={{ with secret "kv/nomad/netbox-redis-cache" }}{{ .Data.data.REDIS_PASSWORD }}{{ end }}
  189. EOF
  190.         destination = "local/env"
  191.         env = true
  192.       }
  193.       vault {
  194.         policies = ["nomad-server"]
  195.       }
  196.     }
  197.   }
  198.  
  199. }
  200.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement