Skip to content

refactor!: group variables for better overview #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 82 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
3cde0f1
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
3fdd3c5
chore!: remove deprecated variables (#738)
kayman-mk Mar 16, 2023
7cc41da
add note for variable section
kayman-mk Mar 20, 2023
d7ad4fe
remove `aws_region`
kayman-mk Mar 22, 2023
df68fb0
rename global variables
kayman-mk Mar 22, 2023
ded5a63
refactor some variables
kayman-mk Mar 22, 2023
b4db8bf
refactor some variables
kayman-mk Mar 22, 2023
b1e90d7
refactor some more
kayman-mk Mar 22, 2023
a51a42b
refactor some more variables
kayman-mk Mar 23, 2023
ba7af60
more variables
kayman-mk Mar 23, 2023
d0e2729
refactor remaining
kayman-mk Mar 23, 2023
dd58916
fix syntax error
kayman-mk Mar 23, 2023
05345cf
format code
kayman-mk Mar 23, 2023
4f73a44
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
c78907a
chore!: remove deprecated variables (#738)
kayman-mk Mar 16, 2023
0165e8d
Merge branch 'refactor-variables' into kayma/split-variables
kayman-mk Mar 23, 2023
323e198
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
93657e6
chore!: remove deprecated variables (#738)
kayman-mk Mar 16, 2023
74d978e
merge refactor-variables
kayman-mk Apr 20, 2023
3b340a4
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
3e17556
chore!: remove deprecated variables (#738)
kayman-mk Mar 16, 2023
3662eeb
feat!: add idle_count_min` and `idle_scale_factor` to Docker Machine …
tmeijn Apr 20, 2023
8aded23
merge refactor-variables
kayman-mk Apr 20, 2023
13874f1
fix syntax error
kayman-mk Apr 20, 2023
26a6d19
feat!: allow to set all docker options for the Executor (#511)
kayman-mk Apr 20, 2023
fe78e96
merge refactor-variables
kayman-mk Apr 20, 2023
e324a7f
fix wrong variable name
kayman-mk Apr 20, 2023
30f03a4
fix syntax error
kayman-mk Apr 20, 2023
90a9c48
fix lint issues
kayman-mk Apr 20, 2023
c13cac4
fix syntax error
kayman-mk Apr 20, 2023
b5f9e17
removed obsolete variables present in executor_docker_options now
kayman-mk Apr 20, 2023
2d79ffc
rename variables agent_* to runner_manager_*
kayman-mk Apr 20, 2023
e014dc6
rename variables in script too
kayman-mk Apr 20, 2023
a94a9e6
rename variables executor_* to runner_worker_*
kayman-mk Apr 20, 2023
31664a0
identify runner_manager variables
kayman-mk Apr 20, 2023
3a76dc7
split variables in runner_manager and runner
kayman-mk Apr 20, 2023
ea2401d
format code
kayman-mk Apr 20, 2023
71b4f9f
fix syntax error
kayman-mk Apr 20, 2023
8887fb0
fix syntax error
kayman-mk Apr 20, 2023
5f507a1
fix wrong variable name in conversion
kayman-mk Apr 20, 2023
b2e3f4c
runner_role and runner_instance
kayman-mk Apr 20, 2023
8f62a0f
introduce runner_manager
kayman-mk Apr 21, 2023
103a2b6
runner_install
kayman-mk Apr 21, 2023
5c987f3
some more variable groupings
kayman-mk Apr 21, 2023
b61ad3f
rework cache variables
kayman-mk Apr 21, 2023
60e1c96
runner_worker_docker_machine_instance
kayman-mk Apr 22, 2023
139f02d
runner_worker_docker_machine_instance_spot
kayman-mk Apr 22, 2023
2e267e0
runner_worker_docker_machine_role
kayman-mk Apr 22, 2023
b43ee5b
GROUP-VARIABLES
kayman-mk Apr 22, 2023
c3bfe40
converted the examples with migration script
kayman-mk Apr 23, 2023
d845abf
fix syntax error and format code
kayman-mk Apr 23, 2023
e02eb85
fix syntax errors
kayman-mk Apr 23, 2023
56a14a9
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
2cb01ad
chore!: remove deprecated variables (#738)
kayman-mk Apr 27, 2023
05b052f
feat!: add idle_count_min` and `idle_scale_factor` to Docker Machine …
tmeijn Apr 20, 2023
dc5a758
feat!: allow to set all docker options for the Executor (#511)
kayman-mk Apr 20, 2023
7f6bea1
merge
kayman-mk Apr 27, 2023
42a6333
format code
kayman-mk Apr 27, 2023
ba92016
add suppressed_tags again
kayman-mk Apr 27, 2023
d82d8e7
fix instance_types
kayman-mk Apr 27, 2023
9a10733
fix example
kayman-mk Apr 27, 2023
0ef219d
rework variable descriptions
kayman-mk Apr 27, 2023
a6fc4fc
GROUP-VARIABLES
kayman-mk Apr 27, 2023
53fb67d
GROUP-VARIABLES
kayman-mk Apr 27, 2023
ee1adc7
GROUP-VARIABLES
kayman-mk Apr 27, 2023
c983ad5
GROUP-VARIABLES
kayman-mk Apr 27, 2023
62c73d8
add docs
kayman-mk Apr 27, 2023
9c7db8f
more docs
kayman-mk Apr 27, 2023
bcb967f
GROUP-VARIABLES
kayman-mk Apr 27, 2023
026b7e7
fix!: remove deprecated pull policy variable (#710)
tmeijn Mar 2, 2023
1e289df
chore!: remove deprecated variables (#738)
kayman-mk Apr 27, 2023
4128105
feat!: add idle_count_min` and `idle_scale_factor` to Docker Machine …
tmeijn Apr 20, 2023
7e05787
feat!: allow to set all docker options for the Executor (#511)
kayman-mk Apr 20, 2023
421d29e
merge refactor-variables
kayman-mk May 3, 2023
4953db4
GROUP-VARIABLES
kayman-mk May 3, 2023
cd41f05
GROUP-VARIABLES
kayman-mk May 3, 2023
60f3ba1
reworked all `README.md`
kayman-mk May 8, 2023
5a3f01d
change module source to `cattle-ops`
kayman-mk May 8, 2023
4208313
Merge branch 'main' into kayma/group-variables
kayman-mk May 11, 2023
72f9b58
merge base
kayman-mk May 11, 2023
cf0eba1
GROUP-VARIABLES
kayman-mk May 11, 2023
48ebfee
GROUP-VARIABLES
kayman-mk May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"version": "0.2",
"language": "en",
"words": [
"alltrue",
"amazonec",
"amannn",
"amazonec",
"anytrue",
"aquasecurity",
"awscli",
Expand All @@ -16,14 +18,16 @@
"codeowners",
"companys",
"concat",
"cpu",
"cpus",
"cpuset",
"devskim",
"dind",
"endfor",
"filesha",
"formatlist",
"gitter",
"godotenv",
"golangci",
"gruntwork",
"glrunners",
"instancelifecycle",
"kics",
"joho",
Expand All @@ -38,24 +42,31 @@
"pylint",
"pylintrc",
"pyright",
"setsubtract",
"shuf",
"signoff",
"signum",
"stretchr",
"subkey",
"substr",
"sysctl",
"sysctls",
"templatefile",
"terrascan",
"terratest",
"tfenv",
"tflint",
"tftpl",
"tfsec",
"tftpl",
"tfvars",
"tmpfs",
"trivy",
"typecheck",
"userdata",
"xanzy"
"userns",
"xanzy",
"xvda"
],
"flagWords": []
}
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
terraform: [ 1.0.11, 1.3.9, latest ]
terraform: [ 1.3.9, latest ]
example:
[
"runner-default",
Expand Down Expand Up @@ -137,7 +137,8 @@ jobs:
run: tflint --init

- name: Run TFLint
run: tflint
# assign necessary variables to avoid errors
run: "tflint --var='runner_instance={\"name_prefix\": \"a\", \"name\": \"b\"}'"

tfsec:
name: tfsec PR commenter
Expand Down
2 changes: 2 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ DISABLE_LINTERS:
- TERRAFORM_TFLINT
# Super slow linter, but useful. We disable it here and run it in parallel to Megalinter saves some minutes.
- TERRAFORM_KICS
# has issues with the Terraform code `optional` variable definitions: https://github.com/tenable/terrascan/issues/1532
- TERRAFORM_TERRASCAN
# Nice linter to report CVEs and other cool stuff. But it reports problems with the Terraform code which can't be disabled by
# configuration.
- REPOSITORY_TRIVY
Expand Down
2 changes: 1 addition & 1 deletion .terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.8
1.3.0
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<!-- First line should be a H1: Badges on top please! -->
<!-- markdownlint-disable MD041 -->
<!-- markdownlint-disable MD041/first-line-heading/first-line-h1 -->
[![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/)
[![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)
[![Actions](https://github.com/cattle-ops/terraform-aws-gitlab-runner/workflows/CI/badge.svg)](https://github.com/cattle-ops/terraform-aws-gitlab-runner/actions)
<!-- markdownlint-enable MD041/first-line-heading/first-line-h1 -->

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

Expand Down Expand Up @@ -385,13 +386,12 @@ module "runner" {

Since spot instances can be taken over by AWS depending on the instance type and AZ you are using, you may want multiple instances
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
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)
of docker-machine supports spot fleets.
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) of docker-machine supports spot fleets.

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
module is using consume more RAM using spot fleets.
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
`instance_type` of the runner from `t3.micro` to `t3.small`.
module is using consume more RAM using spot fleets. 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 `instance_type` of the runner from `t3.micro` to `t3.small`.

#### Configuration example

Expand Down Expand Up @@ -685,7 +685,6 @@ Made with [contributors-img](https://contrib.rocks).
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <a name="input_runners_root_size"></a> [runners\_root\_size](#input\_runners\_root\_size) | Runner instance root size in GB. | `number` | `16` | no |
Expand Down
8 changes: 4 additions & 4 deletions examples/runner-certificates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Create a PEM-encoded `.crt` file containing the public certificate of your Gitla
module {
...
# Public cert of my companys gitlab instance
runners_gitlab_certificate = file("${path.module}/my_gitlab_instance_cert.crt")
agent_gitlab_certificate = file("${path.module}/my_gitlab_instance_cert.crt")
...
}
```
Expand All @@ -44,7 +44,7 @@ Add your CA and intermediary certs to a second PEM-encoded `.crt` file.
module {
...
# Other public certs relating to my company.
runners_ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
agent_gitlab_ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
...
}
```
Expand All @@ -58,7 +58,7 @@ For **user images**, you must:
The runner module can be configured to do this step. Configure the module like so:

```terraform
module {
module "runner" {
# ...

# Mount EC2 host certs in docker so all user docker images can reference them.
Expand Down Expand Up @@ -107,7 +107,7 @@ For **user images**, you must:
This avoids maintaining the script in each pipeline file, but expects that all user images use the same OS.

```terraform
module {
module "runner" {
# ...

runners_pre_build_script = <<EOT
Expand Down
32 changes: 19 additions & 13 deletions examples/runner-certificates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,37 @@ module "runner" {
###############################################
# General
###############################################

runners_name = var.runner_name
runners_gitlab_url = var.gitlab_url

runners_executor = "docker"

aws_region = var.aws_region
environment = var.environment

###############################################
# Certificates
###############################################

# Public cert of my companys gitlab instance
runners_gitlab_certificate = file("${path.module}/my_gitlab_instance_cert.crt")

# Other public certs relating to my company.
runners_ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
runner_gitlab = {
url = var.gitlab_url
certificate = file("${path.module}/my_gitlab_instance_cert.crt")
ca_certificate = file("${path.module}/my_company_ca_cert_bundle.crt")
}

# Mount EC2 host certs in docker so all user docker images can reference them.
# Each user image will need to do:
# cp /etc/gitlab-runner/certs/* /usr/local/share/ca-certificates/
# update-ca-certificates
# Or similar OS-dependent commands. The above are an example for Ubuntu.
runners_additional_volumes = ["/etc/gitlab-runner/certs/:/etc/gitlab-runner/certs:ro"]

runner_worker_docker_options = {
volumes = [
"/cache",
"/etc/gitlab-runner/certs/:/etc/gitlab-runner/certs:ro"
]
}

###############################################
# Registration
###############################################

gitlab_runner_registration_config = {
runner_gitlab_registration_config = {
registration_token = var.registration_token
tag_list = "docker_runner"
description = "runner docker - auto"
Expand All @@ -71,5 +71,11 @@ module "runner" {
###############################################
vpc_id = module.vpc.vpc_id
subnet_id = element(module.vpc.public_subnets, 0)
runner_instance = {
name = var.runner_name
}

runner_worker = {
type = "docker"
}
}
72 changes: 40 additions & 32 deletions examples/runner-default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,26 @@ module "vpc_endpoints" {
module "runner" {
source = "../../"

aws_region = var.aws_region
environment = var.environment

vpc_id = module.vpc.vpc_id
subnet_id = element(module.vpc.private_subnets, 0)
metrics_autoscaling = ["GroupDesiredCapacity", "GroupInServiceCapacity"]
vpc_id = module.vpc.vpc_id
subnet_id = element(module.vpc.private_subnets, 0)

runners_name = var.runner_name
runners_gitlab_url = var.gitlab_url
enable_runner_ssm_access = true
runner_instance = {
collect_autoscaling_metrics = ["GroupDesiredCapacity", "GroupInServiceCapacity"]
name = var.runner_name
ssm_access = true
}

gitlab_runner_security_group_ids = [data.aws_security_group.default.id]
runner_networking = {
allow_incoming_ping_security_group_ids = [data.aws_security_group.default.id]
}

docker_machine_spot_price_bid = "on-demand-price"
runner_gitlab = {
url = var.gitlab_url
}

gitlab_runner_registration_config = {
runner_gitlab_registration_config = {
registration_token = var.registration_token
tag_list = "docker_spot_runner"
description = "runner default - auto"
Expand All @@ -74,46 +78,49 @@ module "runner" {
maximum_timeout = "3600"
}

tags = {
"tf-aws-gitlab-runner:example" = "runner-default"
"tf-aws-gitlab-runner:instancelifecycle" = "spot:yes"
runner_worker_gitlab_pipeline = {
pre_build_script = <<EOT
'''
echo 'multiline 1'
echo 'multiline 2'
'''
EOT
post_build_script = "\"echo 'single line'\""
}

runners_privileged = "true"
runners_additional_volumes = ["/certs/client"]
runner_worker_docker_options = {
privileged = "true"
volumes = ["/cache", "/certs/client"]
}

runners_volumes_tmpfs = [
runner_worker_docker_volumes_tmpfs = [
{
volume = "/var/opt/cache",
options = "rw,noexec"
}
]

runners_services_volumes_tmpfs = [
runner_worker_docker_services_volumes_tmpfs = [
{
volume = "/var/lib/mysql",
options = "rw,noexec"
}
]

# working 9 to 5 :)
runners_machine_autoscaling = [
runner_worker_docker_machine_autoscaling_options = [
# working 9 to 5 :)
{
periods = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]
periods = ["* * 0-9,17-23 * * mon-fri *", "* * * * * sat,sun *"]
idle_count = 0
idle_time = 60
timezone = var.timezone
}
]

runners_pre_build_script = <<EOT
'''
echo 'multiline 1'
echo 'multiline 2'
'''
EOT

runners_post_build_script = "\"echo 'single line'\""
tags = {
"tf-aws-gitlab-runner:example" = "runner-default"
"tf-aws-gitlab-runner:instancelifecycle" = "spot:yes"
}

# Uncomment the HCL code below to configure a docker service so that registry mirror is used in auto-devops jobs
# 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
Expand All @@ -139,7 +146,7 @@ module "runner" {
#
# If not using an official docker image for your job, you may need to specify `DOCKER_HOST: tcp://docker:2375`
## UNCOMMENT 6 LINES BELOW
# runners_docker_services = [{
# runner_worker_docker_services = [{
# name = "docker:20.10.16-dind"
# alias = "docker"
# command = ["--registry-mirror", "https://mirror.gcr.io"]
Expand All @@ -149,7 +156,8 @@ module "runner" {

# Example how to configure runners, to utilize EC2 user-data feature
# example template, creates (configurable) swap file for the runner
# runners_userdata = templatefile("${path.module}/../../templates/swap.tpl", {
# swap_size = "512"
# })
# runner_worker_docker_machine_instance = {
# start_script = templatefile("${path.module}/../../templates/swap.tpl", {
# swap_size = "512"
# }
}
Loading