Add nextcloud

This commit is contained in:
IamTheFij 2022-02-17 14:03:50 -08:00
parent 9f49777f1b
commit daa5a14f4e
2 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,85 @@
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
variable "nextcloud_db" {
type = string
default = "nextcloud"
}
variable "nextcloud_user" {
type = string
default = "nextcloud"
}
variable "nextcloud_pass" {
type = string
default = "nextcloud"
}
job "nextcloud-bootstrap" {
datacenters = ["dc1"]
type = "batch"
group "nextcloud-bootstrap" {
network {
mode = "bridge"
}
service {
connect {
sidecar_service {
proxy {
upstreams {
destination_name = "mysql-server"
# TODO: how do I get these to not bind to the host eth0 address
local_bind_port = 6061
}
config {
protocol = "tcp"
}
}
}
sidecar_task {
resources {
cpu = 50
memory = 50
}
}
}
}
task "nextcloud-bootstrap" {
driver = "docker"
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",
]
volumes = [
"local/bootstrap.sql:/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
}
}
}
}

96
nomad/nextcloud.nomad Normal file
View File

@ -0,0 +1,96 @@
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
variable "nextcloud_db" {
type = string
default = "nextcloud"
}
variable "nextcloud_user" {
type = string
default = "nextcloud"
}
variable "nextcloud_pass" {
type = string
default = "nextcloud"
}
job "nextcloud" {
datacenters = ["dc1"]
type = "service"
group "nextcloud" {
count = 1
network {
mode = "bridge"
port "web" {
host_network = "loopback"
to = 80
}
}
service {
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=web,websecure",
"traefik.http.routers.nextcloud.rule=Host(`nextcloud.${var.base_hostname}`)",
"traefik.http.routers.nextcloud.tls=true",
]
}
task "main" {
driver = "docker"
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
}
}
}
}