Skip to content

Commit

Permalink
feat: shell is also a supported executor
Browse files Browse the repository at this point in the history
  • Loading branch information
lmilbaum committed Nov 12, 2023
1 parent d3e3b1f commit 053c294
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 121 deletions.
116 changes: 116 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,122 @@ locals {
]

docker_machine_adds_name_tag = signum(sum(local.docker_machine_version_test)) <= 0

template_user_data = templatefile("${path.module}/template/user-data.tftpl",
{
eip = var.runner_instance.use_eip ? local.template_eip : ""
logging = var.runner_cloudwatch.enable ? local.logging_user_data : ""
gitlab_runner = local.template_gitlab_runner
user_data_trace_log = var.debug.trace_runner_user_data
yum_update = var.runner_install.yum_update ? local.file_yum_update : ""
extra_config = var.runner_install.start_script
})

file_yum_update = file("${path.module}/template/yum_update.tftpl")

template_eip = templatefile("${path.module}/template/eip.tftpl", {
eip = join(",", [for eip in aws_eip.gitlab_runner : eip.public_ip])
})

template_gitlab_runner = templatefile("${path.module}/template/gitlab-runner.tftpl",
{
gitlab_runner_version = var.runner_gitlab.runner_version
docker_machine_version = var.runner_install.docker_machine_version
docker_machine_download_url = var.runner_install.docker_machine_download_url
runners_config = local.template_runner_config
runners_userdata = var.runner_worker_docker_machine_instance.start_script
runners_executor = var.runner_worker.type
runners_install_amazon_ecr_credential_helper = var.runner_install.amazon_ecr_credential_helper
curl_cacert = length(var.runner_gitlab.certificate) > 0 ? "--cacert /etc/gitlab-runner/certs/gitlab.crt" : ""
pre_install_certificates = local.pre_install_certificates
pre_install = var.runner_install.pre_install_script
post_install = var.runner_install.post_install_script
runners_gitlab_url = var.runner_gitlab.url
runners_token = var.runner_gitlab.registration_token
secure_parameter_store_gitlab_runner_registration_token_name = var.runner_gitlab_registration_token_secure_parameter_store_name
secure_parameter_store_runner_token_key = local.secure_parameter_store_runner_token_key
secure_parameter_store_runner_sentry_dsn = local.secure_parameter_store_runner_sentry_dsn
secure_parameter_store_gitlab_token_name = var.runner_gitlab.access_token_secure_parameter_store_name
secure_parameter_store_region = data.aws_region.current.name
gitlab_runner_registration_token = var.runner_gitlab_registration_config.registration_token
gitlab_runner_description = var.runner_gitlab_registration_config["description"]
gitlab_runner_tag_list = var.runner_gitlab_registration_config["tag_list"]
gitlab_runner_locked_to_project = var.runner_gitlab_registration_config["locked_to_project"]
gitlab_runner_run_untagged = var.runner_gitlab_registration_config["run_untagged"]
gitlab_runner_maximum_timeout = var.runner_gitlab_registration_config["maximum_timeout"]
gitlab_runner_type = var.runner_gitlab_registration_config["type"]
gitlab_runner_group_id = var.runner_gitlab_registration_config["group_id"]
gitlab_runner_project_id = var.runner_gitlab_registration_config["project_id"]
gitlab_runner_access_level = var.runner_gitlab_registration_config.access_level
sentry_dsn = var.runner_manager.sentry_dsn
public_key = var.runner_worker_docker_machine_fleet.enable == true ? tls_private_key.fleet[0].public_key_openssh : ""
use_fleet = var.runner_worker_docker_machine_fleet.enable
private_key = var.runner_worker_docker_machine_fleet.enable == true ? tls_private_key.fleet[0].private_key_pem : ""
use_new_runner_authentication_gitlab_16 = var.runner_gitlab_registration_config.type != ""
})

template_runner_config = templatefile("${path.module}/template/runner-config.tftpl",
{
aws_region = data.aws_region.current.name
gitlab_url = var.runner_gitlab.url
gitlab_clone_url = var.runner_gitlab.url_clone
tls_ca_file = length(var.runner_gitlab.certificate) > 0 ? "tls-ca-file=\"/etc/gitlab-runner/certs/gitlab.crt\"" : ""
runners_machine_autoscaling = [for config in var.runner_worker_docker_machine_autoscaling_options : {
for key, value in config :
# Convert key from snake_case to PascalCase which is the casing for this section.
join("", [for subkey in split("_", key) : title(subkey)]) => jsonencode(value) if value != null
}]
runners_vpc_id = var.vpc_id
runners_subnet_id = var.subnet_id
runners_subnet_ids = length(var.runner_worker_docker_machine_instance.subnet_ids) > 0 ? var.runner_worker_docker_machine_instance.subnet_ids : [var.subnet_id]
runners_aws_zone = data.aws_availability_zone.runners.name_suffix
runners_instance_types = var.runner_worker_docker_machine_instance.types
runners_spot_price_bid = var.runner_worker_docker_machine_instance_spot.max_price == "on-demand-price" || var.runner_worker_docker_machine_instance_spot.max_price == null ? "" : var.runner_worker_docker_machine_instance_spot.max_price
runners_ami = var.runner_worker.type == "docker+machine" ? data.aws_ami.docker-machine[0].id : ""
runners_security_group_name = var.runner_worker.type == "docker+machine" ? aws_security_group.docker_machine[0].name : ""
runners_max_growth_rate = var.runner_worker_docker_machine_instance.max_growth_rate
runners_monitoring = var.runner_worker_docker_machine_instance.monitoring
runners_ebs_optimized = var.runner_worker_docker_machine_instance.ebs_optimized
runners_instance_profile = var.runner_worker.type == "docker+machine" ? aws_iam_instance_profile.docker_machine[0].name : ""
docker_machine_options = length(local.docker_machine_options_string) == 1 ? "" : local.docker_machine_options_string
docker_machine_name = format("%s-%s", local.runner_tags_merged["Name"], "%s") # %s is always needed
runners_name = var.runner_instance.name
runners_tags = replace(replace(local.runner_tags_string, ",,", ","), "/,$/", "")
runners_token = var.runner_gitlab.registration_token
runners_userdata = var.runner_worker_docker_machine_instance.start_script
runners_executor = var.runner_worker.type
runners_limit = var.runner_worker.max_jobs
runners_concurrent = var.runner_manager.maximum_concurrent_jobs
runners_pull_policies = local.runners_pull_policies
runners_idle_count = var.runner_worker_docker_machine_instance.idle_count
runners_idle_time = var.runner_worker_docker_machine_instance.idle_time
runners_max_builds = local.runners_max_builds_string
runners_root_size = var.runner_worker_docker_machine_instance.root_size
runners_volume_type = var.runner_worker_docker_machine_instance.volume_type
runners_iam_instance_profile_name = var.runner_worker_docker_machine_role.profile_name
runners_use_private_address_only = var.runner_worker_docker_machine_instance.private_address_only
runners_use_private_address = !var.runner_worker_docker_machine_instance.private_address_only
runners_request_spot_instance = var.runner_worker_docker_machine_instance_spot.enable
runners_environment_vars = jsonencode(var.runner_worker.environment_variables)
runners_pre_build_script = var.runner_worker_gitlab_pipeline.pre_build_script
runners_post_build_script = var.runner_worker_gitlab_pipeline.post_build_script
runners_pre_clone_script = var.runner_worker_gitlab_pipeline.pre_clone_script
runners_request_concurrency = var.runner_worker.request_concurrency
runners_output_limit = var.runner_worker.output_limit
runners_check_interval = var.runner_manager.gitlab_check_interval
runners_volumes_tmpfs = join("\n", [for v in var.runner_worker_docker_volumes_tmpfs : format("\"%s\" = \"%s\"", v.volume, v.options)])
runners_services_volumes_tmpfs = join("\n", [for v in var.runner_worker_docker_services_volumes_tmpfs : format("\"%s\" = \"%s\"", v.volume, v.options)])
runners_docker_services = local.runners_docker_services
runners_docker_options = local.runners_docker_options_toml
bucket_name = local.bucket_name
shared_cache = var.runner_worker_cache.shared
sentry_dsn = var.runner_manager.sentry_dsn
prometheus_listen_address = var.runner_manager.prometheus_listen_address
auth_type = var.runner_worker_cache.authentication_type
use_fleet = var.runner_worker_docker_machine_fleet.enable
launch_template = var.runner_worker_docker_machine_fleet.enable == true ? aws_launch_template.fleet_gitlab_runner[0].name : ""
}
)
}

resource "local_file" "config_toml" {
Expand Down
Loading

0 comments on commit 053c294

Please sign in to comment.