From 9580b0069c9583d92c49b1d46172e92d3518244a Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Sun, 2 Jun 2024 00:55:54 +0200 Subject: [PATCH] Add BirdBot & enable auto-restart --- services/birdbot/Taskfile.dist.yml | 11 ++++++++ services/birdbot/_common/main.tf | 37 +++++++++++++++++++++++++ services/birdbot/_common/vars.tf | 14 ++++++++++ services/birdbot/_common/versions.tf | 7 +++++ services/birdbot/boxnet/main.tf | 7 +++++ services/birdbot/boxnet/versions.tf | 7 +++++ services/birdbot/craft/main.tf | 7 +++++ services/birdbot/craft/versions.tf | 7 +++++ services/birdbot/kurzgesagt/main.tf | 7 +++++ services/birdbot/kurzgesagt/versions.tf | 7 +++++ services/consul/_common/main.tf | 2 ++ 11 files changed, 113 insertions(+) create mode 100644 services/birdbot/Taskfile.dist.yml create mode 100644 services/birdbot/_common/main.tf create mode 100644 services/birdbot/_common/vars.tf create mode 100644 services/birdbot/_common/versions.tf create mode 100644 services/birdbot/boxnet/main.tf create mode 100644 services/birdbot/boxnet/versions.tf create mode 100644 services/birdbot/craft/main.tf create mode 100644 services/birdbot/craft/versions.tf create mode 100644 services/birdbot/kurzgesagt/main.tf create mode 100644 services/birdbot/kurzgesagt/versions.tf diff --git a/services/birdbot/Taskfile.dist.yml b/services/birdbot/Taskfile.dist.yml new file mode 100644 index 0000000..d9a11fa --- /dev/null +++ b/services/birdbot/Taskfile.dist.yml @@ -0,0 +1,11 @@ +version: "3" + +vars: + TARGET: '{{.TARGET}}' + +includes: + tf: + vars: + SERVICE: "birdbot" + ENVIRONMENT: "{{.TARGET}}" + taskfile: ../../taskfiles/Taskfile_service.dist.yml diff --git a/services/birdbot/_common/main.tf b/services/birdbot/_common/main.tf new file mode 100644 index 0000000..4baa6e8 --- /dev/null +++ b/services/birdbot/_common/main.tf @@ -0,0 +1,37 @@ + + +data "vault_generic_secret" "discord" { + path = "secret/services/birdbot/discord" +} + +data "vault_generic_secret" "openai" { + path = "secret/services/birdbot/openai" +} + +resource "docker_container" "birdbot" { + image = "yeslayla/birdbot-chatgpt:${var.birdbot_version}" + name = "birdbot-${var.birdbot_name}" + + restart = "always" + + env = [ + "DISCORD_TOKEN=${data.vault_generic_secret.discord.data["token"]}", + "DISCORD_APPLICATION_ID=${data.vault_generic_secret.discord.data["app_id"]}", + "DISCORD_GUILD_ID=${var.discord_guild_id}", + "OPENAI_KEY=${data.vault_generic_secret.openai.data["token"]}" + ] + + mounts { + target = "/etc/birdbot" + source = "/volume1/homes/layla/birdbot/${var.birdbot_name}/etc" + read_only = false + type = "bind" + } + + mounts { + target = "/var/lib/birdbot" + source = "/volume1/homes/layla/birdbot/${var.birdbot_name}/var" + read_only = false + type = "bind" + } +} diff --git a/services/birdbot/_common/vars.tf b/services/birdbot/_common/vars.tf new file mode 100644 index 0000000..8249601 --- /dev/null +++ b/services/birdbot/_common/vars.tf @@ -0,0 +1,14 @@ +variable "birdbot_version" { + description = "BirdBot container tag" + type = string +} + +variable "birdbot_name" { + description = "BirdBot iteration name" + type = string +} + +variable "discord_guild_id" { + description = "Discord guild ID" + type = string +} \ No newline at end of file diff --git a/services/birdbot/_common/versions.tf b/services/birdbot/_common/versions.tf new file mode 100644 index 0000000..b433ffb --- /dev/null +++ b/services/birdbot/_common/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + } + } +} diff --git a/services/birdbot/boxnet/main.tf b/services/birdbot/boxnet/main.tf new file mode 100644 index 0000000..9c54fdc --- /dev/null +++ b/services/birdbot/boxnet/main.tf @@ -0,0 +1,7 @@ +module "birdbot" { + source = "../_common" + + birdbot_name = "boxnet" + birdbot_version = "v0.1.6" + discord_guild_id = "1088421016964956180" +} \ No newline at end of file diff --git a/services/birdbot/boxnet/versions.tf b/services/birdbot/boxnet/versions.tf new file mode 100644 index 0000000..b433ffb --- /dev/null +++ b/services/birdbot/boxnet/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + } + } +} diff --git a/services/birdbot/craft/main.tf b/services/birdbot/craft/main.tf new file mode 100644 index 0000000..0e20e77 --- /dev/null +++ b/services/birdbot/craft/main.tf @@ -0,0 +1,7 @@ +module "birdbot" { + source = "../_common" + + birdbot_name = "craft" + birdbot_version = "v0.1.6" + discord_guild_id = "1165727967800983684" +} diff --git a/services/birdbot/craft/versions.tf b/services/birdbot/craft/versions.tf new file mode 100644 index 0000000..b433ffb --- /dev/null +++ b/services/birdbot/craft/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + } + } +} diff --git a/services/birdbot/kurzgesagt/main.tf b/services/birdbot/kurzgesagt/main.tf new file mode 100644 index 0000000..fab3f05 --- /dev/null +++ b/services/birdbot/kurzgesagt/main.tf @@ -0,0 +1,7 @@ +module "birdbot" { + source = "../_common" + + birdbot_name = "kurzgesagt" + birdbot_version = "v0.1.6" + discord_guild_id = "1016797201931976714" +} diff --git a/services/birdbot/kurzgesagt/versions.tf b/services/birdbot/kurzgesagt/versions.tf new file mode 100644 index 0000000..b433ffb --- /dev/null +++ b/services/birdbot/kurzgesagt/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + } + } +} diff --git a/services/consul/_common/main.tf b/services/consul/_common/main.tf index d3a4c8d..f9fd2f6 100644 --- a/services/consul/_common/main.tf +++ b/services/consul/_common/main.tf @@ -17,6 +17,8 @@ resource "docker_container" "consul" { image = "${var.consul_image}:${var.consul_version}" name = var.container_name + restart = "always" + env = [] ports {