Skip to content

Commit 0b1299b

Browse files
authored
feat!: migrate to ARC (terraform-google-modules#173)
1 parent 3ac2822 commit 0b1299b

39 files changed

+761
-779
lines changed

README.md

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,41 @@
11
# terraform-google-github-actions-runners
2-
32
[![awesome-runners](https://img.shields.io/badge/listed%20on-awesome--runners-blue.svg)](https://github.com/jonico/awesome-runners)
43

5-
Using these Terraform modules you can quickly deploy Self Hosted Github Runners for jobs in your GitHub Actions workflows
6-
7-
## [Self Hosted Runners on GKE](modules/gh-runner-gke/README.md)
8-
9-
The `gh-runner-gke` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using GKE.
10-
11-
This includes
12-
13-
- Enabling necessary APIs
14-
- VPC
15-
- GKE Cluster
16-
- Kubernetes Secret
17-
18-
Below are some examples:
4+
## Description
5+
Using these Terraform modules you can quickly deploy self-hosted GitHub Runners for jobs in your GitHub Actions workflows
196

20-
### [Self Hosted runners on GKE that support Docker Workflows](examples/gh-runner-gke-dind/README.md)
7+
## Modules
218

22-
This example shows how to deploy Self Hosted Runners on GKE that supports Docker Workflows.
9+
### [Self Hosted Runners on GKE](modules/gh-runner-gke/)
10+
The `gh-runner-gke` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using GKE. This module follows the guidance for using [Actions Runner Controller](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners-with-actions-runner-controller/quickstart-for-actions-runner-controller#installing-actions-runner-controller) provided by GitHub
2311

24-
### [Simple Self Hosted Runners on GKE](examples/gh-runner-gke-simple/README.md)
25-
26-
This example shows how to deploy a simple GKE Self Hosted Runner.
12+
Examples:
13+
- [Simple Self Hosted Runners on GKE](examples/gh-runner-gke-simple/)
14+
- [Self Hosted runners on GKE that support Docker Workflows](examples/gh-runner-gke-dind/)
15+
- [Self Hosted runners on GKE that support Docker Workflows in rootless configuration](examples/gh-runner-gke-dind-rootless/)
2716

2817
More examples of [Self Hosted Runners on GKE/Anthos](https://github.com/github-developer/self-hosted-runners-anthos).
2918

30-
## [Self Hosted Runners on Managed Instance Groups using VMs](modules/gh-runner-mig-vm/README.md)
3119

20+
### [Self Hosted Runners on Managed Instance Groups using VMs](modules/gh-runner-mig-vm/)
3221
The `gh-runner-mig-vm` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using Managed Instance Groups.
3322

34-
This includes
35-
36-
- Enabling necessary APIs
37-
- VPC
38-
- NAT & Cloud Router
39-
- Service Account for MIG
40-
- MIG Instance Template
41-
- MIG Instance Manager
42-
- FW Rules
43-
- Secret Manager Secret
44-
45-
Deployment of Managed Instance Groups requires a [Google VM image](https://cloud.google.com/compute/docs/images) with a startup script that downloads and configures the Runner or a pre-baked image with the runner installed.
46-
47-
Below are some examples:
48-
49-
### [Simple Self Hosted Runner on MIG VMs](examples/gh-runner-mig-native-simple/README.md)
50-
51-
This example shows how to deploy a MIG Self Hosted Runner with startup scripts.
52-
53-
### [Self Hosted Runner on MIG VMs from Packer Image](examples/gh-runner-mig-native-packer/README.md)
54-
55-
This example shows how to deploy a MIG Self Hosted Runner with an image pre-baked using Packer.
56-
57-
## [Self Hosted Runners on Managed Instance Groups using Container VMs](modules/gh-runner-mig-container-vm/README.md)
23+
Examples:
24+
- [Simple Self Hosted Runner on MIG VMs](examples/gh-runner-mig-native-simple/)
25+
- [Self Hosted Runner on MIG VMs from Packer Image](examples/gh-runner-mig-native-packer/)
5826

27+
### [Self Hosted Runners on Managed Instance Groups using Container VMs](modules/gh-runner-mig-container-vm/)
5928
The `gh-runner-mig-container-vm` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using Managed Instance Groups.
6029

61-
This includes
62-
63-
- Enabling necessary APIs
64-
- VPC
65-
- NAT & Cloud Router
66-
- MIG Container Instance Template
67-
- MIG Instance Manager
68-
- FW Rules
30+
Examples:
31+
- [Simple Self Hosted Runner on MIG Container VMs](examples/gh-runner-mig-container-vm-simple/)
32+
- [Self Hosted runners on MIG Container VMs that support Docker Workflows](examples/gh-runner-mig-container-vm-dind/)
6933

70-
Below are some examples:
34+
### [GitHub OIDC](modules/gh-oidc/)
35+
This module handles the opinionated creation of infrastructure necessary to configure [Workload Identity pools](https://cloud.google.com/iam/docs/workload-identity-federation#pools) and [providers](https://cloud.google.com/iam/docs/workload-identity-federation#providers) for authenticating to GCP using GitHub Actions OIDC tokens.
7136

72-
### [Self Hosted runners on MIG Container VMs that support Docker Workflows](examples/gh-runner-mig-container-vm-dind/README.md)
73-
74-
This example shows how to deploy a Self Hosted Runner that supports Docker Workflows on MIG Container VMs.
75-
76-
### [Simple Self Hosted Runner on MIG Container VMs](examples/gh-runner-mig-container-vm-simple/README.md)
77-
78-
This example shows how to deploy a Self Hosted Runner on MIG Container VMs.
37+
Examples:
38+
- [Simple Workload Identity configuration for GitHub OIDC](examples/oidc-simple/)
7939

8040

8141
## Requirements
@@ -94,5 +54,11 @@ The following dependencies must be available:
9454
Refer to the [contribution guidelines](./CONTRIBUTING.md) for
9555
information on contributing to this module.
9656

57+
[iam-module]: https://registry.terraform.io/modules/terraform-google-modules/iam/google
58+
[project-factory-module]: https://registry.terraform.io/modules/terraform-google-modules/project-factory/google
9759
[terraform-provider-gcp]: https://www.terraform.io/docs/providers/google/index.html
9860
[terraform]: https://www.terraform.io/downloads.html
61+
62+
## Security Disclosures
63+
64+
Please see our [security disclosure process](./SECURITY.md).

build/int.cloudbuild.yaml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,54 @@ steps:
4545
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerMIGContainerVM --stage destroy --verbose']
4646
waitFor:
4747
- verify-gh-runner-mig-container-vm
48-
# test/fixtures/gh-runner-gke
49-
- id: apply-gh-runner-gke
48+
# TestAll/examples/gh-runner-gke-simple
49+
- id: apply-gh-runner-gke-simple
5050
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
51-
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerGKE --stage apply --verbose']
51+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeSimple --stage apply --verbose']
5252
waitFor:
5353
- init-all
54-
- id: verify-gh-runner-gke
54+
- id: verify-gh-runner-gke-simple
5555
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
56-
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerGKE --stage verify --verbose']
56+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeSimple --stage verify --verbose']
5757
waitFor:
58-
- apply-gh-runner-gke
59-
- id: destroy-gh-runner-gke
58+
- apply-gh-runner-gke-simple
59+
- id: destroy-gh-runner-gke-simple
6060
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
61-
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerGKE --stage destroy --verbose']
61+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeSimple --stage destroy --verbose']
6262
waitFor:
63-
- verify-gh-runner-gke
63+
- verify-gh-runner-gke-simple
64+
# TestAll/examples/gh-runner-gke-dind
65+
- id: apply-gh-runner-gke-dind
66+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
67+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeDind --stage apply --verbose']
68+
waitFor:
69+
- init-all
70+
- id: verify-gh-runner-gke-dind
71+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
72+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeDind --stage verify --verbose']
73+
waitFor:
74+
- apply-gh-runner-gke-dind
75+
- id: destroy-gh-runner-gke-dind
76+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
77+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeDind --stage destroy --verbose']
78+
waitFor:
79+
- verify-gh-runner-gke-dind
80+
# TestAll/examples/gh-runner-gke-dind-rootless
81+
- id: apply-gh-runner-gke-dind-rootless
82+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
83+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeDindRootless --stage apply --verbose']
84+
waitFor:
85+
- init-all
86+
- id: verify-gh-runner-gke-dind-rootless
87+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
88+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeDindRootless --stage verify --verbose']
89+
waitFor:
90+
- apply-gh-runner-gke-dind-rootless
91+
- id: destroy-gh-runner-gke-dind-rootless
92+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
93+
args: ['/bin/bash', '-c', 'cft test run TestGhRunnerGkeDindRootless --stage destroy --verbose']
94+
waitFor:
95+
- verify-gh-runner-gke-dind-rootless
6496
# examples/oidc-simple
6597
- id: apply-oidc
6698
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'

docs/upgrading_to_v4.0.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Upgrading to v4.0
2+
3+
The v4.0 release of the `gh-runner-gke` module contains breaking changes.
4+
## Migration Instructions
5+
6+
### `gh-runner-gke` module
7+
8+
```diff
9+
module "runner-gke" {
10+
source = "terraform-google-modules/github-actions-runners/google//modules/gh-runner-gke"
11+
- version = "~> 3.0"
12+
+ version = "~> 4.0"
13+
14+
project_id = var.project_id
15+
create_network = true
16+
+ cluster_suffix = "repo"
17+
- repo_name = "repo"
18+
- repo_owner = "repo_owner"
19+
- repo_url = "repo_url"
20+
- gh_token = "gh_token"
21+
+ gh_app_id = "123456"
22+
+ gh_app_installation_id = "12345678"
23+
+ gh_app_private_key = "sample"
24+
+ gh_config_url = "https://github.com/ORGANIZATION"
25+
}
26+
```
27+
28+
- Previously, the name of the created GKE cluster appended `repo_name` as a suffix. Now, the value of the suffix is set via `cluster_suffix`, as runner clusters can be created for workflows more than one GitHub repo. To prevent cluster deletion when upgrading, set the value of `cluster_suffix` to the previous value of `repo_name`.
29+
- The module now prefers authentication via GitHub App installation. Follow the instructions for [authenticating to ARC via GitHub App](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners-with-actions-runner-controller/authenticating-to-the-github-api#authenticating-arc-with-a-github-app), and provide the necessary values to the module instead of the previous repo authentication values. Upgrading will destroy the previously created `runner_k8s_config` kubernetes secret, so previous GitHub Runner images may fail.
30+
- Previously, the GKE cluster service account was provided with the `roles/storage.objectViewer` role to enable pulling images from Container Registry. The module no longer requires access to Container Registry, and so IAM membership has been removed. If your cluster relies on this role, you will need to add it again manually.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Self Hosted runners on GKE that support dind-rootless
2+
3+
## Overview
4+
5+
This example shows how to deploy runners that support Docker Workflows on GKE in a rootless configuration. This example is based on the instructions published in [Deploying GitHub Action Runners on GKE with dind-rootless](https://medium.com/google-cloud/github-action-runners-on-gke-with-dind-rootless-bd54e23516c9).
6+
7+
More examples of [Self Hosted Runners on GKE/Anthos](https://github.com/github-developer/self-hosted-runners-anthos).
8+
9+
## Deployment
10+
11+
1. Follow the instructions in the [GitHub documentation](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners-with-actions-runner-controller/authenticating-to-the-github-api#authenticating-arc-with-a-github-app) to create a GitHub App for authenticating ARC
12+
13+
1. Gather the values for your GitHub App ID, GitHub App Installation ID, and GitHub App Private Key from the instructions linked above.
14+
15+
1. Substitute your values into the example [`main.tf`](main.tf). Modify any other values as needed. For a full list of available variables, refer to the [module documentation](../../modules/gh-runner-gke/).
16+
17+
1. Execute Terraform commands to create the required resources.
18+
```sh
19+
terraform init
20+
terraform apply
21+
```
22+
23+
1. Your runners should become active at `https://github.com/organizations/ORGANIZATION/settings/actions/runners`.
24+
25+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
26+
## Inputs
27+
28+
| Name | Description | Type | Default | Required |
29+
|------|-------------|------|---------|:--------:|
30+
| project\_id | The project id to deploy Github Runner MIG | `string` | n/a | yes |
31+
32+
## Outputs
33+
34+
| Name | Description |
35+
|------|-------------|
36+
| cluster\_name | Cluster name |
37+
| location | Cluster location |
38+
| project\_id | The project in which resources are created |
39+
| service\_account | The default service account used for running nodes. |
40+
41+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "runner-gke" {
18+
source = "terraform-google-modules/github-actions-runners/google//modules/gh-runner-gke"
19+
version = "~> 3.0"
20+
21+
project_id = var.project_id
22+
create_network = true
23+
network_name = "runner-network-dind-r"
24+
subnet_name = "runner-subnet-dind-r"
25+
cluster_suffix = "dind-rootless"
26+
gh_app_id = "123456"
27+
gh_app_installation_id = "12345678"
28+
gh_app_private_key = "sample"
29+
gh_config_url = "https://github.com/ORGANIZATION"
30+
31+
# pass values.yaml for dind-rootless runners configuratin
32+
arc_runners_values = [
33+
file("${path.module}/values.yaml")
34+
]
35+
}

test/fixtures/gh-runner-gke/outputs.tf renamed to examples/gh-runner-gke-dind-rootless/outputs.tf

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,20 @@
1616

1717
output "service_account" {
1818
description = "The default service account used for running nodes."
19-
value = module.example_gke_runner.service_account
19+
value = module.runner-gke.service_account
2020
}
2121

2222
output "cluster_name" {
2323
description = "Cluster name"
24-
value = module.example_gke_runner.cluster_name
25-
}
26-
output "network_name" {
27-
description = "Name of VPC"
28-
value = module.example_gke_runner.network_name
29-
}
30-
31-
output "subnet_name" {
32-
description = "Name of VPC"
33-
value = module.example_gke_runner.subnet_name
24+
value = module.runner-gke.cluster_name
3425
}
3526

3627
output "location" {
3728
description = "Cluster location"
38-
value = module.example_gke_runner.location
29+
value = module.runner-gke.location
3930
}
4031

4132
output "project_id" {
42-
value = var.project_id_gke
33+
value = var.project_id
34+
description = "The project in which resources are created"
4335
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*****************************************
18+
Kubernetes provider configuration
19+
*****************************************/
20+
21+
data "google_client_config" "default" {
22+
}
23+
24+
provider "kubernetes" {
25+
host = "https://${module.runner-gke.kubernetes_endpoint}"
26+
token = data.google_client_config.default.access_token
27+
cluster_ca_certificate = base64decode(module.runner-gke.ca_certificate)
28+
}
29+
30+
provider "helm" {
31+
kubernetes {
32+
host = "https://${module.runner-gke.kubernetes_endpoint}"
33+
token = data.google_client_config.default.access_token
34+
cluster_ca_certificate = base64decode(module.runner-gke.ca_certificate)
35+
exec {
36+
api_version = "client.authentication.k8s.io/v1beta1"
37+
command = "gke-gcloud-auth-plugin"
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)