Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jenkins-local-terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.terraform/
terraform.tfstate*
3 changes: 3 additions & 0 deletions jenkins-local-terraform/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM jenkins/jenkins:lts-jdk11
COPY --chown=jenkins:jenkins plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt
19 changes: 19 additions & 0 deletions jenkins-local-terraform/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: build

build:
docker build . --tag jenkins-local:latest

.PHONY: init

init:
cd tf/ && terraform init

.PHONY: deploy

deploy:
cd tf/ && terraform plan && terraform apply --auto-approve

.PHONY: destroy

destroy:
cd tf/ && terraform destroy --auto-approve
14 changes: 14 additions & 0 deletions jenkins-local-terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Local Jenkins with Terraform and Docker Desktop

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A list of resources created by the terraform configuration would be a good addition to this file.

# Prerequisites

- Install Terraform
- Install Docker Desktop
- Enable Kubernetes in Docker Desktop

# Instructions

1. `make build` builds the Jenkins docker image
1. `make init` initializes the tf directory
1. `make deploy` plans and applies the terraform configuration
1. `make destroy` destroys the terraform configuration
4 changes: 4 additions & 0 deletions jenkins-local-terraform/plugins.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
configuration-as-code:1625.v27444588cc3d
git:5.0.0
kubernetes:3923.v294a_d4250b_91
workflow-aggregator:596.v8c21c963d92d
42 changes: 42 additions & 0 deletions jenkins-local-terraform/tf/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions jenkins-local-terraform/tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = "docker-desktop"
}

provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}

resource "helm_release" "jenkins" {
name = "jenkins"
repository = "https://charts.jenkins.io"
chart = "jenkins"
namespace = kubernetes_namespace.jenkins_namespace.metadata[0].name

values = [
"${file("values.yaml")}",
]

set {
name = "controller.serviceType"
value = "LoadBalancer"
}

set {
name = "controller.adminPassword"
value = "jenkins123" # Replace with a secure password
}

# set {
# name = "controller.installPlugins"
# value = "simple-theme-plugin:0.6.0,workflow-job:2.41,workflow-aggregator:2.6,credentials-binding:1.27,git:4.10.0"
# }
}

resource "kubernetes_namespace" "jenkins_namespace" {
metadata {
name = "jenkins"
}
}
30 changes: 30 additions & 0 deletions jenkins-local-terraform/tf/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
controller:
image: jenkins-local
tag: latest
imagePullPolicy: Never
installPlugins: false

jenkins:
systemMessage: "Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n"

nodes:
- permanent:
name: "static-agent"
remoteFS: "/home/jenkins"
launcher:
inbound:
workDirSettings:
disabled: true
failIfWorkDirIsMissing: false
internalDir: "remoting"
workDirPath: "/tmp"

slaveAgentPort: 50000
agentProtocols:
- "jnlp2"

tool:
git:
installations:
- name: git
home: /usr/local/bin/git
12 changes: 12 additions & 0 deletions jenkins-local-terraform/tf/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.19.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.9.0"
}
}
}