From e36c97184bc008fdd5ea1a9510cfa520df5b276f Mon Sep 17 00:00:00 2001 From: Matthias Kay Date: Thu, 9 Dec 2021 23:11:16 +0100 Subject: [PATCH] feat: Add variable for Docker registry mirror (#400) * Add variable for Docker registry mirror * Terraform docs added * Check correct variable --- README.md | 1 + locals.tf | 4 +++- main.tf | 2 +- variables.tf | 6 ++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96c1f18a7..38cc691d0 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,7 @@ terraform destroy | [runners\_gitlab\_url](#input\_runners\_gitlab\_url) | URL of the GitLab instance to connect to. | `string` | n/a | yes | | [runners\_helper\_image](#input\_runners\_helper\_image) | Overrides the default helper image used to clone repos and upload artifacts, will be used in the runner config.toml | `string` | `""` | no | | [runners\_iam\_instance\_profile\_name](#input\_runners\_iam\_instance\_profile\_name) | IAM instance profile name of the runners, will be used in the runner config.toml | `string` | `""` | no | +| [runners\_docker\_registry\_mirror](#input\_runners\_docker\_registry\_mirror) | The docker registry mirror to use to avoid rate limiting by hub.docker.com | `string` | `""` | no | | [runners\_idle\_count](#input\_runners\_idle\_count) | Idle count of the runners, will be used in the runner config.toml. | `number` | `0` | no | | [runners\_idle\_time](#input\_runners\_idle\_time) | Idle time of the runners, will be used in the runner config.toml. | `number` | `600` | no | | [runners\_image](#input\_runners\_image) | Image to run builds, will be used in the runner config.toml | `string` | `"docker:18.03.1-ce"` | no | diff --git a/locals.tf b/locals.tf index 2e0262eee..d563e9426 100644 --- a/locals.tf +++ b/locals.tf @@ -2,9 +2,11 @@ locals { // Convert list to a string separated and prepend by a comma docker_machine_options_string = format( ",%s", - join(",", formatlist("%q", var.docker_machine_options)), + join(",", formatlist("%q", concat(var.docker_machine_options, local.runners_docker_registry_mirror_option))), ) + runners_docker_registry_mirror_option = var.runners_docker_registry_mirror == "" ? [] : ["engine-registry-mirror=${var.runners_docker_registry_mirror}"] + // Ensure max builds is optional runners_max_builds_string = var.runners_max_builds == 0 ? "" : format("MaxBuilds = %d", var.runners_max_builds) diff --git a/main.tf b/main.tf index a83759ff7..32c4459ab 100644 --- a/main.tf +++ b/main.tf @@ -109,7 +109,7 @@ locals { runners_ebs_optimized = var.runners_ebs_optimized runners_instance_profile = aws_iam_instance_profile.docker_machine.name runners_additional_volumes = local.runners_additional_volumes - docker_machine_options = length(var.docker_machine_options) == 0 ? "" : local.docker_machine_options_string + docker_machine_options = length(local.docker_machine_options_string) == 1 ? "" : local.docker_machine_options_string runners_name = var.runners_name runners_tags = replace(var.overrides["name_docker_machine_runners"] == "" ? format( "Name,%s-docker-machine,%s,%s", diff --git a/variables.tf b/variables.tf index 3fc1e2b36..03f2bdbfa 100644 --- a/variables.tf +++ b/variables.tf @@ -248,6 +248,12 @@ variable "runners_iam_instance_profile_name" { default = "" } +variable "runners_docker_registry_mirror" { + description = "The docker registry mirror to use to avoid rate limiting by hub.docker.com" + type = string + default = "" +} + variable "runners_environment_vars" { description = "Environment variables during build execution, e.g. KEY=Value, see runner-public example. Will be used in the runner config.toml" type = list(string)