# Continuwuity for Nomad

You can either pass the configuration as environment variables or mount a file containing the configuration from consul.
This given configuration assumes that you have a traefik reverse proxy running.

## Persistence
The database being a RockDB file, it is recommended to use a volume to persist the data.
The example below uses a volume, you need to configure the CSI driver on your cluster.

| Volume Name | Mount Path | Purpose |
|-------------|------------|---------|
| continuwuity-volume | `/var/lib/continuwuity` | Store the database |
| continuwuity-media-volume | `/var/lib/continuwuity/media` | Store uploaded media |

## Configuration
### Using environment variables
```hcl
job "continuwuity" {
  datacenters = ["dc1"]
  type      = "service"
  node_pool = "default"

  group "continuwuity" {
    count = 1

    network {
      port "http" {
        static = 6167
      }
    }

    service {
      name = "continuwuity"
      port = "http"
      tags = [
        "traefik.enable=true",
        "traefik.http.routers.continuwuity.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))",
        "traefik.http.routers.continuwuity.entrypoints=https",
        "traefik.http.routers.continuwuity.tls=true",
        "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt",
        "traefik.http.routers.continuwuity-http.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))",
        "traefik.http.routers.continuwuity-http.entrypoints=http",
        "traefik.http.routers.continuwuity-http.middlewares=continuwuity-redirect",
        "traefik.http.middlewares.continuwuity-redirect.redirectscheme.scheme=https",
        "traefik.http.middlewares.continuwuity-redirect.redirectscheme.permanent=true",
      ]
    }

    volume "continuwuity-volume" {
      type            = "csi"
      read_only       = false
      source          = "continuwuity-volume"
      attachment_mode = "file-system"
      access_mode     = "single-node-writer"
      per_alloc       = false
    }

    volume "continuwuity-media-volume" {
      type            = "csi"
      read_only       = false
      source          = "continuwuity-media-volume"
      attachment_mode = "file-system"
      access_mode     = "single-node-writer"
      per_alloc       = false

      mount_options {
        mount_flags = []
      }
    }

    task "continuwuity" {
      driver = "docker"

      env {
        CONTINUWUITY_SERVER_NAME        = "matrix.example.com"
        CONTINUWUITY_TRUSTED_SERVERS    = "[\"matrix.org\", \"mozilla.org\"]"
        CONTINUWUITY_ALLOW_REGISTRATION = false
        CONTINUWUITY_ADDRESS            = "0.0.0.0"
        CONTINUWUITY_PORT               = 6167
        CONTINUWUITY_DATABASE_PATH      = "/var/lib/continuwuity"
        CONTINUWUITY_WELL_KNOWN         = <<EOF
{
client=https://matrix.example.com,
server=matrix.example.com:443
}
EOF
      }

      config {
        image = "forgejo.ellis.link/continuwuation/continuwuity:latest"
        ports = ["http"]
      }

      volume_mount {
        volume      = "continuwuity-volume"
        destination = "/var/lib/continuwuity"
      }

      volume_mount {
        volume      = "continuwuity-media-volume"
        destination = "/var/lib/continuwuity/media"
      }
    }
  }
}
```

### Using consul
```hcl
...
      template {
        data = <<EOF
{{key "config/continuwuity"}}
EOF
        destination = "local/conduwuit.toml"
      }
...
```
