Skip to content

Commit f1d5f68

Browse files
committed
feat: allow setting runners.docker.services. cattle-ops#489
1 parent 9d39138 commit f1d5f68

File tree

7 files changed

+63
-29
lines changed

7 files changed

+63
-29
lines changed

examples/runner-default/README.md

+30-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ This examples shows:
88
- You can log into the instance via SSM (Session Manager).
99
- Registration via GitLab token.
1010
- Auto scaling using `docker+machine` executor.
11-
- Addtional security groups that are allowed access to the runner agent
11+
- Additional security groups that are allowed access to the runner agent
12+
- Use of `runners.docker.services` to configure docker registry mirror
1213

1314
![runners-default](https://github.com/npalm/assets/raw/main/images/terraform-aws-gitlab-runner/runner-default.png)
1415

@@ -41,47 +42,47 @@ No output.
4142
<!-- BEGIN_TF_DOCS -->
4243
## Requirements
4344

44-
| Name | Version |
45-
|------|---------|
46-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1 |
47-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.7 |
48-
| <a name="requirement_local"></a> [local](#requirement\_local) | ~> 2 |
49-
| <a name="requirement_null"></a> [null](#requirement\_null) | ~> 3.0 |
50-
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
51-
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | ~> 3 |
45+
| Name | Version |
46+
| ------------------------------------------------------------------------- | ------- |
47+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1 |
48+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.7 |
49+
| <a name="requirement_local"></a> [local](#requirement\_local) | ~> 2 |
50+
| <a name="requirement_null"></a> [null](#requirement\_null) | ~> 3.0 |
51+
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
52+
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | ~> 3 |
5253

5354
## Providers
5455

55-
| Name | Version |
56-
|------|---------|
57-
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.7 |
58-
| <a name="provider_null"></a> [null](#provider\_null) | ~> 3.0 |
56+
| Name | Version |
57+
| ---------------------------------------------------- | ------- |
58+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.7 |
59+
| <a name="provider_null"></a> [null](#provider\_null) | ~> 3.0 |
5960

6061
## Modules
6162

62-
| Name | Source | Version |
63-
|------|--------|---------|
64-
| <a name="module_runner"></a> [runner](#module\_runner) | ../../ | n/a |
65-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | 2.70 |
63+
| Name | Source | Version |
64+
| ------------------------------------------------------ | ----------------------------- | ------- |
65+
| <a name="module_runner"></a> [runner](#module\_runner) | ../../ | n/a |
66+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | 2.70 |
6667

6768
## Resources
6869

69-
| Name | Type |
70-
|------|------|
71-
| [null_resource.cancel_spot_requests](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
70+
| Name | Type |
71+
| ------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
72+
| [null_resource.cancel_spot_requests](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
7273
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
73-
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
74+
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
7475

7576
## Inputs
7677

77-
| Name | Description | Type | Default | Required |
78-
|------|-------------|------|---------|:--------:|
79-
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | `"eu-west-1"` | no |
80-
| <a name="input_environment"></a> [environment](#input\_environment) | A name that identifies the environment, will used as prefix and for tagging. | `string` | `"runners-default"` | no |
81-
| <a name="input_gitlab_url"></a> [gitlab\_url](#input\_gitlab\_url) | URL of the gitlab instance to connect to. | `string` | `"https://gitlab.com"` | no |
82-
| <a name="input_registration_token"></a> [registration\_token](#input\_registration\_token) | n/a | `any` | n/a | yes |
83-
| <a name="input_runner_name"></a> [runner\_name](#input\_runner\_name) | Name of the runner, will be used in the runner config.toml | `string` | `"default-auto"` | no |
84-
| <a name="input_timezone"></a> [timezone](#input\_timezone) | Name of the timezone that the runner will be used in. | `string` | `"Europe/Amsterdam"` | no |
78+
| Name | Description | Type | Default | Required |
79+
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- | -------- | ---------------------- | :------: |
80+
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | `"eu-west-1"` | no |
81+
| <a name="input_environment"></a> [environment](#input\_environment) | A name that identifies the environment, will used as prefix and for tagging. | `string` | `"runners-default"` | no |
82+
| <a name="input_gitlab_url"></a> [gitlab\_url](#input\_gitlab\_url) | URL of the gitlab instance to connect to. | `string` | `"https://gitlab.com"` | no |
83+
| <a name="input_registration_token"></a> [registration\_token](#input\_registration\_token) | n/a | `any` | n/a | yes |
84+
| <a name="input_runner_name"></a> [runner\_name](#input\_runner\_name) | Name of the runner, will be used in the runner config.toml | `string` | `"default-auto"` | no |
85+
| <a name="input_timezone"></a> [timezone](#input\_timezone) | Name of the timezone that the runner will be used in. | `string` | `"Europe/Amsterdam"` | no |
8586

8687
## Outputs
8788

examples/runner-default/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ module "runner" {
9494
EOT
9595

9696
runners_post_build_script = "\"echo 'single line'\""
97+
98+
# Configure a docker service so that registry mirror is used in auto-devops jobs
99+
# See https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27171 and https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#the-service-in-the-gitlab-runner-configuration-file
100+
runners_docker_services = [{
101+
name = "docker:20.10.16-dind"
102+
alias = "docker"
103+
command = ["--registry-mirror", "https://mirror.gcr.io"]
104+
entrypoint = ["dockerd-entrypoint.sh"]
105+
}]
97106
}
98107

99108
resource "null_resource" "cancel_spot_requests" {

locals.tf

+5
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ locals {
2626
runners_machine_autoscaling = var.runners_machine_autoscaling
2727
}
2828
)
29+
30+
runners_docker_services = templatefile("${path.module}/template/runners_docker_services.tpl", {
31+
runners_docker_services = var.runners_docker_services
32+
}
33+
)
2934
}

main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ locals {
128128
runners_check_interval = var.runners_check_interval
129129
runners_volumes_tmpfs = join("\n", [for v in var.runners_volumes_tmpfs : format("\"%s\" = \"%s\"", v.volume, v.options)])
130130
runners_services_volumes_tmpfs = join("\n", [for v in var.runners_services_volumes_tmpfs : format("\"%s\" = \"%s\"", v.volume, v.options)])
131+
runners_docker_services = local.runners_docker_services
131132
bucket_name = local.bucket_name
132133
shared_cache = var.cache_shared
133134
sentry_dsn = var.sentry_dsn

template/runner-config.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ listen_address = "${prometheus_listen_address}"
2626
pull_policy = "${runners_pull_policy}"
2727
runtime = "${runners_docker_runtime}"
2828
helper_image = "${runners_helper_image}"
29+
${runners_docker_services}
2930
[runners.docker.tmpfs]
3031
${runners_volumes_tmpfs}
3132
[runners.docker.services_tmpfs]

template/runners_docker_services.tpl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%{ for config in runners_docker_services ~}
2+
[[runners.docker.services]]
3+
name = "${config.name}"
4+
alias = "${config.alias}"
5+
entrypoint = [${replace(format("\"%s\"", join("\",\"", config.entrypoint)), "/\"{2,}/", "\"")}]
6+
command = [${replace(format("\"%s\"", join("\",\"", config.command)), "/\"{2,}/", "\"")}]
7+
%{ endfor ~}

variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,16 @@ variable "runners_services_volumes_tmpfs" {
670670
default = []
671671
}
672672

673+
variable "runners_docker_services" {
674+
type = list(object({
675+
name = string
676+
alias = string
677+
entrypoint = list(string)
678+
command = list(string)
679+
}))
680+
default = []
681+
}
682+
673683
variable "kms_key_id" {
674684
description = "KMS key id to encrypted the CloudWatch logs. Ensure CloudWatch has access to the provided KMS key."
675685
type = string

0 commit comments

Comments
 (0)