🏡 index : github.com/captn3m0/nebula.git

author Nemo <me@captnemo.in> 2018-07-28 20:03:43.0 +05:30:00
committer Nemo <me@captnemo.in> 2018-07-28 20:03:43.0 +05:30:00
commit
3322870a5397ddc8827e6423782018756e6c23f5 [patch]
tree
6a4c3e12a5657bd48e0596ec4bb288ae7eab18ea
parent
1f545f31179fe973084f9b2e2172b86c33bb89bd
download
3322870a5397ddc8827e6423782018756e6c23f5.tar.gz

Creates a generic docker-container module



Diff

 main.tf                   |  7 -------
 requestbin.tf             | 16 ++++++++++++++++
 variables.tf              |  5 +++++
 requestbin/README.md      |  6 ------
 requestbin/main.tf        | 25 -------------------------
 requestbin/variables.tf   |  9 ---------
 modules/container/main.tf | 23 +++++++++++++++++++++++
 modules/container/vars.tf | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 105 insertions(+), 47 deletions(-)

diff --git a/main.tf b/main.tf
index 90403e0..ff9e4fa 100644
--- a/main.tf
+++ a/main.tf
@@ -90,13 +90,6 @@
  postgres-network-id = "${module.db.postgres-network-id}"
}

module "requestbin" {

  source             = "requestbin"
  domain             = "requestbin.bb8.fun"
  traefik-labels     = "${var.traefik-common-labels}"
  traefik-network-id = "${module.docker.traefik-network-id}"
}

module "resilio" {

  source             = "resilio"
  domain             = "sync.bb8.fun"
diff --git a/requestbin.tf b/requestbin.tf
new file mode 100644
index 0000000..948a6ae 100644
--- /dev/null
+++ a/requestbin.tf
@@ -1,0 +1,16 @@
module "requestbin" {

  name   = "requestbin"
  source = "./modules/container"
  image  = "jankysolutions/requestbin:latest"

  labels = "${merge(

    var.traefik-common-labels, map(
      "traefik.port", 8000,
      "traefik.frontend.rule","Host:requestbin.${var.root-domain}"
  ))}"

  networks = "${list(module.docker.traefik-network-id)}"

  destroy_grace_seconds = 10
  must_run              = true
}
diff --git a/variables.tf b/variables.tf
index 835387d..93fde51 100644
--- a/variables.tf
+++ a/variables.tf
@@ -77,3 +77,8 @@
variable "monica-app-key" {}
variable "monica-hash-salt" {}
variable "monica-smtp-password" {}

variable "root-domain" {

  description = "root domain for most applications"
  default     = "bb8.fun"
}
diff --git a/requestbin/README.md b/requestbin/README.md
deleted file mode 100644
index 16e96a1..0000000 100644
--- a/requestbin/README.md
+++ /dev/null
@@ -1,6 +1,0 @@
# requestbin

- runscope has stopped hosting their public version of Requestb.in
- https://github.com/Runscope/requestbin#readme

There is no official image: https://github.com/Runscope/requestbin/issues/51 so using an unofficial image at https://hub.docker.com/r/jankysolutions/requestbin
diff --git a/requestbin/main.tf b/requestbin/main.tf
deleted file mode 100644
index ce8d936..0000000 100644
--- a/requestbin/main.tf
+++ /dev/null
@@ -1,25 +1,0 @@
data "docker_registry_image" "requestbin" {

  name = "jankysolutions/requestbin:latest"
}

resource "docker_image" "requestbin" {

  name          = "${data.docker_registry_image.requestbin.name}"
  pull_triggers = ["${data.docker_registry_image.requestbin.sha256_digest}"]
}

resource "docker_container" "requestbin" {

  name  = "requestbin"
  image = "${docker_image.requestbin.latest}"

  labels = "${merge(

    var.traefik-labels, map(
      "traefik.port", 8000,
      "traefik.frontend.rule","Host:${var.domain}"
  ))}"

  networks = ["${var.traefik-network-id}"]

  restart               = "unless-stopped"
  destroy_grace_seconds = 10
  must_run              = true
}
diff --git a/requestbin/variables.tf b/requestbin/variables.tf
deleted file mode 100644
index 500e0e6..0000000 100644
--- a/requestbin/variables.tf
+++ /dev/null
@@ -1,9 +1,0 @@
variable "domain" {

  type = "string"
}

variable "traefik-labels" {

  type = "map"
}

variable "traefik-network-id" {}
diff --git a/modules/container/main.tf b/modules/container/main.tf
new file mode 100644
index 0000000..b539842 100644
--- /dev/null
+++ a/modules/container/main.tf
@@ -1,0 +1,23 @@
data "docker_registry_image" "image" {

  name = "${var.image}"
}

resource "docker_image" "image" {

  name          = "${data.docker_registry_image.image.name}"
  pull_triggers = ["${data.docker_registry_image.image.sha256_digest}"]
}

resource "docker_container" "container" {

  name                  = "${var.name}"
  image                 = "${docker_image.image.latest}"
  ports                 = "${var.ports}"
  restart               = "${var.restart}"
  env                   = "${var.env}"
  command               = "${var.command}"
  entrypoint            = "${var.entrypoint}"
  user                  = "${var.user}"
  networks              = ["${var.networks}"]
  labels                = "${var.labels}"
  destroy_grace_seconds = "${var.destroy_grace_seconds}"
  must_run              = "${var.must_run}"
}
diff --git a/modules/container/vars.tf b/modules/container/vars.tf
new file mode 100644
index 0000000..edd44c4 100644
--- /dev/null
+++ a/modules/container/vars.tf
@@ -1,0 +1,61 @@
variable "image" {

  description = "docker image (with tag)"
}

variable "name" {

  description = "docker container name"
}

variable "ports" {

  description = "list of port mappings"
  type        = "list"
  default     = []
}

variable "networks" {

  description = "list of networks"
  type        = "list"
  default     = []
}

variable "restart" {

  description = "restart-policy"
  default     = "unless-stopped"
}

variable "must_run" {

  description = "If true, then the Docker container will be kept running. "
  default     = "true"
  type        = "string"
}

variable "user" {

  description = "user"
  default     = ""
}

variable "destroy_grace_seconds" {

  description = "Container will be destroyed after n seconds or on successful stop."
  default     = 10
  type        = "string"
}

variable "command" {

  description = "command"
  default     = []
}

variable "entrypoint" {

  description = "entrypoint"
  default     = []
}

variable "env" {

  description = "environment variables"
  default     = []
}

variable "labels" {

  description = "labels"
  default     = {}
}