Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Feb 28, 2019
2 parents 2bcc61f + 9eae537 commit 56cf1ae
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 83 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.1.0] - 2019-02-28
- Bugfix: Shared cache is not working #33
- Bugfix: Missing documentation makes setup fail #31
- Added: Docker executor to run a single node runner, thanks to @msvechla

## [2.0.0] - 2019-01-13
- Changed: Replaced cache user by a instance profile to access the cache from the build
- Changed: Update gitlab toml cache section, removed deprecated usages of s3
Expand Down Expand Up @@ -84,7 +89,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Update default AMI's to The latest Amazon Linux AMI 2017.09.1 - released on 2018-01-17.
- Minor updates in the example

[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.0.0...HEAD
[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.1.0...HEAD
[2.1.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/1.8.0...2.0.0
[1.8.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/1.7.0...1.8.0
[1.7.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/1.6.0...1.7.0
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This repo contains a terraform module and example to run a [GitLab CI multi runn

The setup is based on the blog post: [Auto scale GitLab CI runners and save 90% on EC2 costs](https://about.gitlab.com/2017/11/23/autoscale-ci-runners/) The created runner will have by default a shared cache in S3 and logging is streamed to CloudWatch. The cache in S3 will expire in X days, see configuration. The logging can be disabled.

Besides the auto scaling option (docker+machine executor) the docker executor is supported as wel for a single node.

## Prerequisites

### Terraform
Expand Down Expand Up @@ -92,20 +94,21 @@ module "gitlab-runner" {
ssh_public_key = "${file("${var.ssh_key_file}")}"
vpc_id = "${module.vpc.vpc_id}"
subnet_id_gitlab_runner = "${element(module.vpc.private_subnets, 0)}"
subnet_ids_gitlab_runner = "${module.vpc.private_subnets}"
subnet_id_runners = "${element(module.vpc.private_subnets, 0)}"
runners_name = "${var.runner_name}"
runners_gitlab_url = "${var.gitlab_url}"
runners_token = "${var.runner_token}"
runners_name = "${var.runner_name}"
runners_gitlab_url = "${var.gitlab_url}"
runners_token = "${var.runner_token}"
# Optional
runners_off_peak_timezone = "Europe/Amsterdam"
runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
}
```

## Inputs

All variables and defaults:


| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| allow_iam_service_linked_role_creation | Attach policy to runner instance to create service linked roles. | string | `true` | no |
Expand All @@ -114,6 +117,8 @@ All variables and defaults:
| aws_region | AWS region. | string | - | yes |
| cache_bucket_prefix | Prefix for s3 cache bucket name. | string | `` | no |
| cache_expiration_days | Number of days before cache objects expires. | string | `1` | no |
| cache_shared | Enables cache sharing between runners, false by default. | string | `false` | no |
| create_runners_iam_instance_profile | | string | `true` | no |
| docker_machine_instance_type | Instance type used for the instances hosting docker-machine. | string | `m4.large` | no |
| docker_machine_options | Additional to set options for docker machien. Each element of the list should be key and value. E.g. '["--amazonec2-zone=a"]' | list | `<list>` | no |
| docker_machine_spot_price_bid | Spot price bid. | string | `0.04` | no |
Expand All @@ -132,6 +137,7 @@ All variables and defaults:
| runners_idle_time | Idle time of the runners, will be used in the runner config.toml | string | `600` | no |
| runners_image | Image to run builds, will be used in the runner config.toml | string | `docker:18.03.1-ce` | no |
| runners_limit | Limit for the runners, will be used in the runner config.toml | string | `0` | no |
| runners_machine_iam_instance_profile_name | IAM instance profile name to assign to the spot instance which runs the build. | string | `` | no |
| runners_monitoring | Enable detailed cloudwatch monitoring for spot instances. | string | `false` | no |
| runners_name | Name of the runner, will be used in the runner config.toml | string | - | yes |
| runners_off_peak_idle_count | Off peak idle count of the runners, will be used in the runner config.toml. | string | `0` | no |
Expand All @@ -148,7 +154,7 @@ All variables and defaults:
| runners_token | Token for the runner, will be used in the runner config.toml | string | - | yes |
| runners_use_private_address | Restrict runners to use only private address | string | `true` | no |
| ssh_public_key | Public SSH key used for the gitlab-runner ec2 instance. | string | - | yes |
| subnet_id_gitlab_runner | Subnet used for hosting the gitlab-runner. | string | - | yes |
| subnet_ids_gitlab_runner | Subnets used for hosting the gitlab-runner. | list | - | yes |
| subnet_id_runners | Subnet used to hosts the docker-machine runners. | string | - | yes |
| tags | Map of tags that will be added to created resources. By default resources will be taggen with name and environemnt. | map | `<map>` | no |
| userdata_post_install | User-data script snippet to insert after gitlab-runner install | string | `` | no |
Expand All @@ -159,10 +165,9 @@ All variables and defaults:

| Name | Description |
|------|-------------|
| runner_agent role | ARN of the rule used for the ec2 instance for the GitLab runner agent. |
| runner_agent_role | ARN of the rule used for the ec2 instance for the GitLab runner agent. |
| runner_as_group_name | Name of the autoscaling group for the gitlab-runner instance |
| runner_cache_bucket_arn | ARN of the S3 for the build cache. |
| runner_role | ARN of the rule used for the docker machine runners. |

## Example

Expand Down
6 changes: 3 additions & 3 deletions examples/runner-default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ module "runner" {

ssh_public_key = "${local_file.public_ssh_key.content}"

vpc_id = "${module.vpc.vpc_id}"
subnet_id_gitlab_runner = "${element(module.vpc.private_subnets, 0)}"
subnet_id_runners = "${element(module.vpc.private_subnets, 0)}"
vpc_id = "${module.vpc.vpc_id}"
subnet_ids_gitlab_runner = "${module.vpc.private_subnets}"
subnet_id_runners = "${element(module.vpc.private_subnets, 0)}"

runners_name = "${var.runner_name}"
runners_gitlab_url = "${var.gitlab_url}"
Expand Down
1 change: 1 addition & 0 deletions examples/runner-docker/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.11.7
6 changes: 6 additions & 0 deletions examples/runner-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example - Runner - Docker runner

Example how create a gitlab runner using the docker executor on a single node, running in a private subnet.

## Prerequisite
The terraform version is managed using [tfenv](https://github.com/Zordrak/tfenv). If you are not using tfenv please check `.terraform-version` for the tested version.
25 changes: 25 additions & 0 deletions examples/runner-docker/key.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "tls_private_key" "ssh" {
algorithm = "RSA"
}

resource "local_file" "public_ssh_key" {
depends_on = ["tls_private_key.ssh"]

content = "${tls_private_key.ssh.public_key_openssh}"
filename = "${var.public_ssh_key_filename}"
}

resource "local_file" "private_ssh_key" {
depends_on = ["tls_private_key.ssh"]

content = "${tls_private_key.ssh.private_key_pem}"
filename = "${var.private_ssh_key_filename}"
}

resource "null_resource" "file_permission" {
depends_on = ["local_file.private_ssh_key"]

provisioner "local-exec" {
command = "${format("chmod 600 %s", var.private_ssh_key_filename)}"
}
}
34 changes: 34 additions & 0 deletions examples/runner-docker/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "1.37.0"

name = "vpc-${var.environment}"
cidr = "10.1.0.0/16"

azs = ["eu-west-1a"]
public_subnets = ["10.1.101.0/24"]

tags = {
Environment = "${var.environment}"
}
}

module "runner" {
source = "../../"

aws_region = "${var.aws_region}"
environment = "${var.environment}"

ssh_public_key = "${local_file.public_ssh_key.content}"

runners_use_private_address = false

vpc_id = "${module.vpc.vpc_id}"
subnet_ids_gitlab_runner = "${module.vpc.public_subnets}"
subnet_id_runners = "${element(module.vpc.public_subnets, 0)}"

runners_executor = "docker"
runners_name = "${var.runner_name}"
runners_gitlab_url = "${var.gitlab_url}"
runners_token = "${var.runner_token}"
}
20 changes: 20 additions & 0 deletions examples/runner-docker/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
provider "aws" {
region = "${var.aws_region}"
version = "1.23"
}

provider "template" {
version = "1.0"
}

provider "local" {
version = "1.1"
}

provider "null" {
version = "1.0"
}

provider "tls" {
version = "1.1"
}
12 changes: 12 additions & 0 deletions examples/runner-docker/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
key_name = "gitlab-runner"

environment = "runner-docker"

aws_region = "eu-west-1"

# Add the following variables:
runner_name = "docker.m3"

gitlab_url = "https://gitlab.com"

runner_token = "3939146918cced54ecf1dd08e6b87e"
34 changes: 34 additions & 0 deletions examples/runner-docker/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
variable "aws_region" {
description = "AWS region."
type = "string"
default = "eu-west-1"
}

variable "environment" {
description = "A name that indentifies the environment, will used as prefix and for taggin."
default = "ci-runners"
type = "string"
}

variable "public_ssh_key_filename" {
default = "generated/id_rsa.pub"
}

variable "private_ssh_key_filename" {
default = "generated/id_rsa"
}

variable "runner_name" {
description = "Name of the runner, will be used in the runner config.toml"
type = "string"
}

variable "gitlab_url" {
description = "URL of the gitlab instance to connect to."
type = "string"
}

variable "runner_token" {
description = "Token for the runner, will be used in the runner config.toml"
type = "string"
}
13 changes: 3 additions & 10 deletions examples/runner-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,11 @@ module "runner" {

runners_use_private_address = false

vpc_id = "${module.vpc.vpc_id}"
subnet_id_gitlab_runner = "${element(module.vpc.public_subnets, 0)}"
subnet_id_runners = "${element(module.vpc.public_subnets, 0)}"
vpc_id = "${module.vpc.vpc_id}"
subnet_ids_gitlab_runner = "${module.vpc.public_subnets}"
subnet_id_runners = "${element(module.vpc.public_subnets, 0)}"

runners_name = "${var.runner_name}"
runners_gitlab_url = "${var.gitlab_url}"
runners_token = "${var.runner_token}"

runners_off_peak_timezone = "Europe/Amsterdam"
runners_off_peak_idle_count = 0
runners_off_peak_idle_time = 60

# working 9 to 5 :)
runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
}
Loading

0 comments on commit 56cf1ae

Please sign in to comment.