mirror of
https://github.com/luigieai/homelab.git
synced 2025-06-07 07:56:37 -03:00
Postgree + PgAdmin
This commit is contained in:
parent
35afbb644c
commit
ad5f57a0c4
13 changed files with 231 additions and 13 deletions
|
@ -1,8 +1,20 @@
|
|||
module "caddy" {
|
||||
source = "./modules/caddy"
|
||||
cloudflare_api_token = var.cloudflare_caddy_api_token
|
||||
endpoint = "192.168.15.92"
|
||||
endpoint = "192.168.15.92"
|
||||
providers = {
|
||||
nomad = nomad
|
||||
}
|
||||
}
|
||||
|
||||
module "postgree" {
|
||||
source = "./modules/postgreeSQL"
|
||||
postgree_user = var.postgree_user
|
||||
postgree_password = var.postgree_password
|
||||
pgadmin_user = var.pgadmin_user
|
||||
pgadmin_password = var.pgadmin_password
|
||||
providers = {
|
||||
nomad = nomad
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,13 @@ adguard.lab.marioverde.com.br {
|
|||
dns cloudflare "${cloudflare_api_token}"
|
||||
}
|
||||
}
|
||||
red.lab.marioverde.com.br {
|
||||
reverse_proxy "${endpoint}:8080"
|
||||
encode gzip zstd
|
||||
tls {
|
||||
dns cloudflare "${cloudflare_api_token}"
|
||||
}
|
||||
}
|
||||
#
|
||||
vault.lab.marioverde.com.br {
|
||||
reverse_proxy "https://${endpoint}:8200" {
|
||||
|
@ -25,3 +32,19 @@ vault.lab.marioverde.com.br {
|
|||
dns cloudflare "${cloudflare_api_token}"
|
||||
}
|
||||
}
|
||||
|
||||
pgadmin.lab.marioverde.com.br {
|
||||
reverse_proxy "${endpoint}:8090" {
|
||||
header_up Redirect off
|
||||
header_up Host {host}
|
||||
header_up X-Scheme {scheme}
|
||||
header_up X-Real-IP {remote}
|
||||
header_up X-Forwarded-Proto {scheme}
|
||||
}
|
||||
log {
|
||||
output stderr
|
||||
}
|
||||
tls {
|
||||
dns cloudflare "${cloudflare_api_token}"
|
||||
}
|
||||
}
|
|
@ -2,6 +2,6 @@ data "template_file" "caddyfile" {
|
|||
template = file("${path.module}/conf/Caddyfile")
|
||||
vars = {
|
||||
cloudflare_api_token = var.cloudflare_api_token
|
||||
endpoint = var.endpoint
|
||||
endpoint = var.endpoint
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
resource "nomad_job" "app" {
|
||||
jobspec = templatefile("${path.module}/conf/caddy.hcl", {
|
||||
caddyfile = data.template_file.caddyfile.rendered
|
||||
caddyfile = data.template_file.caddyfile.rendered
|
||||
NOMAD_ALLOC_DIR = "/alloc"
|
||||
})
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
nomad = {
|
||||
source = "hashicorp/nomad"
|
||||
source = "hashicorp/nomad"
|
||||
version = "2.0.0-rc.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ variable "cloudflare_api_token" {
|
|||
}
|
||||
|
||||
variable "endpoint" {
|
||||
type = string
|
||||
type = string
|
||||
description = "Nomad's server endpoint, the machine IP Address so we can reverse proxy our services."
|
||||
}
|
54
terraform/modules/postgreeSQL/conf/pgadmin.hcl
Normal file
54
terraform/modules/postgreeSQL/conf/pgadmin.hcl
Normal file
|
@ -0,0 +1,54 @@
|
|||
job "pg_admin" {
|
||||
datacenters = ["dc"]
|
||||
type = "service"
|
||||
|
||||
group "pg_admin" {
|
||||
count = 1
|
||||
|
||||
network {
|
||||
|
||||
port "pgadmin_port" {
|
||||
static = 8090
|
||||
to = 80
|
||||
}
|
||||
}
|
||||
|
||||
restart {
|
||||
attempts = 2
|
||||
interval = "5m"
|
||||
delay = "30s"
|
||||
mode = "delay"
|
||||
}
|
||||
|
||||
task "pg_admin" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "dpage/pgadmin4:latest"
|
||||
#network_mode = "host"
|
||||
volumes = [
|
||||
"${NOMAD_ALLOC_DIR}/pgadmin/servers.json:/servers.json",
|
||||
"${NOMAD_ALLOC_DIR}/servers.passfile:/root/.pgpass",
|
||||
]
|
||||
|
||||
ports = ["pgadmin_port"]
|
||||
}
|
||||
env {
|
||||
PGADMIN_DEFAULT_EMAIL="${PGADMIN_USER}"
|
||||
PGADMIN_DEFAULT_PASSWORD="${PGADMIN_PASSWORD}"
|
||||
}
|
||||
|
||||
service {
|
||||
name = "pgadmin"
|
||||
port = "pgadmin_port"
|
||||
provider = "nomad"
|
||||
}
|
||||
|
||||
logs {
|
||||
max_files = 5
|
||||
max_file_size = 15
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
65
terraform/modules/postgreeSQL/conf/postgree.hcl
Normal file
65
terraform/modules/postgreeSQL/conf/postgree.hcl
Normal file
|
@ -0,0 +1,65 @@
|
|||
job "postgres" {
|
||||
datacenters = ["dc"]
|
||||
type = "service"
|
||||
|
||||
group "postgres" {
|
||||
count = 1
|
||||
|
||||
network {
|
||||
|
||||
port "postgres_port" {
|
||||
static = 5432
|
||||
to = 5432
|
||||
}
|
||||
}
|
||||
|
||||
restart {
|
||||
attempts = 2
|
||||
interval = "5m"
|
||||
delay = "30s"
|
||||
mode = "delay"
|
||||
}
|
||||
|
||||
task "postgres" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "postgres:alpine"
|
||||
network_mode = "host"
|
||||
volumes = [
|
||||
"${NOMAD_ALLOC_DIR}/postgres/:/data/postgres",
|
||||
]
|
||||
|
||||
ports = ["postgres_port"]
|
||||
}
|
||||
env {
|
||||
POSTGRES_USER="${POSTGREE_USER}"
|
||||
POSTGRES_PASSWORD="${POSTGREE_PASSWORD}"
|
||||
PGDATA="/data/postgres"
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 1000
|
||||
memory = 1024
|
||||
}
|
||||
|
||||
service {
|
||||
name = "postgres"
|
||||
port = "postgres_port"
|
||||
provider = "nomad"
|
||||
check {
|
||||
name = "alive"
|
||||
type = "tcp"
|
||||
interval = "10s"
|
||||
timeout = "4s"
|
||||
}
|
||||
}
|
||||
|
||||
logs {
|
||||
max_files = 5
|
||||
max_file_size = 15
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
15
terraform/modules/postgreeSQL/job.tf
Normal file
15
terraform/modules/postgreeSQL/job.tf
Normal file
|
@ -0,0 +1,15 @@
|
|||
resource "nomad_job" "app_postgree" {
|
||||
jobspec = templatefile("${path.module}/conf/postgree.hcl", {
|
||||
NOMAD_ALLOC_DIR = "/alloc"
|
||||
POSTGREE_USER = var.postgree_user
|
||||
POSTGREE_PASSWORD = var.postgree_password
|
||||
})
|
||||
}
|
||||
|
||||
resource "nomad_job" "app_pgadmin" {
|
||||
jobspec = templatefile("${path.module}/conf/pgadmin.hcl", {
|
||||
NOMAD_ALLOC_DIR = "/alloc"
|
||||
PGADMIN_USER = var.pgadmin_user
|
||||
PGADMIN_PASSWORD = var.pgadmin_password
|
||||
})
|
||||
}
|
9
terraform/modules/postgreeSQL/providers..tf
Normal file
9
terraform/modules/postgreeSQL/providers..tf
Normal file
|
@ -0,0 +1,9 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
nomad = {
|
||||
source = "hashicorp/nomad"
|
||||
version = "2.0.0-rc.1"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.14"
|
||||
}
|
19
terraform/modules/postgreeSQL/variables.tf
Normal file
19
terraform/modules/postgreeSQL/variables.tf
Normal file
|
@ -0,0 +1,19 @@
|
|||
variable "postgree_user" {
|
||||
type = string
|
||||
description = "Postgree username"
|
||||
}
|
||||
|
||||
variable "postgree_password" {
|
||||
type = string
|
||||
description = "Poastgree password"
|
||||
}
|
||||
|
||||
variable "pgadmin_user" {
|
||||
type = string
|
||||
description = "PgAdmin username"
|
||||
}
|
||||
|
||||
variable "pgadmin_password" {
|
||||
type = string
|
||||
description = "PgAdmin password"
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
# Configure the Nomad provider.
|
||||
provider "nomad" {
|
||||
address = "http://192.168.15.92:4646"
|
||||
}
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
nomad = {
|
||||
source = "hashicorp/nomad"
|
||||
source = "hashicorp/nomad"
|
||||
version = "2.0.0-rc.1"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.14"
|
||||
}
|
||||
|
||||
# Configure the Nomad provider.
|
||||
provider "nomad" {
|
||||
address = "http://192.168.15.92:4646"
|
||||
}
|
||||
|
|
|
@ -2,3 +2,23 @@ variable "cloudflare_caddy_api_token" {
|
|||
type = string
|
||||
description = "API key to edit TLS in DNS zones in Cloudflare used by Caddy"
|
||||
}
|
||||
|
||||
variable "postgree_user" {
|
||||
type = string
|
||||
description = "Postgree username"
|
||||
}
|
||||
|
||||
variable "postgree_password" {
|
||||
type = string
|
||||
description = "Poastgree password"
|
||||
}
|
||||
|
||||
variable "pgadmin_user" {
|
||||
type = string
|
||||
description = "PgAdmin username"
|
||||
}
|
||||
|
||||
variable "pgadmin_password" {
|
||||
type = string
|
||||
description = "PgAdmin password"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue