Make nextcloud bootstrap a prestart task

This commit is contained in:
IamTheFij 2022-03-11 19:30:25 -08:00
parent 73d96756bf
commit de2729c239
3 changed files with 36 additions and 96 deletions

View File

@ -1,85 +0,0 @@
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
}
}
}
}

View File

@ -70,6 +70,41 @@ job "nextcloud" {
} }
task "nextcloud-bootstrap" {
driver = "docker"
lifecycle {
hook = "prestart"
sidecar = false
}
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
}
}
task "main" { task "main" {
driver = "docker" driver = "docker"
@ -89,8 +124,6 @@ job "nextcloud" {
cpu = 50 cpu = 50
memory = 250 memory = 250
} }
} }
} }
} }

View File

@ -4,14 +4,6 @@ variable "base_hostname" {
default = "dev.homelab" default = "dev.homelab"
} }
resource "nomad_job" "nextcloud-bootstrap" {
hcl2 {
enabled = true
}
jobspec = file("${path.module}/nextcloud-bootstrap.nomad")
}
resource "nomad_job" "nextcloud" { resource "nomad_job" "nextcloud" {
hcl2 { hcl2 {
enabled = true enabled = true