Skip to content

Commit

Permalink
Merge pull request #16 from FriedCircuits:feature/github-runners-module
Browse files Browse the repository at this point in the history
Module to deploy Github self-hosted runners
  • Loading branch information
FriedCircuits authored Oct 24, 2022
2 parents e5a2e0b + eefb110 commit ddc477e
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Hodgepodge of Terraform modules.

* K8S
* Get Join - Get join config from Kuberenetes control plane
* Github Runners - Deploy Github self-hosted runners
* Helm Chart - Deploy any helm chart
* K8s-At-Home - Deploy a chart from the k8s-at-home helm repo
* Traefik Ingress - Creats Ingress CRDs for host based routing
* Helm Chart - Deploy any helm chart

* JumpCloud
* Users and Groups - Manage users and group membership
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.14
v0.0.15
123 changes: 123 additions & 0 deletions modules/k8s/github-runners/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
resource "kubernetes_namespace" "namespace" {
metadata {
name = var.namespace
}
}

resource "kubernetes_secret" "github" {
metadata {
name = "github-token"
namespace = var.namespace
}
data = {
github_token = var.github_token
}
type = "Opaque"
}

module "cert_manager" {
source = "git::[email protected]:friedcircuits/terraform-modules.git//modules/k8s/helm-chart?ref=v0.0.15"

helm_repo = "https://charts.jetstack.io/"
name = "cert-manager"
chart = "cert-manager"
namespace = var.namespace
create_namespace = false
chart_version = var.cert_chart_verison

helm_values = {
installCRDs = true
resources = {
limits = {
cpu = "100m"
memory = "128Mi"
}
requests = {
cpu = "100m"
memory = "128Mi"
}
}
}

depends_on = [
kubernetes_namespace.namespace,
]
}

module "github" {
source = "git::[email protected]:friedcircuits/terraform-modules.git//modules/k8s/helm-chart?ref=v0.0.15"

helm_repo = "https://actions-runner-controller.github.io/actions-runner-controller"
name = "actions-runner-controller"
chart = "actions-runner-controller"
namespace = var.namespace
create_namespace = false
chart_version = var.github_chart_version


helm_values = {
authSecret = {
create = false
name = "github-token"
}
resources = {
limits = {
cpu = "100m"
memory = "128Mi"
}
requests = {
cpu = "100m"
memory = "128Mi"
}
}
}

depends_on = [
kubernetes_namespace.namespace,
module.cert_manager
]
}

resource "kubernetes_manifest" "runner" {
for_each = { for repo in var.repos : repo.repo => repo }
manifest = {
apiVersion = "actions.summerwind.dev/v1alpha1"
kind = "RunnerDeployment"
metadata = {
name = "runner-deployment"
namespace = var.namespace
}
spec = {
template = {
spec = {
repository = each.value.repo
}
}
}
}
}

resource "kubernetes_manifest" "runner_autoscaler" {
for_each = { for repo in var.repos : repo.repo => repo }
manifest = {
apiVersion = "actions.summerwind.dev/v1alpha1"
kind = "HorizontalRunnerAutoscaler"
metadata = {
name = "runner-deployment-autoscaler"
namespace = var.namespace
}
spec = {
scaleTargetRef = {
name = "runner-deployment"
}
minReplicas = each.value.min
maxReplicas = each.value.max
metrics = [{
type = "TotalNumberOfQueuedAndInProgressWorkflowRuns"
repositoryNames = [
each.value.repo
]
}]
}
}
}
32 changes: 32 additions & 0 deletions modules/k8s/github-runners/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "namespace" {
description = "Which Kubernetes Namespace to deploy the chart into."
type = string
default = "github"
}

variable "cert_chart_verison" {
description = "Helm chart version for cert manager. Required for github runners."
type = string
default = "v1.10.0"
}

variable "github_chart_version" {
description = "The version of the helm chart to use. Note that this is different from the app/container version."
type = string
default = "0.21.0"
}

variable "github_token" {
description = "Github token with repo access."
type = string
}

variable "repos" {
description = "List of repos to run runers for."
type = list(object({
repo = string
min = number
max = number
}))
default = []
}
14 changes: 14 additions & 0 deletions modules/k8s/github-runners/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">= 1.0"

required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.0"
}
}
}

0 comments on commit ddc477e

Please sign in to comment.