refactor: simplify project structure
This commit is contained in:
7
modules/20-services-apps/watchtower/.env.example
Normal file
7
modules/20-services-apps/watchtower/.env.example
Normal file
@@ -0,0 +1,7 @@
|
||||
WATCHTOWER_CLEANUP=true
|
||||
WATCHTOWER_POLL_INTERVAL=86400
|
||||
WATCHTOWER_INCLUDE_STOPPED=false
|
||||
WATCHTOWER_REVIVE_STOPPED=false
|
||||
WATCHTOWER_ROLLING_RESTART=true
|
||||
WATCHTOWER_NOTIFICATIONS=shoutrrr
|
||||
WATCHTOWER_NOTIFICATION_URL=discord://token@webhook_id
|
||||
@@ -1,58 +1,48 @@
|
||||
// Watchtower module for automatic Docker container updates
|
||||
// This module configures a Watchtower container that monitors and updates other containers
|
||||
terraform {
|
||||
required_providers {
|
||||
dotenv = {
|
||||
source = "germanbrew/dotenv"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "image_tag" {
|
||||
description = "The tag for the Watchtower container image"
|
||||
type = string
|
||||
default = "latest"
|
||||
}
|
||||
|
||||
locals {
|
||||
container_name = var.container_name != "" ? var.container_name : "watchtower"
|
||||
container_name = "watchtower"
|
||||
image = "containrrr/watchtower"
|
||||
image_tag = var.image_tag != "" ? var.image_tag : "latest"
|
||||
|
||||
default_env_vars = {
|
||||
TZ = var.timezone
|
||||
WATCHTOWER_CLEANUP = var.cleanup
|
||||
WATCHTOWER_POLL_INTERVAL = var.poll_interval
|
||||
WATCHTOWER_INCLUDE_STOPPED = var.include_stopped
|
||||
WATCHTOWER_REVIVE_STOPPED = var.revive_stopped
|
||||
WATCHTOWER_ROLLING_RESTART = var.rolling_restart
|
||||
WATCHTOWER_NOTIFICATION_URL = var.notification_url
|
||||
WATCHTOWER_NOTIFICATIONS = var.enable_notifications ? "shoutrrr" : ""
|
||||
env_file = "${path.module}/.env"
|
||||
|
||||
env_vars = {
|
||||
WATCHTOWER_CLEANUP = provider::dotenv::get_by_key("WATCHTOWER_CLEANUP", local.env_file)
|
||||
WATCHTOWER_POLL_INTERVAL = provider::dotenv::get_by_key("WATCHTOWER_POLL_INTERVAL", local.env_file)
|
||||
WATCHTOWER_INCLUDE_STOPPED = false
|
||||
WATCHTOWER_REVIVE_STOPPED = false
|
||||
WATCHTOWER_ROLLING_RESTART = true
|
||||
WATCHTOWER_NOTIFICATION_URL = provider::dotenv::get_by_key("WATCHTOWER_NOTIFICATION_URL", local.env_file)
|
||||
WATCHTOWER_NOTIFICATIONS = provider::dotenv::get_by_key("WATCHTOWER_NOTIFICATIONS", local.env_file)
|
||||
}
|
||||
|
||||
// Merge default env vars with any additional ones provided
|
||||
env_vars = merge(local.default_env_vars, var.additional_env_vars)
|
||||
|
||||
// Default volumes for Docker socket access
|
||||
default_volumes = [
|
||||
|
||||
volumes = [
|
||||
{
|
||||
host_path = "/var/run/docker.sock"
|
||||
container_path = "/var/run/docker.sock"
|
||||
read_only = true
|
||||
}
|
||||
]
|
||||
|
||||
// Merge default volumes with any additional ones provided
|
||||
volumes = concat(local.default_volumes, var.additional_volumes)
|
||||
}
|
||||
|
||||
// Use the generic docker-service module to deploy Watchtower
|
||||
module "watchtower" {
|
||||
source = "../../10-services-generic/docker-service"
|
||||
|
||||
container_name = local.container_name
|
||||
image = "containrrr/watchtower"
|
||||
tag = local.image_tag
|
||||
|
||||
restart_policy = var.restart_policy
|
||||
network_mode = "bridge"
|
||||
|
||||
env_vars = local.env_vars
|
||||
volumes = local.volumes
|
||||
|
||||
labels = var.labels
|
||||
|
||||
// Watchtower doesn't typically expose ports but we'll include the option
|
||||
ports = var.ports
|
||||
|
||||
// Add monitoring label if enabled
|
||||
monitoring = var.monitoring
|
||||
|
||||
depends_on = []
|
||||
source = "../../10-services-generic/docker-service"
|
||||
container_name = local.container_name
|
||||
image = local.image
|
||||
tag = local.image_tag
|
||||
env_vars = local.env_vars
|
||||
volumes = local.volumes
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
output "container_name" {
|
||||
description = "Name of the created Watchtower container"
|
||||
value = module.watchtower.container_name
|
||||
}
|
||||
|
||||
output "container_id" {
|
||||
description = "ID of the created Watchtower container"
|
||||
value = module.watchtower.container_id
|
||||
}
|
||||
|
||||
output "image_id" {
|
||||
description = "ID of the Watchtower image used"
|
||||
value = module.watchtower.image_id
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
variable "container_name" {
|
||||
description = "Name for the Watchtower container"
|
||||
type = string
|
||||
default = "watchtower"
|
||||
}
|
||||
|
||||
variable "image_tag" {
|
||||
description = "The tag for the Watchtower container image"
|
||||
type = string
|
||||
default = "latest"
|
||||
}
|
||||
|
||||
variable "restart_policy" {
|
||||
description = "Restart policy for the container"
|
||||
type = string
|
||||
default = "unless-stopped"
|
||||
}
|
||||
|
||||
variable "timezone" {
|
||||
description = "Timezone for the container"
|
||||
type = string
|
||||
default = "Etc/UTC"
|
||||
}
|
||||
|
||||
variable "cleanup" {
|
||||
description = "Remove old images after updating"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "poll_interval" {
|
||||
description = "Poll interval (in seconds) for checking for updates"
|
||||
type = number
|
||||
default = 86400 // Default: check once per day
|
||||
}
|
||||
|
||||
variable "include_stopped" {
|
||||
description = "Include stopped containers when checking for updates"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "revive_stopped" {
|
||||
description = "Restart stopped containers after updating"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "rolling_restart" {
|
||||
description = "Restart containers one by one instead of all at once"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "notification_url" {
|
||||
description = "URL for sending update notifications via shoutrrr"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "enable_notifications" {
|
||||
description = "Enable shoutrrr notifications"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "additional_env_vars" {
|
||||
description = "Additional environment variables for Watchtower"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "additional_volumes" {
|
||||
description = "Additional volumes to mount in the container"
|
||||
type = list(object({
|
||||
host_path = string
|
||||
container_path = string
|
||||
read_only = bool
|
||||
}))
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "labels" {
|
||||
description = "Labels to set on the container"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "ports" {
|
||||
description = "Ports to expose (Watchtower typically doesn't need ports exposed)"
|
||||
type = list(object({
|
||||
internal = number
|
||||
external = number
|
||||
protocol = string
|
||||
}))
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "monitoring" {
|
||||
description = "Enable monitoring for the container"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
Reference in New Issue
Block a user