Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 21 additions & 42 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,54 +145,33 @@ module "runner" {

### Scenario: Use of Docker autoscaler

As docker machine is no longer maintained by docker, gitlab recently developed docker autoscaler to replace docker machine
(still in beta). An option is available to test it out.

Tested with amazon-linux-2-x86 as runner manager and ubuntu-server-22-lts-x86 for runner worker. The following commands have been
added to the original AMI for the runner worker for the docker-autoscaler to work correctly:

```bash
# Install docker
# Add Docker's official GPG key:
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update

apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
usermod -aG docker ubuntu
```
As docker machine is no longer maintained by Docker, GitLab recently developed docker autoscaler to replace docker machine.

Tested with amazon-linux-2-x86 as runner manager and ubuntu-server-22-lts-x86 for runner worker. The main problem is to find an AMI
which has the Docker engine pre-installed. This means that any "base" Amazon Linux or Ubuntu AMI cannot work.

There is a project in the early alpha phase to support you to build your own AMI: https://github.com/cattle-ops/AWS-Fleeting-Plugin-AMI

#### Docker Autoscaler Configuration

```hcl
module "runner" {
# https://registry.terraform.io/modules/cattle-ops/gitlab-runner/aws/
source = "cattle-ops/gitlab-runner/aws"
source = "cattle-ops/gitlab-runner/aws"

vpc_id = module.vpc.vpc_id
vpc_id = module.vpc.vpc_id
subnet_id = element(module.vpc.private_subnets, 0)

runner_gitlab = {
tag_list = "runner_worker"
type = "instance"
url = "https://gitlab.com"

preregistered_runner_token_ssm_parameter_name = "my-gitlab-runner-token-ssm-parameter-name"
}
runner_manager = {
maximum_concurrent_jobs = 5

runner_ami_filter = {
name = ["amazon-linux-2-x86"]
}

runner_ami_owners = ["amazon"]

runner_worker = {
max_jobs = 5
request_concurrency = 5
Expand All @@ -202,19 +181,19 @@ module "runner" {
runner_worker_docker_autoscaler_asg = {
on_demand_percentage_above_base_capacity = 0
enable_mixed_instances_policy = true
idle_time = 600
subnet_ids = vpc.private_subnets_ids
types = ["t3a.medium", "t3.medium"]
volume_type = "gp3"
private_address_only = true
ebs_optimized = true
root_size = 40
subnet_ids = module.vpc.private_subnets
types = ["t3a.medium", "t3.medium"]
}

runner_worker_docker_autoscaler = {
connector_config_user = "ubuntu"
connector_config_user = "ubuntu" # this user id is used to connect to the instance via SSH
}

runner_worker_docker_autoscaler_ami_filter = {
name = ["ubuntu-server-22-lts-x86-*"]
}

runner_worker_docker_autoscaler_ami_owners = ["099720109477"] # Canonical
}
```

Expand Down
26 changes: 6 additions & 20 deletions examples/runner-fleeting-plugin/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ module "runner" {
subnet_id = element(module.vpc.private_subnets, 0)

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

runner_networking = {
allow_incoming_ping_security_group_ids = [data.aws_security_group.default.id]
name = var.runner_name
ssm_access = true
}

runner_gitlab = {
Expand All @@ -76,23 +71,14 @@ module "runner" {
max_jobs = 10
}

runner_worker_gitlab_pipeline = {
pre_build_script = <<EOT
'''
echo 'multiline 1'
echo 'multiline 2'
'''
EOT
post_build_script = "\"echo 'single line'\""
}

runner_worker_docker_autoscaler = {
fleeting_plugin_version = "1.0.0"
connector_config_user = "ubuntu" # this user id is used to connect to the instance via SSH
}

runner_worker_docker_autoscaler_ami_owners = ["591542846629"] # FIXME Change to your AWS account ID
# FIXME: this AMI is outdated, but has Docker installed, which is needed. There are no other AMIs available with Docker pre-installed.
runner_worker_docker_autoscaler_ami_owners = ["099720109477"] # Canonical
runner_worker_docker_autoscaler_ami_filter = {
name = ["al2023-ami-ecs-hvm-2023.0.20240723-kernel-6.1-x86_64"] # FIXME Change to your AMI name
name = ["ubuntu-server-22-lts-x86-*"]
}

runner_worker_docker_autoscaler_instance = {
Expand Down