Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion docker_autoscaler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ resource "aws_autoscaling_group" "autoscaler" {
for_each = local.tags
content {
key = tag.key
value = tag.value
value = tag.key == "Name" ? "${tag.value}-runner-worker" : tag.value
propagate_at_launch = true
}
}
Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ locals {
docker_autoscaling_name = var.runner_worker.type == "docker-autoscaler" ? aws_autoscaling_group.autoscaler[0].name : ""
connector_config_user = var.runner_worker_docker_autoscaler.connector_config_user
runners_capacity_per_instance = var.runner_worker_docker_autoscaler.capacity_per_instance
delete_instances_on_shutdown = var.runner_worker_docker_autoscaler.delete_instances_on_shutdown
runners_max_use_count = var.runner_worker_docker_autoscaler.max_use_count
runners_max_instances = var.runner_worker.max_jobs

Expand Down Expand Up @@ -165,7 +166,7 @@ resource "aws_autoscaling_group" "gitlab_runner_instance" {

content {
key = tag.key
value = tag.value
value = tag.key == "Name" ? "${tag.value}-manager" : tag.value
propagate_at_launch = true
}
}
Expand Down
42 changes: 24 additions & 18 deletions template/gitlab-runner.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,25 @@ if [[ "${runners_executor}" == "docker-autoscaler" ]]; then
usermod -a -G docker ec2-user
service docker start

echo "Installing Docker fleeting plugin"
# Determine architecture
if [[ "$(uname -m)" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$(uname -m)" == "i686" ]]; then
ARCH="386"
elif [[ "$(uname -m)" == "armv7l" ]]; then
ARCH="arm"
elif [[ "$(uname -m)" == "aarch64" ]]; then
ARCH="arm64"
else
echo "Unsupported architecture"
exit 1
fi

wget "https://gitlab.com/gitlab-org/fleeting/plugins/aws/-/releases/v${fleeting_plugin_version}/downloads/fleeting-plugin-aws-$(uname -s | tr '[:upper:]' '[:lower:]')-$ARCH"
chmod +x fleeting-plugin-aws-*
mv fleeting-plugin-aws-* /bin/fleeting-plugin-aws
# TODO make it variable by external variable or by gitlab_runner_version variable
# echo "Installing Docker fleeting plugin"
# # Determine architecture
# if [[ "$(uname -m)" == "x86_64" ]]; then
# ARCH="amd64"
# elif [[ "$(uname -m)" == "i686" ]]; then
# ARCH="386"
# elif [[ "$(uname -m)" == "armv7l" ]]; then
# ARCH="arm"
# elif [[ "$(uname -m)" == "aarch64" ]]; then
# ARCH="arm64"
# else
# echo "Unsupported architecture"
# exit 1
# fi
#
# wget "https://gitlab.com/gitlab-org/fleeting/plugins/aws/-/releases/v${fleeting_plugin_version}/downloads/fleeting-plugin-aws-$(uname -s | tr '[:upper:]' '[:lower:]')-$ARCH"
# chmod +x fleeting-plugin-aws-*
# mv fleeting-plugin-aws-* /bin/fleeting-plugin-aws

mkdir ~/.aws
cat <<EOF > ~/.aws/config
Expand Down Expand Up @@ -297,6 +298,11 @@ if ! ( rpm -q gitlab-runner >/dev/null )
then
curl --fail --retry 6 -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash
yum install gitlab-runner-${gitlab_runner_version} -y

# TODO make it variable by external variable or by gitlab_runner_version variable
if [[ "${runners_executor}" == "docker-autoscaler" ]]; then
gitlab-runner fleeting install
fi
fi

#############################
Expand Down
5 changes: 4 additions & 1 deletion template/runner-docker-autoscaler-config.tftpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Autoscaler config
[runners.autoscaler]
plugin = "fleeting-plugin-aws"
# TODO make it variable by external variable or by gitlab_runner_version variable
plugin = "aws:latest"

capacity_per_instance = ${runners_capacity_per_instance}
update_interval = "${runners_update_interval}"
update_interval_when_expecting = "${runners_update_interval_when_expecting}"

delete_instances_on_shutdown = ${delete_instances_on_shutdown}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: does this make our Lambda function superfluous? We have it to kill the instances on shutdown of the agent.


max_use_count = ${runners_max_use_count}
max_instances = ${runners_max_instances}

Expand Down
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ variable "runner_worker_docker_autoscaler" {
max_use_count = Max job number that can run on a worker.
update_interval = The interval to check with the fleeting plugin for instance updates.
update_interval_when_expecting = The interval to check with the fleeting plugin for instance updates when expecting a state change.
delete_instances_on_shutdown = delete runner worker instance on shuting down gitlab-runner manager (default true).
instance_ready_command = Executes this command on each instance provisioned by the autoscaler to ensure that it is ready for use. A failure results in the instance being removed.
EOT
type = object({
Expand All @@ -754,6 +755,7 @@ variable "runner_worker_docker_autoscaler" {
max_use_count = optional(number, 100)
update_interval = optional(string, "1m")
update_interval_when_expecting = optional(string, "2s")
delete_instances_on_shutdown = optional(bool, true)
instance_ready_command = optional(string, "")
})
default = {}
Expand Down