Skip to content

Commit bafe59c

Browse files
committed
Merge develop branch
2 parents fbaf149 + 19bdf5c commit bafe59c

File tree

7 files changed

+25
-77
lines changed

7 files changed

+25
-77
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ By default the module creates a a cache for the runner in S3. Old objects are au
159159
160160
Creation of the bucket can be disabled and managed outside this module. A good use case is for sharing the cache across multiple runners. For this purpose the cache is implemented as a sub module. For more details see the [cache module](https://github.com/npalm/terraform-aws-gitlab-runner/tree/develop/cache). An example implementation of this use case can be found in the [runner-public](https://github.com/npalm/terraform-aws-gitlab-runner/tree/__GIT_REF__/examples/runner-public) example.
161161
162+
## Cost Estimation
163+
164+
### Hapag-Lloyd AG
165+
We set up a build pipeline for 13 developers (plus one technical user running Renovate to update all
166+
dependencies) in 3 availability zones. Running 2 different type of machines. One for cloud deployment,
167+
aka `terraform apply` (t3.medium, on demand, 3 idles, 15 max, 45 minutes idle time). The other one
168+
for all other jobs (c5.xlarge, spot, 9 idles, 60 max, 45 minutes idle time). All machines are
169+
using a shared S3 cache. The pipeline is running from 7am till 7pm. In the non peak hours all
170+
docker+machine instances are killed.
171+
172+
Per day costs: $20. We are quite satisfied with this pipeline.
173+
162174
## Usage
163175
164176
### Configuration
@@ -324,8 +336,8 @@ terraform destroy
324336
| <a name="input_ami_owners"></a> [ami\_owners](#input\_ami\_owners) | The list of owners used to select the AMI of Gitlab runner agent instances. | `list(string)` | <pre>[<br> "amazon"<br>]</pre> | no |
325337
| <a name="input_arn_format"></a> [arn\_format](#input\_arn\_format) | ARN format to be used. May be changed to support deployment in GovCloud/China regions. | `string` | `"arn:aws"` | no |
326338
| <a name="input_asg_delete_timeout"></a> [asg\_delete\_timeout](#input\_asg\_delete\_timeout) | Timeout when trying to delete the Runner ASG. | `string` | `"10m"` | no |
339+
| <a name="input_asg_max_instance_lifetime"></a> [asg\_max\_instance\_lifetime](#input\_asg\_max\_instance\_lifetime) | The seconds before an instance is refreshed in the ASG. | `number` | `null` | no |
327340
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | n/a | yes |
328-
| <a name="input_aws_zone"></a> [aws\_zone](#input\_aws\_zone) | Deprecated. Will be removed in the next major release. | `string` | `"a"` | no |
329341
| <a name="input_cache_bucket"></a> [cache\_bucket](#input\_cache\_bucket) | Configuration to control the creation of the cache bucket. By default the bucket will be created and used as shared cache. To use the same cache across multiple runners disable the creation of the cache and provide a policy and bucket name. See the public runner example for more details. | `map(any)` | <pre>{<br> "bucket": "",<br> "create": true,<br> "policy": ""<br>}</pre> | no |
330342
| <a name="input_cache_bucket_name_include_account_id"></a> [cache\_bucket\_name\_include\_account\_id](#input\_cache\_bucket\_name\_include\_account\_id) | Boolean to add current account ID to cache bucket name. | `bool` | `true` | no |
331343
| <a name="input_cache_bucket_prefix"></a> [cache\_bucket\_prefix](#input\_cache\_bucket\_prefix) | Prefix for s3 cache bucket name. | `string` | `""` | no |
@@ -341,14 +353,12 @@ terraform destroy
341353
| <a name="input_docker_machine_options"></a> [docker\_machine\_options](#input\_docker\_machine\_options) | List of additional options for the docker machine config. Each element of this list must be a key=value pair. E.g. '["amazonec2-zone=a"]' | `list(string)` | `[]` | no |
342354
| <a name="input_docker_machine_role_json"></a> [docker\_machine\_role\_json](#input\_docker\_machine\_role\_json) | Docker machine runner instance override policy, expected to be in JSON format. | `string` | `""` | no |
343355
| <a name="input_docker_machine_security_group_description"></a> [docker\_machine\_security\_group\_description](#input\_docker\_machine\_security\_group\_description) | A description for the docker-machine security group | `string` | `"A security group containing docker-machine instances"` | no |
344-
| <a name="input_docker_machine_spot_price_bid"></a> [docker\_machine\_spot\_price\_bid](#input\_docker\_machine\_spot\_price\_bid) | Spot price bid. | `string` | `"0.06"` | no |
356+
| <a name="input_docker_machine_spot_price_bid"></a> [docker\_machine\_spot\_price\_bid](#input\_docker\_machine\_spot\_price\_bid) | Spot price bid. The maximum price willing to pay. By default the price is limited by the current on demand price for the instance type chosen. | `string` | `"on-demand-price"` | no |
345357
| <a name="input_docker_machine_version"></a> [docker\_machine\_version](#input\_docker\_machine\_version) | By default docker\_machine\_download\_url is used to set the docker machine version. Version of docker-machine. The version will be ingored once `docker_machine_download_url` is set. | `string` | `""` | no |
346358
| <a name="input_enable_asg_recreation"></a> [enable\_asg\_recreation](#input\_enable\_asg\_recreation) | Enable automatic redeployment of the Runner ASG when the Launch Configs change. | `bool` | `true` | no |
347-
| <a name="input_asg_max_instance_lifetime"></a> [asg\_max\_instance\_lifetime](#input\_asg\_max\_instance\_lifetime) | The seconds before an instance is refreshed in the ASG. | `number` | `null` | no |
348359
| <a name="input_enable_cloudwatch_logging"></a> [enable\_cloudwatch\_logging](#input\_enable\_cloudwatch\_logging) | Boolean used to enable or disable the CloudWatch logging. | `bool` | `true` | no |
349360
| <a name="input_enable_docker_machine_ssm_access"></a> [enable\_docker\_machine\_ssm\_access](#input\_enable\_docker\_machine\_ssm\_access) | Add IAM policies to the docker-machine instances to connect via the Session Manager. | `bool` | `false` | no |
350361
| <a name="input_enable_eip"></a> [enable\_eip](#input\_enable\_eip) | Enable the assignment of an EIP to the gitlab runner instance | `bool` | `false` | no |
351-
| <a name="input_enable_forced_updates"></a> [enable\_forced\_updates](#input\_enable\_forced\_updates) | DEPRECATED! and is replaced by `enable_asg_recreation. Setting this variable to true will do the opposite as expected. For backward compatibility the variable will remain some releases. Old desription: Enable automatic redeployment of the Runner ASG when the Launch Configs change.` | `string` | `null` | no |
352362
| <a name="input_enable_gitlab_runner_ssh_access"></a> [enable\_gitlab\_runner\_ssh\_access](#input\_enable\_gitlab\_runner\_ssh\_access) | Enables SSH Access to the gitlab runner instance. | `bool` | `false` | no |
353363
| <a name="input_enable_kms"></a> [enable\_kms](#input\_enable\_kms) | Let the module manage a KMS key, logs will be encrypted via KMS. Be-aware of the costs of an custom key. | `bool` | `false` | no |
354364
| <a name="input_enable_manage_gitlab_token"></a> [enable\_manage\_gitlab\_token](#input\_enable\_manage\_gitlab\_token) | Boolean to enable the management of the GitLab token in SSM. If `true` the token will be stored in SSM, which means the SSM property is a terraform managed resource. If `false` the Gitlab token will be stored in the SSM by the user-data script during creation of the the instance. However the SSM parameter is not managed by terraform and will remain in SSM after a `terraform destroy`. | `bool` | `true` | no |
@@ -382,7 +392,7 @@ terraform destroy
382392
| <a name="input_runner_instance_enable_monitoring"></a> [runner\_instance\_enable\_monitoring](#input\_runner\_instance\_enable\_monitoring) | Enable the GitLab runner instance to have detailed monitoring. | `bool` | `true` | no |
383393
| <a name="input_runner_instance_metadata_options_http_endpoint"></a> [runner\_instance\_metadata\_options\_http\_endpoint](#input\_runner\_instance\_metadata\_options\_http\_endpoint) | Enable the Gitlab runner agent instance metadata service. The allowed values are enabled, disabled. | `string` | `"enabled"` | no |
384394
| <a name="input_runner_instance_metadata_options_http_tokens"></a> [runner\_instance\_metadata\_options\_http\_tokens](#input\_runner\_instance\_metadata\_options\_http\_tokens) | Set if Gitlab runner agent instance metadata service session tokens are required. The allowed values are optional, required. | `string` | `"optional"` | no |
385-
| <a name="input_runner_instance_spot_price"></a> [runner\_instance\_spot\_price](#input\_runner\_instance\_spot\_price) | By setting a spot price bid price the runner agent will be created via a spot request. Be aware that spot instances can be stopped by AWS. | `string` | `null` | no |
395+
| <a name="input_runner_instance_spot_price"></a> [runner\_instance\_spot\_price](#input\_runner\_instance\_spot\_price) | By setting a spot price bid price the runner agent will be created via a spot request. Be aware that spot instances can be stopped by AWS. Choose "on-demand-price" to pay up to the current on demand price for the instance type chosen. | `string` | `null` | no |
386396
| <a name="input_runner_root_block_device"></a> [runner\_root\_block\_device](#input\_runner\_root\_block\_device) | The EC2 instance root block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id` | `map(string)` | `{}` | no |
387397
| <a name="input_runner_tags"></a> [runner\_tags](#input\_runner\_tags) | Map of tags that will be added to runner EC2 instances. | `map(string)` | `{}` | no |
388398
| <a name="input_runners_additional_volumes"></a> [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 |
@@ -404,10 +414,6 @@ terraform destroy
404414
| <a name="input_runners_max_builds"></a> [runners\_max\_builds](#input\_runners\_max\_builds) | Max builds for each runner after which it will be removed, will be used in the runner config.toml. By default set to 0, no maxBuilds will be set in the configuration. | `number` | `0` | no |
405415
| <a name="input_runners_monitoring"></a> [runners\_monitoring](#input\_runners\_monitoring) | Enable detailed cloudwatch monitoring for spot instances. | `bool` | `false` | no |
406416
| <a name="input_runners_name"></a> [runners\_name](#input\_runners\_name) | Name of the runner, will be used in the runner config.toml. | `string` | n/a | yes |
407-
| <a name="input_runners_off_peak_idle_count"></a> [runners\_off\_peak\_idle\_count](#input\_runners\_off\_peak\_idle\_count) | Deprecated, please use `runners_machine_autoscaling`. Off peak idle count of the runners, will be used in the runner config.toml. | `number` | `-1` | no |
408-
| <a name="input_runners_off_peak_idle_time"></a> [runners\_off\_peak\_idle\_time](#input\_runners\_off\_peak\_idle\_time) | Deprecated, please use `runners_machine_autoscaling`. Off peak idle time of the runners, will be used in the runner config.toml. | `number` | `-1` | no |
409-
| <a name="input_runners_off_peak_periods"></a> [runners\_off\_peak\_periods](#input\_runners\_off\_peak\_periods) | Deprecated, please use `runners_machine_autoscaling`. Off peak periods of the runners, will be used in the runner config.toml. | `string` | `null` | no |
410-
| <a name="input_runners_off_peak_timezone"></a> [runners\_off\_peak\_timezone](#input\_runners\_off\_peak\_timezone) | Deprecated, please use `runners_machine_autoscaling`. Off peak idle time zone of the runners, will be used in the runner config.toml. | `string` | `null` | no |
411417
| <a name="input_runners_output_limit"></a> [runners\_output\_limit](#input\_runners\_output\_limit) | Sets the maximum build log size in kilobytes, by default set to 4096 (4MB) | `number` | `4096` | no |
412418
| <a name="input_runners_post_build_script"></a> [runners\_post\_build\_script](#input\_runners\_post\_build\_script) | Commands to be executed on the Runner just after executing the build, but before executing after\_script. | `string` | `"\"\""` | no |
413419
| <a name="input_runners_pre_build_script"></a> [runners\_pre\_build\_script](#input\_runners\_pre\_build\_script) | Script to execute in the pipeline just before the build, will be used in the runner config.toml | `string` | `"\"\""` | no |

examples/runner-default/main.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module "runner" {
4545
gitlab_runner_security_group_ids = [data.aws_security_group.default.id]
4646

4747
docker_machine_download_url = "https://gitlab-docker-machine-downloads.s3.amazonaws.com/v0.16.2-gitlab.2/docker-machine"
48-
docker_machine_spot_price_bid = "0.06"
48+
docker_machine_spot_price_bid = "on-demand-price"
4949

5050
gitlab_runner_registration_config = {
5151
registration_token = var.registration_token
@@ -79,11 +79,6 @@ module "runner" {
7979
]
8080

8181
# working 9 to 5 :)
82-
# Deprecated, replaced by runners_machine_autoscaling
83-
# runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
84-
# runners_off_peak_timezone = var.timezone
85-
# runners_off_peak_idle_count = 0
86-
# runners_off_peak_idle_time = 60
8782
runners_machine_autoscaling = [
8883
{
8984
periods = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]

examples/runner-public/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module "runner" {
4444
subnet_ids_gitlab_runner = module.vpc.public_subnets
4545
subnet_id_runners = element(module.vpc.public_subnets, 0)
4646

47-
docker_machine_spot_price_bid = "0.1"
47+
docker_machine_spot_price_bid = "on-demand-price"
4848

4949
runners_name = var.runner_name
5050
runners_gitlab_url = var.gitlab_url
@@ -91,7 +91,7 @@ module "runner2" {
9191
subnet_ids_gitlab_runner = module.vpc.public_subnets
9292
subnet_id_runners = element(module.vpc.public_subnets, 0)
9393

94-
docker_machine_spot_price_bid = "0.1"
94+
docker_machine_spot_price_bid = "on-demand-price"
9595

9696
runners_name = var.runner_name
9797
runners_gitlab_url = var.gitlab_url

locals.tf

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ locals {
1515
// custom names for instances and security groups
1616
name_runner_agent_instance = var.overrides["name_runner_agent_instance"] == "" ? local.tags["Name"] : var.overrides["name_runner_agent_instance"]
1717
name_sg = var.overrides["name_sg"] == "" ? local.tags["Name"] : var.overrides["name_sg"]
18-
name_iam_objects = var.overrides["name_iam_objects"] == "" ? local.tags["Name"] : var.overrides["name_iam_objects"]
18+
name_iam_objects = lookup(var.overrides, "name_iam_objects", "") == "" ? local.tags["Name"] : var.overrides["name_iam_objects"]
1919
runners_additional_volumes = <<-EOT
2020
%{~for volume in var.runners_additional_volumes~},"${volume}"%{endfor~}
2121
EOT
@@ -24,11 +24,4 @@ locals {
2424
runners_machine_autoscaling = var.runners_machine_autoscaling
2525
}
2626
)
27-
28-
// Depcrecated off peak, ensure not set if not explicit set.
29-
runners_off_peak_periods_string = var.runners_off_peak_periods == null ? "" : format("OffPeakPeriods = %s", var.runners_off_peak_periods)
30-
runners_off_peak_timezone = var.runners_off_peak_timezone == null ? "" : "OffPeakTimezone = \"${var.runners_off_peak_timezone}\""
31-
runners_off_peak_idle_count = var.runners_off_peak_idle_count == -1 ? "" : format("OffPeakIdleCount = %d", var.runners_off_peak_idle_count)
32-
runners_off_peak_idle_time = var.runners_off_peak_idle_time == -1 ? "" : format("OffPeakIdleTime = %d", var.runners_off_peak_idle_time)
33-
3427
}

main.tf

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ resource "aws_ssm_parameter" "runner_sentry_dsn" {
5050
}
5151

5252
locals {
53-
enable_asg_recreation = var.enable_forced_updates != null ? !var.enable_forced_updates : var.enable_asg_recreation
54-
5553
template_user_data = templatefile("${path.module}/template/user-data.tpl",
5654
{
5755
eip = var.enable_eip ? local.template_eip : ""
@@ -97,7 +95,7 @@ locals {
9795
runners_subnet_id = var.subnet_id_runners
9896
runners_aws_zone = data.aws_availability_zone.runners.name_suffix
9997
runners_instance_type = var.docker_machine_instance_type
100-
runners_spot_price_bid = var.docker_machine_spot_price_bid
98+
runners_spot_price_bid = var.docker_machine_spot_price_bid == "on-demand-price" ? "" : var.docker_machine_spot_price_bid
10199
runners_ami = data.aws_ami.docker-machine.id
102100
runners_security_group_name = aws_security_group.docker_machine.name
103101
runners_monitoring = var.runners_monitoring
@@ -131,10 +129,6 @@ locals {
131129
runners_idle_count = var.runners_idle_count
132130
runners_idle_time = var.runners_idle_time
133131
runners_max_builds = local.runners_max_builds_string
134-
runners_off_peak_timezone = local.runners_off_peak_timezone
135-
runners_off_peak_idle_count = local.runners_off_peak_idle_count
136-
runners_off_peak_idle_time = local.runners_off_peak_idle_time
137-
runners_off_peak_periods_string = local.runners_off_peak_periods_string
138132
runners_machine_autoscaling = local.runners_machine_autoscaling
139133
runners_root_size = var.runners_root_size
140134
runners_iam_instance_profile_name = var.runners_iam_instance_profile_name
@@ -171,7 +165,7 @@ data "aws_ami" "docker-machine" {
171165
}
172166

173167
resource "aws_autoscaling_group" "gitlab_runner_instance" {
174-
name = local.enable_asg_recreation ? "${aws_launch_template.gitlab_runner_instance.name}-asg" : "${var.environment}-as-group"
168+
name = var.enable_asg_recreation ? "${aws_launch_template.gitlab_runner_instance.name}-asg" : "${var.environment}-as-group"
175169
vpc_zone_identifier = var.subnet_ids_gitlab_runner
176170
min_size = "1"
177171
max_size = "1"
@@ -249,7 +243,7 @@ resource "aws_launch_template" "gitlab_runner_instance" {
249243
content {
250244
market_type = instance_market_options.value
251245
spot_options {
252-
max_price = var.runner_instance_spot_price
246+
max_price = var.runner_instance_spot_price == "on-demand-price" ? "" : var.runner_instance_spot_price
253247
}
254248
}
255249
}

template/runner-config.tpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,4 @@ sentry_dsn = "${sentry_dsn}"
6262
${docker_machine_options}
6363
]
6464

65-
${runners_off_peak_timezone}
66-
${runners_off_peak_idle_count}
67-
${runners_off_peak_idle_time}
68-
${runners_off_peak_periods_string}
6965
${runners_machine_autoscaling}

0 commit comments

Comments
 (0)