homelab-nomad/nextcloud/nextcloud.nomad

181 lines
3.5 KiB
Plaintext
Raw Normal View History

2022-02-17 22:03:50 +00:00
variable "nextcloud_db" {
type = string
default = "nextcloud"
}
variable "nextcloud_user" {
type = string
default = "nextcloud"
}
variable "nextcloud_pass" {
type = string
default = "nextcloud"
}
2022-04-15 19:11:41 +00:00
variable "backup_config" {
type = string
description = "HCL config for Restic Scheduler jobs"
}
2022-02-17 22:03:50 +00:00
job "nextcloud" {
datacenters = ["dc1"]
type = "service"
group "nextcloud" {
count = 1
network {
mode = "bridge"
port "web" {
host_network = "loopback"
to = 80
}
}
volume "nextcloud-data" {
type = "host"
read_only = false
source = "nextcloud-data"
}
2022-02-17 22:03:50 +00:00
service {
2022-03-14 22:58:03 +00:00
name = "nextcloud"
2022-02-17 22:03:50 +00:00
port = "web"
connect {
sidecar_service {
proxy {
local_service_port = 80
upstreams {
destination_name = "mysql-server"
local_bind_port = 6060
}
config {
protocol = "tcp"
}
}
}
sidecar_task {
resources {
cpu = 50
memory = 50
}
}
}
tags = [
"traefik.enable=true",
"traefik.http.routers.nextcloud.entryPoints=websecure",
2022-02-17 22:03:50 +00:00
]
}
2022-04-13 21:01:14 +00:00
task "nextcloud-bootstrap" {
driver = "docker"
2022-04-13 21:01:14 +00:00
lifecycle {
hook = "prestart"
sidecar = false
2022-04-13 21:01:14 +00:00
}
config {
image = "mysql:8"
args = [
"/bin/bash",
"-c",
"/usr/bin/mysql -h${NOMAD_UPSTREAM_IP_mysql_server} -P${NOMAD_UPSTREAM_PORT_mysql_server} -uroot -psupersecretpassword < /bootstrap.sql",
]
2022-04-15 19:11:41 +00:00
mount {
type = "bind"
source = "local/bootstrap.sql"
target = "/bootstrap.sql"
}
}
template {
data = <<EOF
CREATE DATABASE IF NOT EXISTS `${var.nextcloud_db}`;
CREATE USER IF NOT EXISTS '${var.nextcloud_user}'@'%' IDENTIFIED BY '${var.nextcloud_pass}';
GRANT ALL ON `${var.nextcloud_db}`.* to '${var.nextcloud_user}'@'%';
EOF
destination = "local/bootstrap.sql"
}
resources {
cpu = 50
memory = 50
}
}
2022-02-17 22:03:50 +00:00
task "main" {
driver = "docker"
volume_mount {
volume = "nextcloud-data"
destination = "/var/www/html"
read_only = false
}
2022-04-13 21:01:14 +00:00
2022-02-17 22:03:50 +00:00
config {
image = "nextcloud"
ports = ["web"]
}
env = {
"MYSQL_HOST" = "${NOMAD_UPSTREAM_ADDR_mysql_server}"
"MYSQL_DATABASE" = "${var.nextcloud_db}"
"MYSQL_USER" = "${var.nextcloud_user}"
"MYSQL_PASSWORD" = "${var.nextcloud_pass}"
}
resources {
cpu = 50
memory = 250
}
}
2022-04-15 19:11:41 +00:00
task "backup" {
driver = "docker"
volume_mount {
volume = "nextcloud-data"
destination = "/data"
read_only = true
}
config {
image = "iamthefij/resticscheduler"
args = ["/jobs/nextcloud.hcl"]
mount {
type = "bind"
target = "/jobs"
source = "jobs"
}
}
env = {
"MYSQL_HOST" = "${NOMAD_UPSTREAM_IP_mysql_server}"
"MYSQL_PORT" = "${NOMAD_UPSTREAM_PORT_mysql_server}"
"MYSQL_DATABASE" = "${var.nextcloud_db}"
"MYSQL_USER" = "${var.nextcloud_user}"
"MYSQL_PASSWORD" = "${var.nextcloud_pass}"
}
template {
data = var.backup_config
destination = "jobs/nextcloud.hcl"
}
resources {
cpu = 50
memory = 256
}
}
2022-02-17 22:03:50 +00:00
}
2022-03-13 17:13:19 +00:00
}