From d7da3c95969c44a7d3a77185781f38ac7a52f74a Mon Sep 17 00:00:00 2001 From: kayma Date: Mon, 18 Oct 2021 20:52:52 +0200 Subject: [PATCH 1/5] Adding /certs/client and docker.sock to volumes for docker in docker --- template/runner-config.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/runner-config.tpl b/template/runner-config.tpl index 30aabd00f..be158d899 100644 --- a/template/runner-config.tpl +++ b/template/runner-config.tpl @@ -19,7 +19,7 @@ sentry_dsn = "${sentry_dsn}" image = "${runners_image}" privileged = ${runners_privileged} disable_cache = ${runners_disable_cache} - volumes = ["/cache"${runners_additional_volumes}] + volumes = ["/cache", "/certs/client", "/var/run/docker.sock:/var/run/docker.sock"${runners_additional_volumes}] shm_size = ${runners_shm_size} pull_policy = "${runners_pull_policy}" runtime = "${runners_docker_runtime}" From 5ca128720d758e07fe58fa427d9d8b316d8f4203 Mon Sep 17 00:00:00 2001 From: kayma Date: Thu, 28 Oct 2021 21:04:20 +0200 Subject: [PATCH 2/5] Make the volumes for docker-in-docker configurable --- locals.tf | 1 + template/runner-config.tpl | 2 +- variables.tf | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/locals.tf b/locals.tf index 8ff1f3654..c6ae31a6a 100644 --- a/locals.tf +++ b/locals.tf @@ -17,6 +17,7 @@ locals { name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"] name_iam_objects = var.overrides["name_iam_objects"] == "" ? local.tags["Name"] : var.overrides["name_iam_objects"] runners_additional_volumes = <<-EOT + %{~if var.runners_add_dind_volumes},"/certs/client", "/var/run/docker.sock:/var/run/docker.sock"%{endif} %{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~} EOT diff --git a/template/runner-config.tpl b/template/runner-config.tpl index be158d899..30aabd00f 100644 --- a/template/runner-config.tpl +++ b/template/runner-config.tpl @@ -19,7 +19,7 @@ sentry_dsn = "${sentry_dsn}" image = "${runners_image}" privileged = ${runners_privileged} disable_cache = ${runners_disable_cache} - volumes = ["/cache", "/certs/client", "/var/run/docker.sock:/var/run/docker.sock"${runners_additional_volumes}] + volumes = ["/cache"${runners_additional_volumes}] shm_size = ${runners_shm_size} pull_policy = "${runners_pull_policy}" runtime = "${runners_docker_runtime}" diff --git a/variables.tf b/variables.tf index f508e9c50..fa5f7b8ea 100644 --- a/variables.tf +++ b/variables.tf @@ -189,6 +189,12 @@ variable "runners_disable_cache" { default = false } +variable "runners_add_dind_volumes" { + description = "Add certificates and docker.sock to the volumes to support docker-in-docker (dind)" + type = bool + default = false +} + variable "runners_additional_volumes" { description = "Additional volumes that will be used in the runner config.toml, e.g Docker socket" type = list(any) From 0fa72ef67d51710c50bda2c151ddfd01fc5e337e Mon Sep 17 00:00:00 2001 From: kayma Date: Thu, 28 Oct 2021 21:08:17 +0200 Subject: [PATCH 3/5] Format code and add documentation --- README.md | 1 + variables.tf | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11359fa5c..a64b4c241 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,7 @@ terraform destroy | [runners\_additional\_volumes](#input\_runners\_additional\_volumes) | Additional volumes that will be used in the runner config.toml, e.g Docker socket | `list(any)` | `[]` | no | | [runners\_concurrent](#input\_runners\_concurrent) | Concurrent value for the runners, will be used in the runner config.toml. | `number` | `10` | no | | [runners\_disable\_cache](#input\_runners\_disable\_cache) | Runners will not use local cache, will be used in the runner config.toml | `bool` | `false` | no | +| [runners\_add\_dind\_volumes](#input\_runners\_add\_dind\_volumes) | Add certificates and docker.sock to the volumes to support docker-in-docker (dind) | `bool` | `false` | no | | [runners\_docker\_runtime](#input\_runners\_docker\_runtime) | docker runtime for runners, will be used in the runner config.toml | `string` | `""` | no | | [runners\_ebs\_optimized](#input\_runners\_ebs\_optimized) | Enable runners to be EBS-optimized. | `bool` | `true` | no | | [runners\_environment\_vars](#input\_runners\_environment\_vars) | Environment variables during build execution, e.g. KEY=Value, see runner-public example. Will be used in the runner config.toml | `list(string)` | `[]` | no | diff --git a/variables.tf b/variables.tf index fa5f7b8ea..dfe6d06c1 100644 --- a/variables.tf +++ b/variables.tf @@ -191,8 +191,8 @@ variable "runners_disable_cache" { variable "runners_add_dind_volumes" { description = "Add certificates and docker.sock to the volumes to support docker-in-docker (dind)" - type = bool - default = false + type = bool + default = false } variable "runners_additional_volumes" { From 3e0186f490676dae315c46cac67291f3e6c1ebe6 Mon Sep 17 00:00:00 2001 From: kayma Date: Sat, 30 Oct 2021 09:16:47 +0200 Subject: [PATCH 4/5] Remove whitespaces in `runners_additional_volumes` if Dind volumes are added --- locals.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/locals.tf b/locals.tf index c6ae31a6a..d1c3de7d7 100644 --- a/locals.tf +++ b/locals.tf @@ -17,8 +17,7 @@ locals { name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"] name_iam_objects = var.overrides["name_iam_objects"] == "" ? local.tags["Name"] : var.overrides["name_iam_objects"] runners_additional_volumes = <<-EOT - %{~if var.runners_add_dind_volumes},"/certs/client", "/var/run/docker.sock:/var/run/docker.sock"%{endif} - %{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~} + %{~if var.runners_add_dind_volumes~},"/certs/client", "/var/run/docker.sock:/var/run/docker.sock"%{endif~}%{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~} EOT runners_machine_autoscaling = templatefile("${path.module}/template/runners_machine_autoscaling.tpl", { From f95b6d22c63ef73aba2190010049c1c292eac4c4 Mon Sep 17 00:00:00 2001 From: kayma Date: Sat, 30 Oct 2021 14:24:31 +0200 Subject: [PATCH 5/5] Add /builds to the volume mount to have everything available inside docker --- locals.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locals.tf b/locals.tf index d1c3de7d7..f885ca343 100644 --- a/locals.tf +++ b/locals.tf @@ -17,7 +17,7 @@ locals { name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"] name_iam_objects = var.overrides["name_iam_objects"] == "" ? local.tags["Name"] : var.overrides["name_iam_objects"] runners_additional_volumes = <<-EOT - %{~if var.runners_add_dind_volumes~},"/certs/client", "/var/run/docker.sock:/var/run/docker.sock"%{endif~}%{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~} + %{~if var.runners_add_dind_volumes~},"/certs/client", "/builds", "/var/run/docker.sock:/var/run/docker.sock"%{endif~}%{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~} EOT runners_machine_autoscaling = templatefile("${path.module}/template/runners_machine_autoscaling.tpl", {