Skip to content

Commit 20b0737

Browse files
authored
seed initial modules (terraform-google-modules#1)
1 parent ab20d61 commit 20b0737

File tree

99 files changed

+3783
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+3783
-189
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @morgante @bbaiju @sethvargo @craigdbarber

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Session.vim
2828
*.tfstate
2929
*.tfstate.*
3030

31+
# test.out files
32+
test.out
33+
3134
# Crash log files
3235
crash.log
3336

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

README.md

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,96 @@
1-
# terraform-google-terraform-google-github-actions-runners
1+
# terraform-google-github-actions-runners
22

3-
This module was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template/), which by default generates a module that simply creates a GCS bucket. As the module develops, this README should be updated.
3+
Using these Terraform modules you can quickly deploy Self Hosted Github Runners for jobs in your GitHub Actions workflows
44

5-
The resources/services/activations/deletions that this module will create/trigger are:
5+
## [Self Hosted Runners on GKE](modules/gh-runner-gke/README.md)
66

7-
- Create a GCS bucket with the provided name
7+
The `gh-runner-gke` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using GKE.
88

9-
## Usage
9+
This includes
1010

11-
Basic usage of this module is as follows:
11+
- Enabling necessary APIs
12+
- VPC
13+
- GKE Cluster
14+
- Kubernetes Secret
1215

13-
```hcl
14-
module "terraform_google_github_actions_runners" {
15-
source = "terraform-google-modules/terraform-google-github-actions-runners/google"
16-
version = "~> 0.1"
16+
Below are some examples:
1717

18-
project_id = "<PROJECT ID>"
19-
bucket_name = "gcs-test-bucket"
20-
}
21-
```
18+
### [Self Hosted runners on GKE that support Docker Workflows](examples/gh-runner-gke-dind/README.md)
2219

23-
Functional examples are included in the
24-
[examples](./examples/) directory.
20+
This example shows how to deploy Self Hosted Runners on GKE that supports Docker Workflows.
2521

26-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
27-
## Inputs
22+
### [Simple Self Hosted Runners on GKE](examples/gh-runner-gke-simple/README.md)
2823

29-
| Name | Description | Type | Default | Required |
30-
|------|-------------|:----:|:-----:|:-----:|
31-
| bucket\_name | The name of the bucket to create | string | n/a | yes |
32-
| project\_id | The project ID to deploy to | string | n/a | yes |
24+
This example shows how to deploy a simple GKE Self Hosted Runner.
3325

34-
## Outputs
26+
More examples of [Self Hosted Runners on GKE/Anthos](https://github.com/github-developer/self-hosted-runners-anthos).
3527

36-
| Name | Description |
37-
|------|-------------|
38-
| bucket\_name | |
28+
## [Self Hosted Runners on Managed Instance Groups using VMs](modules/gh-runner-mig-vm/README.md)
3929

40-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
30+
The `gh-runner-mig-vm` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using Managed Instance Groups.
4131

42-
## Requirements
32+
This includes
4333

44-
These sections describe requirements for using this module.
34+
- Enabling necessary APIs
35+
- VPC
36+
- NAT & Cloud Router
37+
- Service Account for MIG
38+
- MIG Instance Template
39+
- MIG Instance Manager
40+
- FW Rules
41+
- Secret Manager Secret
4542

46-
### Software
43+
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.
4744

48-
The following dependencies must be available:
45+
Below are some examples:
4946

50-
- [Terraform][terraform] v0.12
51-
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v2.0
47+
### [Simple Self Hosted Runner on MIG VMs](examples/gh-runner-mig-native-simple/README.md)
48+
49+
This example shows how to deploy a MIG Self Hosted Runner with startup scripts.
50+
51+
### [Self Hosted Runner on MIG VMs from Packer Image](examples/gh-runner-mig-native-packer/README.md)
52+
53+
This example shows how to deploy a MIG Self Hosted Runner with an image pre-baked using Packer.
54+
55+
## [Self Hosted Runners on Managed Instance Groups using Container VMs](modules/gh-runner-mig-container-vm/README.md)
56+
57+
The `gh-runner-mig-container-vm` module provisions the resources required to deploy Self Hosted Runners on GCP infrastructure using Managed Instance Groups.
5258

53-
### Service Account
59+
This includes
5460

55-
A service account with the following roles must be used to provision
56-
the resources of this module:
61+
- Enabling necessary APIs
62+
- VPC
63+
- NAT & Cloud Router
64+
- MIG Container Instance Template
65+
- MIG Instance Manager
66+
- FW Rules
5767

58-
- Storage Admin: `roles/storage.admin`
68+
Below are some examples:
5969

60-
The [Project Factory module][project-factory-module] and the
61-
[IAM module][iam-module] may be used in combination to provision a
62-
service account with the necessary roles applied.
70+
### [Self Hosted runners on MIG Container VMs that support Docker Workflows](examples/gh-runner-mig-container-vm-dind/README.md)
6371

64-
### APIs
72+
This example shows how to deploy a Self Hosted Runner that supports Docker Workflows on MIG Container VMs.
6573

66-
A project with the following APIs enabled must be used to host the
67-
resources of this module:
74+
### [Simple Self Hosted Runner on MIG Container VMs](examples/gh-runner-mig-container-vm-simple/README.md)
6875

69-
- Google Cloud Storage JSON API: `storage-api.googleapis.com`
76+
This example shows how to deploy a Self Hosted Runner on MIG Container VMs.
7077

71-
The [Project Factory module][project-factory-module] can be used to
72-
provision a project with the necessary APIs enabled.
78+
79+
## Requirements
80+
81+
These sections describe requirements for using this module.
82+
83+
### Software
84+
85+
The following dependencies must be available:
86+
87+
- [Terraform][terraform] v0.12
88+
- [Terraform Provider for GCP][terraform-provider-gcp]
7389

7490
## Contributing
7591

7692
Refer to the [contribution guidelines](./CONTRIBUTING.md) for
7793
information on contributing to this module.
7894

79-
[iam-module]: https://registry.terraform.io/modules/terraform-google-modules/iam/google
80-
[project-factory-module]: https://registry.terraform.io/modules/terraform-google-modules/project-factory/google
8195
[terraform-provider-gcp]: https://www.terraform.io/docs/providers/google/index.html
8296
[terraform]: https://www.terraform.io/downloads.html

build/int.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.terraform
2+
*.tf*
3+
*.tfvars
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.terraform
2+
*.tfstate
3+
*.tf
4+
*.out
5+
sample-manifests
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Download and verify the integrity of the download first
15+
16+
FROM ubuntu:18.04
17+
RUN apt-get update && \
18+
apt-get -y install apt-transport-https \
19+
ca-certificates \
20+
curl \
21+
tar \
22+
jq \
23+
build-essential \
24+
gnupg2 \
25+
iputils-ping \
26+
software-properties-common
27+
28+
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
29+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" && \
30+
apt-get update && \
31+
apt-get -y install docker-ce
32+
33+
ARG GH_RUNNER_VERSION="2.169.0"
34+
WORKDIR /runner
35+
RUN curl -o actions.tar.gz --location "https://github.com/actions/runner/releases/download/v${GH_RUNNER_VERSION}/actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz" && \
36+
tar -zxf actions.tar.gz && \
37+
rm -f actions.tar.gz && \
38+
./bin/installdependencies.sh
39+
40+
COPY entrypoint.sh .
41+
ENV RUNNER_ALLOW_RUNASROOT=1
42+
RUN chmod +x entrypoint.sh
43+
ENTRYPOINT ["/runner/entrypoint.sh"]

examples/gh-runner-gke-dind/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Self Hosted runners on GKE that support Docker Workflows
2+
3+
## Overview
4+
5+
This example shows how to deploy runners that support Docker Workflows on GKE.
6+
7+
More examples of [Self Hosted Runners on GKE/Anthos](https://github.com/github-developer/self-hosted-runners-anthos).
8+
9+
## Steps to deploy this example
10+
11+
- Step 1: Create terraform.tfvars file with the necessary values.
12+
13+
Access tokens require repo scope for private repos and public_repo scope for public repos. GitHub Apps must have the administration permission to use this API. Authenticated users must have admin access to the repository to use this API.
14+
15+
More info can be found [here](https://developer.github.com/v3/actions/self_hosted_runners/).
16+
17+
```tf
18+
project_id = "your-project-id"
19+
gh_token = "your-github-token"
20+
repo_url = "https://github.com/owner/your-repo-name"
21+
repo_name = "your-repo-name"
22+
repo_owner = "owner"
23+
```
24+
25+
- Step 2: Create the infrastructure.
26+
27+
```sh
28+
$ terraform init
29+
$ terraform plan
30+
$ terraform apply
31+
```
32+
33+
- Step 3: Build the example runner image using Google Cloud Build. Alternatively, you can also use a prebuilt image or build using a local docker daemon.
34+
35+
```sh
36+
$ gcloud config set project $PROJECT_ID
37+
$ gcloud services enable cloudbuild.googleapis.com
38+
$ gcloud builds submit --config=cloudbuild.yaml
39+
```
40+
41+
- Step 4: Replace image in [sample k8s deployment manifest](./sample-manifests/deployment.yaml).
42+
43+
```sh
44+
$ kustomize edit set image gcr.io/PROJECT_ID/runner:latest=gcr.io/$PROJECT_ID/runner:latest
45+
```
46+
47+
- Step 5: Generate kubeconfig and apply the manifests for Deployment and HorizontalPodAutoscaler.
48+
49+
```sh
50+
$ gcloud container clusters get-credentials your-cluster-name --zone=your-cluster-zone
51+
$ kustomize build . | kubectl apply -f -
52+
```
53+
54+
- Step 6: Your runners should become active at https://github.com/owner/your-repo-name/settings/actions.
55+
56+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
57+
## Inputs
58+
59+
| Name | Description | Type | Default | Required |
60+
|------|-------------|:----:|:-----:|:-----:|
61+
| gh\_token | Github token that is used for generating Self Hosted Runner Token | string | n/a | yes |
62+
| project\_id | The project id to deploy Github Runner MIG | string | n/a | yes |
63+
| repo\_name | Name of the repo for the Github Action | string | n/a | yes |
64+
| repo\_owner | Owner of the repo for the Github Action | string | n/a | yes |
65+
| repo\_url | Repo URL for the Github Action | string | n/a | yes |
66+
67+
## Outputs
68+
69+
| Name | Description |
70+
|------|-------------|
71+
| ca\_certificate | The cluster ca certificate (base64 encoded) |
72+
| client\_token | The bearer token for auth |
73+
| cluster\_name | Cluster name |
74+
| kubernetes\_endpoint | The cluster endpoint |
75+
| location | Cluster location |
76+
| service\_account | The default service account used for running nodes. |
77+
78+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,12 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
control "gcloud" do
16-
title "gcloud"
17-
18-
describe command("gcloud --project=#{attribute("project_id")} services list --enabled") do
19-
its(:exit_status) { should eq 0 }
20-
its(:stderr) { should eq "" }
21-
its(:stdout) { should match "storage-api.googleapis.com" }
22-
end
23-
end
15+
steps:
16+
- name: "gcr.io/cloud-builders/docker"
17+
args:
18+
[
19+
"build",
20+
"-t",
21+
"gcr.io/$PROJECT_ID/runner:latest",
22+
"-t",
23+
"gcr.io/$PROJECT_ID/runner:0.1",
24+
".",
25+
]
26+
images:
27+
- "gcr.io/$PROJECT_ID/runner"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
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+
#set name for this runner as the hostname
17+
# shellcheck disable=SC2034
18+
# ACTIONS_RUNNER_INPUT_NAME is used by config.sh
19+
ACTIONS_RUNNER_INPUT_NAME=$HOSTNAME
20+
#get regsistration token for this runnner
21+
ACTIONS_RUNNER_INPUT_TOKEN="$(curl -sS --request POST --url "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runners/registration-token" --header "authorization: Bearer ${GITHUB_TOKEN}" --header 'content-type: application/json' | jq -r .token)"
22+
#configure runner
23+
/runner/config.sh --unattended --replace --work "/tmp" --url "$ACTIONS_RUNNER_INPUT_URL" --token "$ACTIONS_RUNNER_INPUT_TOKEN"
24+
#start runner
25+
#https://github.com/actions/runner/issues/246#issuecomment-615293718
26+
/runner/bin/runsvc.sh
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Google LLC
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,10 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
control "gcp" do
16-
title "GCP Resources"
17-
18-
describe google_storage_bucket(name: attribute("bucket_name")) do
19-
it { should exist }
20-
end
21-
end
15+
apiVersion: kustomize.config.k8s.io/v1beta1
16+
kind: Kustomization
17+
resources:
18+
- sample-manifests/deployment.yaml
19+
- sample-manifests/hpa.yaml

0 commit comments

Comments
 (0)