Skip to content

Commit b8a8c1c

Browse files
kayman-mktmeijnnpalm
authored
feat!: restructure module variables (#723)
## Description Restructures all input variables of the agent and executor. Closes #467 (add network_mode to docker.runner config) Closes #513 (wait_for_services_timeout paramete) Closes #819 ## Migrations required YES. Check the script in `/migrations/migrate-to-7-0-0.sh`. --------- Co-authored-by: Tyrone Meijn <[email protected]> Co-authored-by: Niek Palm <[email protected]>
1 parent b8fdc06 commit b8a8c1c

File tree

31 files changed

+1797
-1316
lines changed

31 files changed

+1797
-1316
lines changed

.cspell.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"version": "0.2",
33
"language": "en",
44
"words": [
5+
"alltrue",
56
"amazonec",
67
"amannn",
8+
"amazonec",
79
"anytrue",
810
"aquasecurity",
911
"awscli",
@@ -16,14 +18,16 @@
1618
"codeowners",
1719
"companys",
1820
"concat",
21+
"cpu",
22+
"cpus",
23+
"cpuset",
1924
"devskim",
2025
"dind",
2126
"endfor",
27+
"filesha",
2228
"formatlist",
2329
"gitter",
24-
"godotenv",
25-
"golangci",
26-
"gruntwork",
30+
"glrunners",
2731
"instancelifecycle",
2832
"kics",
2933
"joho",
@@ -38,24 +42,31 @@
3842
"pylint",
3943
"pylintrc",
4044
"pyright",
45+
"setsubtract",
4146
"shuf",
4247
"signoff",
4348
"signum",
4449
"stretchr",
50+
"subkey",
4551
"substr",
52+
"sysctl",
53+
"sysctls",
4654
"templatefile",
4755
"terrascan",
4856
"terratest",
4957
"tfenv",
5058
"tflint",
5159
"tftpl",
5260
"tfsec",
61+
"tftpl",
5362
"tfvars",
5463
"tmpfs",
5564
"trivy",
5665
"typecheck",
5766
"userdata",
58-
"xanzy"
67+
"userns",
68+
"xanzy",
69+
"xvda"
5970
],
6071
"flagWords": []
6172
}

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
fail-fast: false
3333
matrix:
34-
terraform: [ 1.0.11, 1.3.9, latest ]
34+
terraform: [ 1.3.9, latest ]
3535
example:
3636
[
3737
"runner-default",
@@ -137,7 +137,8 @@ jobs:
137137
run: tflint --init
138138

139139
- name: Run TFLint
140-
run: tflint --var 'enable_kms=true'
140+
# assign necessary variables to avoid errors
141+
run: "tflint --var 'enable_managed_kms_key=true' --var='runner_instance={\"name_prefix\": \"a\", \"name\": \"b\"}'"
141142

142143
tfsec:
143144
name: tfsec PR commenter

.mega-linter.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ DISABLE_LINTERS:
44
- TERRAFORM_TFLINT
55
# Super slow linter, but useful. We disable it here and run it in parallel to Megalinter saves some minutes.
66
- REPOSITORY_KICS
7+
# has issues with the Terraform code `optional` variable definitions: https://github.com/tenable/terrascan/issues/1532
8+
- TERRAFORM_TERRASCAN
79
# Nice linter to report CVEs and other cool stuff. But it reports problems with the Terraform code which can't be disabled by
810
# configuration.
911
- REPOSITORY_TRIVY

.terraform-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.8
1+
1.3.0

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<!-- First line should be a H1: Badges on top please! -->
2-
<!-- markdownlint-disable MD041 -->
2+
<!-- markdownlint-disable MD041/first-line-heading/first-line-h1 -->
33
[![Terraform registry](https://img.shields.io/github/v/release/cattle-ops/terraform-aws-gitlab-runner?label=Terraform%20Registry)](https://registry.terraform.io/modules/cattle-ops/gitlab-runner/aws/)
44
[![Gitter](https://badges.gitter.im/terraform-aws-gitlab-runner/Lobby.svg)](https://gitter.im/terraform-aws-gitlab-runner/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
55
[![Actions](https://github.com/cattle-ops/terraform-aws-gitlab-runner/workflows/CI/badge.svg)](https://github.com/cattle-ops/terraform-aws-gitlab-runner/actions)
6+
<!-- markdownlint-enable MD041/first-line-heading/first-line-h1 -->
67

78
# Terraform module for GitLab auto scaling runners on AWS spot instances <!-- omit in toc -->
89

@@ -385,13 +386,12 @@ module "runner" {
385386

386387
Since spot instances can be taken over by AWS depending on the instance type and AZ you are using, you may want multiple instances
387388
types in multiple AZs. This is where spot fleets come in, when there is no capacity on one instance type and one AZ, AWS will take
388-
the next instance type and so on. This update has been possible since the [fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2)
389-
of docker-machine supports spot fleets.
389+
the next instance type and so on. This update has been possible since the
390+
[fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2) of docker-machine supports spot fleets.
390391

391392
We have seen that the [fork](https://gitlab.com/cki-project/docker-machine/-/tree/v0.16.2-gitlab.19-cki.2) of docker-machine this
392-
module is using consume more RAM using spot fleets.
393-
For comparison, if you launch 50 machines in the same time, it consumes ~1.2GB of RAM. In our case, we had to change the
394-
`instance_type` of the runner from `t3.micro` to `t3.small`.
393+
module is using consume more RAM using spot fleets. For comparison, if you launch 50 machines in the same time, it consumes
394+
~1.2GB of RAM. In our case, we had to change the `instance_type` of the runner from `t3.micro` to `t3.small`.
395395

396396
#### Configuration example
397397

@@ -685,7 +685,6 @@ Made with [contributors-img](https://contrib.rocks).
685685
| <a name="input_runners_pre_clone_script"></a> [runners\_pre\_clone\_script](#input\_runners\_pre\_clone\_script) | Commands to be executed on the Runner before cloning the Git repository. this can be used to adjust the Git client configuration first, for example. | `string` | `"\"\""` | no |
686686
| <a name="input_runners_privileged"></a> [runners\_privileged](#input\_runners\_privileged) | Runners will run in privileged mode, will be used in the runner config.toml | `bool` | `true` | no |
687687
| <a name="input_runners_pull_policies"></a> [runners\_pull\_policies](#input\_runners\_pull\_policies) | pull policies for the runners, will be used in the runner config.toml, for Gitlab Runner >= 13.8, see https://docs.gitlab.com/runner/executors/docker.html#using-multiple-pull-policies | `list(string)` | <pre>[<br> "always"<br>]</pre> | no |
688-
| <a name="input_runners_pull_policy"></a> [runners\_pull\_policy](#input\_runners\_pull\_policy) | Deprecated! Use runners\_pull\_policies instead. pull\_policy for the runners, will be used in the runner config.toml | `string` | `""` | no |
689688
| <a name="input_runners_request_concurrency"></a> [runners\_request\_concurrency](#input\_runners\_request\_concurrency) | Limit number of concurrent requests for new jobs from GitLab (default 1). | `number` | `1` | no |
690689
| <a name="input_runners_request_spot_instance"></a> [runners\_request\_spot\_instance](#input\_runners\_request\_spot\_instance) | Whether or not to request spot instances via docker-machine | `bool` | `true` | no |
691690
| <a name="input_runners_root_size"></a> [runners\_root\_size](#input\_runners\_root\_size) | Runner instance root size in GB. | `number` | `16` | no |

examples/runner-certificates/README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,24 @@ Create a PEM-encoded `.crt` file containing the public certificate of your Gitla
3232

3333
```hcl
3434
module {
35-
...
35+
# ...
3636
# Public cert of my companys gitlab instance
37-
runners_gitlab_certificate = file("${path.module}/my_gitlab_instance_cert.crt")
38-
...
37+
runner_gitlab = {
38+
certificate = file("${path.module}/my_gitlab_instance_cert.crt")
39+
}
40+
# ...
3941
}
4042
```
4143

4244
Add your CA and intermediary certs to a second PEM-encoded `.crt` file.
4345
```hcl
4446
module {
45-
...
47+
# ...
4648
# Other public certs relating to my company.
47-
runners_ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
48-
...
49+
runner_gitlab = {
50+
ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
51+
}
52+
# ...
4953
}
5054
```
5155

@@ -58,15 +62,17 @@ For **user images**, you must:
5862
The runner module can be configured to do this step. Configure the module like so:
5963

6064
```terraform
61-
module {
65+
module "runner" {
6266
# ...
6367
6468
# Mount EC2 host certs in docker so all user docker images can reference them.
65-
runners_additional_volumes = ["/etc/gitlab-runner/certs/:/etc/gitlab-runner/certs:ro"]
66-
67-
# ...
69+
runner_worker_docker_options = {
70+
volumes = ["/etc/gitlab-runner/certs/:/etc/gitlab-runner/certs:ro"]
6871
}
69-
```
72+
73+
# ...
74+
}
75+
```
7076
7177
2. Trust the certificates from within the user image.
7278
@@ -107,17 +113,18 @@ For **user images**, you must:
107113
This avoids maintaining the script in each pipeline file, but expects that all user images use the same OS.
108114
109115
```terraform
110-
module {
116+
module "runner" {
111117
# ...
112118
113-
runners_pre_build_script = <<EOT
114-
'''
115-
apt-get install -y ca-certificates
116-
cp /etc/gitlab-runner/certs/* /usr/local/share/ca-certificates/
117-
update-ca-certificates
118-
'''
119-
EOT
120-
119+
runner_worker_gitlab_pipeline = {
120+
pre_build_script = <<EOT
121+
'''
122+
apt-get install -y ca-certificates
123+
cp /etc/gitlab-runner/certs/* /usr/local/share/ca-certificates/
124+
update-ca-certificates
125+
'''
126+
EOT
127+
}
121128
# ...
122129
}
123130
```

examples/runner-certificates/main.tf

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,36 @@ module "runner" {
2727
###############################################
2828
# General
2929
###############################################
30-
31-
runners_name = var.runner_name
32-
runners_gitlab_url = var.gitlab_url
33-
34-
runners_executor = "docker"
35-
36-
aws_region = var.aws_region
3730
environment = var.environment
3831

3932
###############################################
4033
# Certificates
4134
###############################################
4235

4336
# Public cert of my companys gitlab instance
44-
runners_gitlab_certificate = file("${path.module}/my_gitlab_instance_cert.crt")
45-
4637
# Other public certs relating to my company.
47-
runners_ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
38+
runner_gitlab = {
39+
url = var.gitlab_url
40+
certificate = file("${path.module}/my_gitlab_instance_cert.crt")
41+
ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
42+
}
4843

4944
# Mount EC2 host certs in docker so all user docker images can reference them.
5045
# Each user image will need to do:
5146
# cp /etc/gitlab-runner/certs/* /usr/local/share/ca-certificates/
5247
# update-ca-certificates
5348
# Or similar OS-dependent commands. The above are an example for Ubuntu.
54-
runners_additional_volumes = ["/etc/gitlab-runner/certs/:/etc/gitlab-runner/certs:ro"]
49+
runner_worker_docker_options = {
50+
volumes = [
51+
"/cache",
52+
"/etc/gitlab-runner/certs/:/etc/gitlab-runner/certs:ro"
53+
]
54+
}
5555

5656
###############################################
5757
# Registration
5858
###############################################
59-
60-
gitlab_runner_registration_config = {
59+
runner_gitlab_registration_config = {
6160
registration_token = var.registration_token
6261
tag_list = "docker_runner"
6362
description = "runner docker - auto"
@@ -71,5 +70,11 @@ module "runner" {
7170
###############################################
7271
vpc_id = module.vpc.vpc_id
7372
subnet_id = element(module.vpc.public_subnets, 0)
73+
runner_instance = {
74+
name = var.runner_name
75+
}
7476

77+
runner_worker = {
78+
type = "docker"
79+
}
7580
}

0 commit comments

Comments
 (0)