From 70e46005a7a49580ef66b08939fd7ba60335a493 Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Fri, 28 Jun 2024 12:43:20 +0200 Subject: [PATCH] Ubiquity and printers included --- docker.tf | 20 +++---- minio.tf | 8 +-- modules/minio/inputs.tf | 12 ++--- modules/minio/minio.tf | 12 ++--- modules/minio/outputs.tf | 4 +- output.tf | 2 +- printers.tf | 53 ++++++++++++++---- ubiquity.tf | 113 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 187 insertions(+), 37 deletions(-) create mode 100644 ubiquity.tf diff --git a/docker.tf b/docker.tf index 7b10ff0..84c692c 100644 --- a/docker.tf +++ b/docker.tf @@ -1,4 +1,4 @@ -provider "ssh" { +/*provider "ssh" { server = { host = "california.ti" port = 22 @@ -10,22 +10,24 @@ provider "ssh" { } } } -#data "ssh_tunnel" "docker" { -# connection_name = "docker_socket_tunnel_california" -# remote = { -# socket = "/var/run/docker.sock" -# } -#} +data "ssh_tunnel" "docker" { + connection_name = "docker_socket_tunnel_california" + remote = { + socket = "/var/run/docker.sock" + } +} +*/ + provider "docker" { host = "ssh://california.ti" } provider "docker" { alias = "printi" - host = "ssh://prin.ti" + host = "ssh://prin.ti" } provider "docker" { alias = "unifi" - host = "ssh://unifi.ti" + host = "ssh://unifi.ti" } diff --git a/minio.tf b/minio.tf index 18cce2b..fa14b94 100644 --- a/minio.tf +++ b/minio.tf @@ -1,7 +1,7 @@ module "minio" { - source = "./modules/minio" - domain = "s3.california.ti" - network = docker_network.loadbalancer - storage_path = "/media/storage/minio" + source = "./modules/minio" + domain = "s3.california.ti" + network = docker_network.loadbalancer + storage_path = "/media/storage/minio" admin_username = "techinc" } diff --git a/modules/minio/inputs.tf b/modules/minio/inputs.tf index 244ef5a..fb42ef3 100644 --- a/modules/minio/inputs.tf +++ b/modules/minio/inputs.tf @@ -1,20 +1,20 @@ variable "admin_username" { - type = string + type = string description = "The username of the admin user" - default = "admin" + default = "admin" } variable "domain" { - type = string + type = string description = "The domain name of the minio instance" } variable "network" { type = object({ - id = string + id = string name = string }) description = "The network to attach the minio service to" } variable "storage_path" { - type = string - description = "The path to the storage directory to use" + type = string + description = "The path to the storage directory to use" } diff --git a/modules/minio/minio.tf b/modules/minio/minio.tf index c90a21e..78a8343 100644 --- a/modules/minio/minio.tf +++ b/modules/minio/minio.tf @@ -1,5 +1,5 @@ data "docker_registry_image" "minio" { - name = "quay.io/minio/minio:latest" + name = "quay.io/minio/minio:latest" } resource "random_password" "minio_password" { @@ -13,7 +13,7 @@ locals { } resource "docker_service" "minio" { - name = "minio" + name = "minio" task_spec { container_spec { image = "${data.docker_registry_image.minio.name}@${data.docker_registry_image.minio.sha256_digest}" @@ -52,8 +52,8 @@ resource "docker_service" "minio" { } module "minio_nginx_config" { - source = "git::https://code.techinc.nl/grey/terraform-nginx.git//nginx-site-available" - hostname = var.domain + source = "git::https://code.techinc.nl/grey/terraform-nginx.git//nginx-site-available" + hostname = var.domain //certificate = acme_certificate.ooo_grey["s3"] service_name = "minio_s3" upstream_host = "${docker_service.minio.name}:9000" @@ -65,6 +65,6 @@ module "minio_nginx_config" { } ] extra_locations = file("${path.module}/minio_nginx_extra.conf") - allow_non_ssl = true - allow_ssl = false + allow_non_ssl = true + allow_ssl = false } diff --git a/modules/minio/outputs.tf b/modules/minio/outputs.tf index 411369f..90c8818 100644 --- a/modules/minio/outputs.tf +++ b/modules/minio/outputs.tf @@ -1,7 +1,7 @@ output "auth" { value = { - user = docker_service.minio.task_spec[0].container_spec[0].env.MINIO_ROOT_USER - password = nonsensitive(docker_service.minio.task_spec[0].container_spec[0].env.MINIO_ROOT_PASSWORD) + user = var.admin_username + password = nonsensitive(random_password.minio_password.result) } } output "domain" { diff --git a/output.tf b/output.tf index f0fe030..64e1b82 100644 --- a/output.tf +++ b/output.tf @@ -1,4 +1,4 @@ output "minio" { -value = module.minio + value = module.minio } diff --git a/printers.tf b/printers.tf index b6453f2..eec8f63 100644 --- a/printers.tf +++ b/printers.tf @@ -1,14 +1,49 @@ resource "docker_image" "octoprint" { - provider = "docker.printi" - name = "octoprint" + provider = docker.printi + name = "octoprint" build { context = "${path.module}/printers" - target = "octoprint-mjpg-streamer" + target = "octoprint-mjpg-streamer" + tag = ["ti-octoprint"] } } -/* -resource "docker_container" "corexy" { - provider = "docker.printi" - image = docker_image.octoprint.name - name = "corexy" -}*/ \ No newline at end of file + +resource "docker_volume" "ender5plus" { + provider = docker.printi + name = "ender5plus_config" +} + +resource "docker_service" "ender5plus" { + provider = docker.printi + name = "ender5plus" + task_spec { + container_spec { + image = docker_image.octoprint.name + mounts { + target = "/octoprint" + source = docker_volume.ender5plus.name + type = "volume" + } + mounts { + target = "/dev/ttyACM0" + source = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A602AFFK-if00-port0" + type = "bind" + } + env = { + #ENABLE_MJPG_STREAMER = "true" + } + } + restart_policy { + condition = "any" + delay = "20s" + window = "0s" + } + } + endpoint_spec { + ports { + target_port = 80 + published_port = 3000 + publish_mode = "ingress" + } + } +} \ No newline at end of file diff --git a/ubiquity.tf b/ubiquity.tf new file mode 100644 index 0000000..c4aef30 --- /dev/null +++ b/ubiquity.tf @@ -0,0 +1,113 @@ +data "docker_registry_image" "unifi_controller" { + name = "jacobalberty/unifi" +} +resource "docker_service" "unifi_controller" { + name = "unifi_controller" + provider = docker.unifi + task_spec { + container_spec { + image = "${data.docker_registry_image.unifi_controller.name}@${data.docker_registry_image.unifi_controller.sha256_digest}" + env = { + TZ = "Europe/Amsterdam" + } + mounts { + target = "/unifi" + source = "/home/techinc/unifi" + type = "bind" + } + } + restart_policy { + condition = "any" + delay = "0s" + window = "0s" + } + } + endpoint_spec { + ports { + target_port = 8443 + published_port = 443 + publish_mode = "ingress" + } + ports { + target_port = 8443 + published_port = 8443 + publish_mode = "ingress" + } + ports { + target_port = 3478 + published_port = 3478 + publish_mode = "ingress" + protocol = "udp" + } + ports { + target_port = 10001 + published_port = 10001 + publish_mode = "ingress" + protocol = "udp" + } + ports { + target_port = 8080 + published_port = 8080 + publish_mode = "ingress" + } + } +} + +data "docker_registry_image" "http2https" { + name = "articulate/http-to-https" +} +resource "docker_service" "unifi_http2https" { + name = "http2https" + provider = docker.unifi + + task_spec { + container_spec { + image = "${data.docker_registry_image.http2https.name}@${data.docker_registry_image.http2https.sha256_digest}" + } + restart_policy { + condition = "any" + delay = "0s" + window = "0s" + } + } + endpoint_spec { + ports { + target_port = 80 + published_port = 80 + publish_mode = "ingress" + } + } +} + +data "docker_registry_image" "iperf" { + name = "loganmarchione/docker-iperf3:latest" + provider = docker.unifi +} +resource "docker_service" "unifi_iperf" { + name = "iperf" + provider = docker.unifi + task_spec { + container_spec { + image = "${data.docker_registry_image.iperf.name}@${data.docker_registry_image.iperf.sha256_digest}" + } + restart_policy { + condition = "any" + delay = "0s" + window = "0s" + } + } + endpoint_spec { + ports { + target_port = 5201 + published_port = 5201 + publish_mode = "ingress" + protocol = "tcp" + } + ports { + target_port = 5201 + published_port = 5201 + publish_mode = "ingress" + protocol = "udp" + } + } +} \ No newline at end of file