GitLab Runner fleet on AWS using the GitLab Runner and AWS Autoscaling services.
For more details, refer to the Solution Overview.
The terraform stack includes the following components:
- GitLab Job Webhook:
- Triggers the Step Functions workflow whenever new CI/CD jobs are added to the queue.
- Amazon DynamoDB:
- Used for state management and lock acquisition.
- Ensures that scaling operations are not duplicated or run concurrently.
- AWS Step Function:
- Manages workflow to process incoming requests from Gitlab Job Webhook and execute scaling action if required.
- Auto Scaling Group (ASG):
- Dynamically adjusts the number of GitLab Runner instances based on job demand.
- CloudWatch:
- Monitors metrics from the runner to analyze servers load and performance
- IAM Roles:
- Secures interactions between services.
Before using this stack, ensure you have the following AMI must be available in the target region: gitlab-runner-amazon
.
AMI can be built using the following command:
ansible-playbook ami_build.yml -e @aws_vars.yml
Before building the AMI you need the following secrets to be configured:
gl_runner_token
secret string stored in AWS Parameters Store, path:/gitlab_tokens
This secret is used to register new gitlab-runner instances in Gitlab on EC2 instance startup during execution of user-metadata scripts.
gitlab_secret_token
secret stored in secrets or specified explicitly as terraform variable
This secret is used to secure API calls from Gitlab Webhook to AWS API Gateway triggering Step Function to scale AWS Autoscaling Group on demand.
Name | Version |
---|---|
terraform | >= 1.0 |
aws | ~> 5.21 |
Name | Version |
---|---|
aws | 5.84.0 |
No modules.
Name | Description | Type | Default | Required |
---|---|---|---|---|
ami_user | The user to use for the AMI. | string |
"ec2-user" |
no |
api_gateway_stage_name | Name of the API Gateway deployment stage | string |
"dev" |
no |
aws_region | The AWS region to use. | string |
n/a | yes |
bastion_security_group_id | The ID of the bastion security group. | string |
"sg-0a1b2c3d4e5f6g7h8" |
no |
capacity_per_instance | The number of concurrent jobs per instance. | number |
null |
no |
desired_size | The desired number of instances in the autoscaling group. | number |
0 |
no |
environment_name | The name of the environment. | string |
n/a | yes |
fleet_instance_types | The instance types to use. | list(string) |
[ |
no |
gitlab_api_url | Target GitLab base API endpoint in the form of https://my.gitlab.server/api/v4/ . |
string |
"https://gitlab.com/api/v4/" |
no |
gitlab_secret_token | Secret token configured in GitLab webhook for validation | string |
"h&s8BdSbinDQ7h" |
no |
gl_cache_path | The IAM role to use for the instances. | string |
"cache" |
no |
gl_runner_tags | The tags to apply to the GitLab Runner. | list(string) |
null |
no |
group_id | The GitLab group ID. | number |
1347 |
no |
iam_role | The IAM role to use for the instances. | string |
"gitlab-runner" |
no |
idle_threshold | The number of seconds before a runner is considered idle. | number |
null |
no |
image_id | If unset or false (default), use the data lookup for the image | string |
null |
no |
image_name | The 'service_name' of the image to lookup | string |
"gitlab-runner-amazon" |
no |
key_name | The name of the key pair to use. | string |
"gitlab-runner-key" |
no |
max_size | The maximum number of instances in the autoscaling group. | number |
10 |
no |
min_size | The minimum number of instances in the autoscaling group. | number |
0 |
no |
private_subnet_ids | List of subnet IDs to launch resources in. | list(string) |
[ |
no |
root_disk_size | The size of the root disk in GB. | number |
30 |
no |
volume_delete_on_termination | Whether to delete the root volume on instance termination. | bool |
true |
no |
vpc_cidr | The CIDR block for the VPC. | string |
"172.31.0.0/16" |
no |
vpc_id | The ID of the VPC. | string |
n/a | yes |
Name | Description |
---|---|
api_gateway_invoke_url | n/a |