Skip to content

Commit 56cf1ae

Browse files
committed
Merge branch 'release/2.1.0'
2 parents 2bcc61f + 9eae537 commit 56cf1ae

File tree

16 files changed

+227
-83
lines changed

16 files changed

+227
-83
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88

9+
## [2.1.0] - 2019-02-28
10+
- Bugfix: Shared cache is not working #33
11+
- Bugfix: Missing documentation makes setup fail #31
12+
- Added: Docker executor to run a single node runner, thanks to @msvechla
13+
914
## [2.0.0] - 2019-01-13
1015
- Changed: Replaced cache user by a instance profile to access the cache from the build
1116
- Changed: Update gitlab toml cache section, removed deprecated usages of s3
@@ -84,7 +89,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8489
- Update default AMI's to The latest Amazon Linux AMI 2017.09.1 - released on 2018-01-17.
8590
- Minor updates in the example
8691

87-
[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.0.0...HEAD
92+
[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.1.0...HEAD
93+
[2.1.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.0.0...2.1.0
8894
[2.0.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/1.8.0...2.0.0
8995
[1.8.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/1.7.0...1.8.0
9096
[1.7.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/1.6.0...1.7.0

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This repo contains a terraform module and example to run a [GitLab CI multi runn
88

99
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.
1010

11+
Besides the auto scaling option (docker+machine executor) the docker executor is supported as wel for a single node.
12+
1113
## Prerequisites
1214

1315
### Terraform
@@ -92,20 +94,21 @@ module "gitlab-runner" {
9294
ssh_public_key = "${file("${var.ssh_key_file}")}"
9395
9496
vpc_id = "${module.vpc.vpc_id}"
95-
subnet_id_gitlab_runner = "${element(module.vpc.private_subnets, 0)}"
97+
subnet_ids_gitlab_runner = "${module.vpc.private_subnets}"
9698
subnet_id_runners = "${element(module.vpc.private_subnets, 0)}"
9799
98-
runners_name = "${var.runner_name}"
99-
runners_gitlab_url = "${var.gitlab_url}"
100-
runners_token = "${var.runner_token}"
100+
runners_name = "${var.runner_name}"
101+
runners_gitlab_url = "${var.gitlab_url}"
102+
runners_token = "${var.runner_token}"
103+
104+
# Optional
105+
runners_off_peak_timezone = "Europe/Amsterdam"
106+
runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
101107
}
102108
```
103109

104110
## Inputs
105111

106-
All variables and defaults:
107-
108-
109112
| Name | Description | Type | Default | Required |
110113
|------|-------------|:----:|:-----:|:-----:|
111114
| allow_iam_service_linked_role_creation | Attach policy to runner instance to create service linked roles. | string | `true` | no |
@@ -114,6 +117,8 @@ All variables and defaults:
114117
| aws_region | AWS region. | string | - | yes |
115118
| cache_bucket_prefix | Prefix for s3 cache bucket name. | string | `` | no |
116119
| cache_expiration_days | Number of days before cache objects expires. | string | `1` | no |
120+
| cache_shared | Enables cache sharing between runners, false by default. | string | `false` | no |
121+
| create_runners_iam_instance_profile | | string | `true` | no |
117122
| docker_machine_instance_type | Instance type used for the instances hosting docker-machine. | string | `m4.large` | no |
118123
| 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 |
119124
| docker_machine_spot_price_bid | Spot price bid. | string | `0.04` | no |
@@ -132,6 +137,7 @@ All variables and defaults:
132137
| runners_idle_time | Idle time of the runners, will be used in the runner config.toml | string | `600` | no |
133138
| runners_image | Image to run builds, will be used in the runner config.toml | string | `docker:18.03.1-ce` | no |
134139
| runners_limit | Limit for the runners, will be used in the runner config.toml | string | `0` | no |
140+
| runners_machine_iam_instance_profile_name | IAM instance profile name to assign to the spot instance which runs the build. | string | `` | no |
135141
| runners_monitoring | Enable detailed cloudwatch monitoring for spot instances. | string | `false` | no |
136142
| runners_name | Name of the runner, will be used in the runner config.toml | string | - | yes |
137143
| runners_off_peak_idle_count | Off peak idle count of the runners, will be used in the runner config.toml. | string | `0` | no |
@@ -148,7 +154,7 @@ All variables and defaults:
148154
| runners_token | Token for the runner, will be used in the runner config.toml | string | - | yes |
149155
| runners_use_private_address | Restrict runners to use only private address | string | `true` | no |
150156
| ssh_public_key | Public SSH key used for the gitlab-runner ec2 instance. | string | - | yes |
151-
| subnet_id_gitlab_runner | Subnet used for hosting the gitlab-runner. | string | - | yes |
157+
| subnet_ids_gitlab_runner | Subnets used for hosting the gitlab-runner. | list | - | yes |
152158
| subnet_id_runners | Subnet used to hosts the docker-machine runners. | string | - | yes |
153159
| tags | Map of tags that will be added to created resources. By default resources will be taggen with name and environemnt. | map | `<map>` | no |
154160
| userdata_post_install | User-data script snippet to insert after gitlab-runner install | string | `` | no |
@@ -159,10 +165,9 @@ All variables and defaults:
159165

160166
| Name | Description |
161167
|------|-------------|
162-
| runner_agent role | ARN of the rule used for the ec2 instance for the GitLab runner agent. |
168+
| runner_agent_role | ARN of the rule used for the ec2 instance for the GitLab runner agent. |
163169
| runner_as_group_name | Name of the autoscaling group for the gitlab-runner instance |
164170
| runner_cache_bucket_arn | ARN of the S3 for the build cache. |
165-
| runner_role | ARN of the rule used for the docker machine runners. |
166171

167172
## Example
168173

examples/runner-default/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ module "runner" {
2525

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

28-
vpc_id = "${module.vpc.vpc_id}"
29-
subnet_id_gitlab_runner = "${element(module.vpc.private_subnets, 0)}"
30-
subnet_id_runners = "${element(module.vpc.private_subnets, 0)}"
28+
vpc_id = "${module.vpc.vpc_id}"
29+
subnet_ids_gitlab_runner = "${module.vpc.private_subnets}"
30+
subnet_id_runners = "${element(module.vpc.private_subnets, 0)}"
3131

3232
runners_name = "${var.runner_name}"
3333
runners_gitlab_url = "${var.gitlab_url}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.11.7

examples/runner-docker/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example - Runner - Docker runner
2+
3+
Example how create a gitlab runner using the docker executor on a single node, running in a private subnet.
4+
5+
## Prerequisite
6+
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.

examples/runner-docker/key.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "tls_private_key" "ssh" {
2+
algorithm = "RSA"
3+
}
4+
5+
resource "local_file" "public_ssh_key" {
6+
depends_on = ["tls_private_key.ssh"]
7+
8+
content = "${tls_private_key.ssh.public_key_openssh}"
9+
filename = "${var.public_ssh_key_filename}"
10+
}
11+
12+
resource "local_file" "private_ssh_key" {
13+
depends_on = ["tls_private_key.ssh"]
14+
15+
content = "${tls_private_key.ssh.private_key_pem}"
16+
filename = "${var.private_ssh_key_filename}"
17+
}
18+
19+
resource "null_resource" "file_permission" {
20+
depends_on = ["local_file.private_ssh_key"]
21+
22+
provisioner "local-exec" {
23+
command = "${format("chmod 600 %s", var.private_ssh_key_filename)}"
24+
}
25+
}

examples/runner-docker/main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module "vpc" {
2+
source = "terraform-aws-modules/vpc/aws"
3+
version = "1.37.0"
4+
5+
name = "vpc-${var.environment}"
6+
cidr = "10.1.0.0/16"
7+
8+
azs = ["eu-west-1a"]
9+
public_subnets = ["10.1.101.0/24"]
10+
11+
tags = {
12+
Environment = "${var.environment}"
13+
}
14+
}
15+
16+
module "runner" {
17+
source = "../../"
18+
19+
aws_region = "${var.aws_region}"
20+
environment = "${var.environment}"
21+
22+
ssh_public_key = "${local_file.public_ssh_key.content}"
23+
24+
runners_use_private_address = false
25+
26+
vpc_id = "${module.vpc.vpc_id}"
27+
subnet_ids_gitlab_runner = "${module.vpc.public_subnets}"
28+
subnet_id_runners = "${element(module.vpc.public_subnets, 0)}"
29+
30+
runners_executor = "docker"
31+
runners_name = "${var.runner_name}"
32+
runners_gitlab_url = "${var.gitlab_url}"
33+
runners_token = "${var.runner_token}"
34+
}

examples/runner-docker/providers.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
provider "aws" {
2+
region = "${var.aws_region}"
3+
version = "1.23"
4+
}
5+
6+
provider "template" {
7+
version = "1.0"
8+
}
9+
10+
provider "local" {
11+
version = "1.1"
12+
}
13+
14+
provider "null" {
15+
version = "1.0"
16+
}
17+
18+
provider "tls" {
19+
version = "1.1"
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
key_name = "gitlab-runner"
2+
3+
environment = "runner-docker"
4+
5+
aws_region = "eu-west-1"
6+
7+
# Add the following variables:
8+
runner_name = "docker.m3"
9+
10+
gitlab_url = "https://gitlab.com"
11+
12+
runner_token = "3939146918cced54ecf1dd08e6b87e"

examples/runner-docker/variables.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
variable "aws_region" {
2+
description = "AWS region."
3+
type = "string"
4+
default = "eu-west-1"
5+
}
6+
7+
variable "environment" {
8+
description = "A name that indentifies the environment, will used as prefix and for taggin."
9+
default = "ci-runners"
10+
type = "string"
11+
}
12+
13+
variable "public_ssh_key_filename" {
14+
default = "generated/id_rsa.pub"
15+
}
16+
17+
variable "private_ssh_key_filename" {
18+
default = "generated/id_rsa"
19+
}
20+
21+
variable "runner_name" {
22+
description = "Name of the runner, will be used in the runner config.toml"
23+
type = "string"
24+
}
25+
26+
variable "gitlab_url" {
27+
description = "URL of the gitlab instance to connect to."
28+
type = "string"
29+
}
30+
31+
variable "runner_token" {
32+
description = "Token for the runner, will be used in the runner config.toml"
33+
type = "string"
34+
}

examples/runner-public/main.tf

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,11 @@ module "runner" {
2323

2424
runners_use_private_address = false
2525

26-
vpc_id = "${module.vpc.vpc_id}"
27-
subnet_id_gitlab_runner = "${element(module.vpc.public_subnets, 0)}"
28-
subnet_id_runners = "${element(module.vpc.public_subnets, 0)}"
26+
vpc_id = "${module.vpc.vpc_id}"
27+
subnet_ids_gitlab_runner = "${module.vpc.public_subnets}"
28+
subnet_id_runners = "${element(module.vpc.public_subnets, 0)}"
2929

3030
runners_name = "${var.runner_name}"
3131
runners_gitlab_url = "${var.gitlab_url}"
3232
runners_token = "${var.runner_token}"
33-
34-
runners_off_peak_timezone = "Europe/Amsterdam"
35-
runners_off_peak_idle_count = 0
36-
runners_off_peak_idle_time = 60
37-
38-
# working 9 to 5 :)
39-
runners_off_peak_periods = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
4033
}

0 commit comments

Comments
 (0)