Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Mar 29, 2019
2 parents e6d262a + 0f07a0d commit 88e0446
Show file tree
Hide file tree
Showing 31 changed files with 462 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
config-terraform.sh

*.out
example/*.secrets*.tfvars
*.secrets*.tfvars
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [3.0.0] - 2019-03-29
- Changed: The runner will register itself based on the registration token. No need to preregister the runner before running terraform. See the [README](README.md) for configuration and migration. #33

## [2.3.0] - 2019-03-27
- Bugfix: Added a profile for the docker machine runners. #41
- Changed: Changed the name of runner instance, added `docker-machine` to the name.
Expand Down Expand Up @@ -102,7 +105,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.3.0...HEAD
[Unreleased]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/3.0.0...HEAD
[3.0.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.3.0...3.0.0
[2.3.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.2.1...2.3.0
[2.2.1]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.2.0...2.2.1
[2.2.0]: https://github.com/npalm/terraform-aws-gitlab-runner/compare/2.1.0...2.2.0
Expand Down
165 changes: 103 additions & 62 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform.tfvars
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Examples

Please see the readme in per example for more details:

- [runner-default] The default setup, private subnet, auto register, runner on spot instances.
- [runner-public] Runner in a public subnet, auto register, runner on spot instances.
- [runner-docker] Runners run on the same instance as the agent.
- [runner-pre-registered] Runner needs to be preregistered, old setup DEPRECATED.
4 changes: 2 additions & 2 deletions examples/runner-default/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Example - Runner - Private subnets
# Example - Spot Runner - Private subnets

Example how create a gitlab runner, running in a private subnet.
Example how to run builds on spot instnaces in a private subent.

## 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.
13 changes: 11 additions & 2 deletions examples/runner-default/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "1.59.0"
version = "1.60.0"

name = "vpc-${var.environment}"
cidr = "10.0.0.0/16"
Expand All @@ -11,6 +11,7 @@ module "vpc" {

enable_nat_gateway = true
single_nat_gateway = true
enable_s3_endpoint = true

tags = {
Environment = "${var.environment}"
Expand All @@ -31,7 +32,15 @@ module "runner" {

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

gitlab_runner_registration_config = {
registration_token = "${var.registration_token}"
tag_list = "docker_spot_runner"
description = "runner default - auto"
locked_to_project = "true"
run_untagged = "false"
maximum_timeout = "3600"
}

runners_off_peak_timezone = "Europe/Amsterdam"
runners_off_peak_idle_count = 0
Expand Down
4 changes: 2 additions & 2 deletions examples/runner-default/providers.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
provider "aws" {
region = "${var.aws_region}"
version = "2.2"
version = "2.4"
}

provider "template" {
version = "2.1"
}

provider "local" {
version = "1.1"
version = "1.2"
}

provider "null" {
Expand Down
12 changes: 0 additions & 12 deletions examples/runner-default/terraform.tfvars

This file was deleted.

9 changes: 4 additions & 5 deletions examples/runner-default/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ variable "aws_region" {

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

variable "public_ssh_key_filename" {
Expand All @@ -21,14 +21,13 @@ variable "private_ssh_key_filename" {
variable "runner_name" {
description = "Name of the runner, will be used in the runner config.toml"
type = "string"
default = "default-auto"
}

variable "gitlab_url" {
description = "URL of the gitlab instance to connect to."
type = "string"
default = "https://gitlab.com"
}

variable "runner_token" {
description = "Token for the runner, will be used in the runner config.toml"
type = "string"
}
variable "registration_token" {}
15 changes: 12 additions & 3 deletions examples/runner-docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module "vpc" {
name = "vpc-${var.environment}"
cidr = "10.1.0.0/16"

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

tags = {
Environment = "${var.environment}"
Expand All @@ -30,5 +31,13 @@ module "runner" {
runners_executor = "docker"
runners_name = "${var.runner_name}"
runners_gitlab_url = "${var.gitlab_url}"
runners_token = "${var.runner_token}"

gitlab_runner_registration_config = {
registration_token = "${var.registration_token}"
tag_list = "docker_runner"
description = "runner docker - auto"
locked_to_project = "true"
run_untagged = "false"
maximum_timeout = "3600"
}
}
4 changes: 2 additions & 2 deletions examples/runner-docker/providers.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
provider "aws" {
region = "${var.aws_region}"
version = "2.2"
version = "2.4"
}

provider "template" {
version = "2.1"
}

provider "local" {
version = "1.1"
version = "1.2"
}

provider "null" {
Expand Down
12 changes: 0 additions & 12 deletions examples/runner-docker/terraform.tfvars

This file was deleted.

9 changes: 4 additions & 5 deletions examples/runner-docker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variable "aws_region" {

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

Expand All @@ -21,14 +21,13 @@ variable "private_ssh_key_filename" {
variable "runner_name" {
description = "Name of the runner, will be used in the runner config.toml"
type = "string"
default = "docker"
}

variable "gitlab_url" {
description = "URL of the gitlab instance to connect to."
type = "string"
default = "https://www.gitlab.com"
}

variable "runner_token" {
description = "Token for the runner, will be used in the runner config.toml"
type = "string"
}
variable "registration_token" {}
1 change: 1 addition & 0 deletions examples/runner-pre-registered/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.11.13
6 changes: 6 additions & 0 deletions examples/runner-pre-registered/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example - Spot Runner - Private subnets

This is the previous default example. For this example you need to register the runner before running terraform and provide the runner token. Since version 3+ the runner can register itself by providing the registration token. This examples is to show case backwards compatibility.

## 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.
Empty file.
25 changes: 25 additions & 0 deletions examples/runner-pre-registered/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)}"
}
}
44 changes: 44 additions & 0 deletions examples/runner-pre-registered/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "1.60.0"

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

azs = ["eu-west-1a"]
private_subnets = ["10.0.1.0/24"]
public_subnets = ["10.0.101.0/24"]

enable_nat_gateway = true
single_nat_gateway = true

enable_s3_endpoint = true

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

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

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

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

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}"
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 *\"]"
}
20 changes: 20 additions & 0 deletions examples/runner-pre-registered/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
provider "aws" {
region = "${var.aws_region}"
version = "2.4"
}

provider "template" {
version = "2.1"
}

provider "local" {
version = "1.2"
}

provider "null" {
version = "2.1"
}

provider "tls" {
version = "1.2"
}
34 changes: 34 additions & 0 deletions examples/runner-pre-registered/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"
}
2 changes: 1 addition & 1 deletion examples/runner-public/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Example - Runner - Public subnets
# Example - Spot Runner - Public subnets

Example how create a gitlab runner, running in a public subnet.

Expand Down
12 changes: 10 additions & 2 deletions examples/runner-public/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "1.59.0"
version = "1.60.0"

name = "vpc-${var.environment}"
cidr = "10.1.0.0/16"
Expand Down Expand Up @@ -30,5 +30,13 @@ module "runner" {

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

gitlab_runner_registration_config = {
registration_token = "${var.registration_token}"
tag_list = "docker_spot_runner"
description = "runner public - auto"
locked_to_project = "true"
run_untagged = "false"
maximum_timeout = "3600"
}
}
Loading

0 comments on commit 88e0446

Please sign in to comment.