From b98b18e0f1b8cb566a3c71bea4104e6390abdada Mon Sep 17 00:00:00 2001 From: Luigi Oliveira Date: Tue, 29 Oct 2024 02:28:35 -0300 Subject: [PATCH] added postiz but I'm not using it anymore, not useful to me --- terraform/main.tf | 2 +- terraform/modules/caddy/conf/Caddyfile | 4 +- terraform/modules/postiz/conf/postiz.hcl | 77 ++++++++++++++++++++++++ terraform/modules/postiz/job.tf | 25 ++++++++ terraform/modules/postiz/providers..tf | 22 +++++++ terraform/modules/postiz/variables.tf | 34 +++++++++++ terraform/variables.tf | 15 +++++ 7 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 terraform/modules/postiz/conf/postiz.hcl create mode 100644 terraform/modules/postiz/job.tf create mode 100644 terraform/modules/postiz/providers..tf create mode 100644 terraform/modules/postiz/variables.tf diff --git a/terraform/main.tf b/terraform/main.tf index 978a57f..84857f7 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -55,4 +55,4 @@ module "twitchminer" { providers = { nomad = nomad } -} +} \ No newline at end of file diff --git a/terraform/modules/caddy/conf/Caddyfile b/terraform/modules/caddy/conf/Caddyfile index 0f0694d..2c82551 100644 --- a/terraform/modules/caddy/conf/Caddyfile +++ b/terraform/modules/caddy/conf/Caddyfile @@ -56,8 +56,8 @@ keycloak.lab.marioverde.com.br { } } -dockge.lab.marioverde.com.br { - reverse_proxy 192.168.15.46:5001 +postiz.lab.marioverde.com.br { + reverse_proxy * "${endpoint}:5000" tls { dns cloudflare "${cloudflare_api_token}" } diff --git a/terraform/modules/postiz/conf/postiz.hcl b/terraform/modules/postiz/conf/postiz.hcl new file mode 100644 index 0000000..b9d7857 --- /dev/null +++ b/terraform/modules/postiz/conf/postiz.hcl @@ -0,0 +1,77 @@ +job "postizz" { + datacenters = ["dc"] + type = "service" + + group "postizz" { + count = 1 + + update { + healthy_deadline = "15m" + progress_deadline = "20m" + } + + + network { + port "postizz" { + static = 5000 + to = 5000 + } + } + + restart { + attempts = 2 + interval = "5m" + delay = "30s" + mode = "delay" + } + + task "postizz" { + driver = "docker" + + config { + image = "ghcr.io/gitroomhq/postiz-app:amd64-1729871118" + ports = ["postizz"] + volumes = [ + "${NOMAD_ALLOC_DIR}/postiz-config:/config/", + "${NOMAD_ALLOC_DIR}/postiz-uploads:/uploads/" + ] + } + + resources { + memory_max = 3024 + } + + env { + MAIN_URL = "https://${URL}" + FRONTEND_URL = "https://${URL}" + NEXT_PUBLIC_BACKEND_URL = "https://${URL}/api" + JWT_SECRET = "${JWT_SECRET}" + DATABASE_URL = "postgresql://${POSTGREE_USER}:${POSTGREE_PASSWORD}@${POSTGREE_ENDPOINT}:5432/${POSTGREE_DATABASE}" + REDIS_URL = "redis://${REDIS_ENPOINT}" + BACKEND_INTERNAL_URL = "http://localhost:3000" + IS_GENERAL = "true" + STORAGE_PROVIDER = "local" + UPLOAD_DIRECTORY = "/uploads" + NEXT_PUBLIC_UPLOAD_DIRECTORY = "/uploads" + } + service { + name = "postizz" + port = "postizz" + provider = "nomad" + + check { + name = "postiz-check" + type = "tcp" + port = "postizz" + interval = "10s" + timeout = "3s" + } + } + + logs { + max_files = 5 + max_file_size = 15 + } + } + } +} \ No newline at end of file diff --git a/terraform/modules/postiz/job.tf b/terraform/modules/postiz/job.tf new file mode 100644 index 0000000..0589199 --- /dev/null +++ b/terraform/modules/postiz/job.tf @@ -0,0 +1,25 @@ +resource "postgresql_database" "postiz_database" { + name = var.postgree_database + owner = var.postgree_user + lc_collate = "C" + connection_limit = -1 + allow_connections = true + alter_object_ownership = true +} + +resource "nomad_job" "app" { + jobspec = templatefile("${path.module}/conf/postiz.hcl", { + NOMAD_ALLOC_DIR = "/alloc" + URL = var.url + POSTGREE_ENDPOINT = var.postgree_endpoint + POSTGREE_USER = var.postgree_user + POSTGREE_PASSWORD = var.postgree_password + POSTGREE_DATABASE = var.postgree_database + REDIS_ENPOINT = var.redis_endpoint + JWT_SECRET = var.jwt_secret + + depends_on = postgresql_database.postiz_database + }) +} + + diff --git a/terraform/modules/postiz/providers..tf b/terraform/modules/postiz/providers..tf new file mode 100644 index 0000000..eac63ea --- /dev/null +++ b/terraform/modules/postiz/providers..tf @@ -0,0 +1,22 @@ +terraform { + required_providers { + nomad = { + source = "hashicorp/nomad" + version = "2.0.0-rc.1" + } + postgresql = { + source = "cyrilgdn/postgresql" + version = "1.24.0" + } + } + required_version = ">= 0.14" +} + +provider "postgresql" { + host = var.postgree_endpoint + port = 5432 + username = var.postgree_user + password = var.postgree_password + sslmode = "disable" + connect_timeout = 15 +} \ No newline at end of file diff --git a/terraform/modules/postiz/variables.tf b/terraform/modules/postiz/variables.tf new file mode 100644 index 0000000..4876972 --- /dev/null +++ b/terraform/modules/postiz/variables.tf @@ -0,0 +1,34 @@ +variable "url" { + type = string + description = "Caddy url for potiz" +} + +variable "postgree_endpoint" { + type = string + description = "Postgree host for potiz" +} + +variable "postgree_user" { + type = string + description = "Postgree username for potiz" +} + +variable "postgree_password" { + type = string + description = "Postgree password for potiz" +} + +variable "postgree_database" { + type = string + description = "Postgree database for potiz" +} + +variable "redis_endpoint" { + type = string + description = "Redis host for potiz" +} + +variable "jwt_secret" { + type = string + description = "JWT token for potiz" +} \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index e7ecc72..8e5ca1b 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -46,4 +46,19 @@ variable "twitch_username" { variable "twitch_password" { type = string description = "Twitch password" +} + +variable "postiz_database" { + type = string + description = "postiz database name" +} + +variable "postiz_url" { + type = string + description = "postiz url on caddy" +} + +variable "postiz_jwt" { + type = string + description = "postiz jwt token" } \ No newline at end of file