Browse Source

feat: Add Joplin Sync server

pull/2/head
Karan Sharma 8 months ago
parent
commit
99ef06ec82
  1. 2
      terraform/env.sample
  2. 8
      terraform/main.tf
  3. 9
      terraform/modules/caddy/conf/Caddyfile-internal
  4. 8
      terraform/modules/caddy/conf/Caddyfile-public
  5. 9
      terraform/modules/cloudflare/records.tf
  6. 105
      terraform/modules/joplin/conf/joplin.nomad
  7. 8
      terraform/modules/joplin/job.tf
  8. 3
      terraform/modules/joplin/variables.tf
  9. 1
      terraform/modules/shynet/conf/shynet.nomad
  10. 4
      terraform/variables.tf

2
terraform/env.sample

@ -3,4 +3,4 @@ CLOUDFLARE_API_TOKEN=
TF_VAR_cloudflare_caddy_api_token=
TF_VAR_shynet_postgresql_password=
TF_VAR_shynet_django_secret_key=
TF_VAR_nextcloud_postgresql_password=
TF_VAR_joplin_postgresql_password=

8
terraform/main.tf

@ -36,3 +36,11 @@ module "shynet" {
nomad = nomad
}
}
module "joplin" {
source = "./modules/joplin"
joplin_postgresql_password = var.joplin_postgresql_password
providers = {
nomad = nomad
}
}

9
terraform/modules/caddy/conf/Caddyfile-internal

@ -20,3 +20,12 @@ pihole.mrkaran.dev {
dns cloudflare "${cloudflare_api_token}"
}
}
joplin.mrkaran.dev {
{{ range service "joplin-web" }}
reverse_proxy {{ .Address }}:{{ .Port }}
{{ end }}
tls {
dns cloudflare "${cloudflare_api_token}"
}
}

8
terraform/modules/caddy/conf/Caddyfile-public

@ -7,11 +7,3 @@ shynet.mrkaran.dev {
}
}
nextcloud.mrkaran.dev {
{{ range service "nextcloud-web" }}
reverse_proxy {{ .Address }}:{{ .Port }}
{{ end }}
tls {
dns cloudflare "${cloudflare_api_token}"
}
}

9
terraform/modules/cloudflare/records.tf

@ -70,14 +70,13 @@ resource "cloudflare_record" "shynet" {
}
resource "cloudflare_record" "nextcloud" {
resource "cloudflare_record" "joplin" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "nextcloud"
name = "joplin"
type = "A"
ttl = "1"
proxied = "true"
# TODO: shift to floating IP
value = "68.183.87.4"
proxied = "false"
value = var.ips["floyd_tailscale"]
}

105
terraform/modules/joplin/conf/joplin.nomad

@ -0,0 +1,105 @@
job "joplin" {
datacenters = ["hydra"]
type = "service"
group "app" {
count = 1
network {
port "http" {
to = 22300
host_network = "tailscale"
}
port "db" {
to = 5432
host_network = "tailscale"
}
}
restart {
attempts = 2
interval = "2m"
delay = "30s"
mode = "fail"
}
task "web" {
driver = "docker"
service {
name = "joplin-web"
tags = ["joplin", "web"]
port = "http"
}
config {
image = "joplin/server:latest"
ports = ["http"]
}
env {
APP_BASE_URL = "https://joplin.mrkaran.dev"
DB_CLIENT = "pg"
POSTGRES_DATABASE = "joplin"
POSTGRES_USER = "joplin"
POSTGRES_PASSWORD = "${joplin_postgresql_password}"
}
template {
data = <<EOH
{{- with service "joplin-db" }}
{{- with index . 0 }}
POSTGRES_HOST="{{.Address}}"
POSTGRES_PORT="{{.Port}}"
{{- end }}
{{ end }}
EOH
destination = "secrets/file.env"
env = true
change_mode = "restart"
}
resources {
cpu = 200
memory = 100
}
}
task "db" {
driver = "docker"
service {
name = "joplin-db"
tags = ["joplin", "db"]
port = "db"
}
config {
image = "postgres:13"
# Bind the data directory to preserve config.
mount {
type = "bind"
target = "/var/lib/postgresql/data"
source = "/data/joplin/db/"
readonly = false
}
ports = ["db"]
}
env {
POSTGRES_DB = "joplin"
POSTGRES_USER = "joplin"
POSTGRES_PASSWORD = "${joplin_postgresql_password}"
}
# resources {
# cpu = 200
# memory = 200
# }
}
}
}

8
terraform/modules/joplin/job.tf

@ -0,0 +1,8 @@
resource "nomad_job" "app" {
jobspec = templatefile("${path.module}/conf/joplin.nomad", {
joplin_postgresql_password = var.joplin_postgresql_password
})
hcl2 {
enabled = true
}
}

3
terraform/modules/joplin/variables.tf

@ -0,0 +1,3 @@
variable "joplin_postgresql_password" {
type = string
}

1
terraform/modules/shynet/conf/shynet.nomad

@ -73,6 +73,7 @@ job "shynet" {
destination = "secrets/file.env"
env = true
change_mode = "restart"
}
resources {

4
terraform/variables.tf

@ -21,7 +21,7 @@ variable "shynet_django_secret_key" {
description = "Django secret key generated for Shynet"
}
variable "nextcloud_postgresql_password" {
variable "joplin_postgresql_password" {
type = string
description = "Password for nextcloud PostgreSQL server"
description = "Password for joplin PostgreSQL server"
}

Loading…
Cancel
Save