Skip to main content

Deploy Grav CMS with Hashicorp Nomad

Shen Zhen, China

Grav is a Fast, Simple, and Flexible file-based Web-platform.

Docker-Compose

To test the container we can use docker compose up -d - make sure the /opt/grav/config dir exists and can be written to by your Docker user:

version: "3.9"

services:
  grav:
    image: linuxserver/grav:latest
    container_name: grav
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    volumes:
      - /opt/grav/config:/config
    ports:
      - 8080:80
    restart: unless-stopped

Nomad Job

In Nomad we first need to create the volumes on our host in /etc/nomad.d/client.hcl and then define it here:

volume "grav_config" {
    type      = "host"
    read_only = false
    source    = "grav_config"
}

It can then be mounted into the container:

volume_mount {
    volume      = "grav_config"
    destination = "/config"
    read_only   = false
}

Complete Job File

job "grav" {
  datacenters = ["dc1"]
    group "grav" {
        
        network {
            mode = "host"
            port "http" {
                to = 80
            }
        }

        update {
            max_parallel = 1
            min_healthy_time  = "10s"
            healthy_deadline  = "5m"
            progress_deadline = "10m"
            auto_revert = true
            auto_promote = true
            canary = 1
        }

        restart {
            attempts = 10
            interval = "5m"
            delay    = "25s"
            mode     = "delay"
        }

        volume "grav_config" {
            type      = "host"
            read_only = false
            source    = "grav_config"
        }

        service {
            name = "grav-frontend"
            port = "http"
            tags = [
                "frontend"
            ]

            check {
                name     = "HTTP Health"
                path     = "/"
                type     = "http"
                protocol = "http"
                interval = "10s"
                timeout  = "2s"
            }
        }

        task "grav-frontend" {
            driver = "docker"

            volume_mount {
                volume      = "grav_config"
                destination = "/config"
                read_only   = false
            }

            config {
                image = "linuxserver/grav:latest"
                ports = ["http"]
                network_mode = "host"
                force_pull = false
            }

            env {
              PUID= "1000"
              PGID= "1000"
              TZ = "America/New_York"
            }

            resources {
                cpu    = 100
                memory = 300
            }
        }
    }
}

Deploy the Grav CMS with Hashicorp Nomad

Deploy the Grav CMS with Hashicorp Nomad