jenkins.nomad (3823B)
1 job "jenkins" { 2 datacenters = ["dc1"] 3 4 vault {} 5 6 group "server" { 7 count = 1 8 9 volume "tls" { 10 type = "csi" 11 source = "certbot" 12 access_mode = "multi-node-multi-writer" 13 attachment_mode = "file-system" 14 } 15 volume "jenkins" { 16 type = "csi" 17 source = "jenkins" 18 access_mode = "multi-node-multi-writer" 19 attachment_mode = "file-system" 20 } 21 22 network { 23 port "jenkins" { 24 to = 8080 25 } 26 port "jnlp" { 27 to = 50000 28 } 29 port "https" { 30 static = 44401 31 } 32 } 33 34 # Install jenkins plugins 35 # https://www.jenkins.io/doc/book/installing/docker 36 task "install-jenkins-plugins" { 37 driver = "podman" 38 39 volume_mount { 40 volume = "jenkins" 41 destination = "/var/jenkins_home" 42 } 43 44 config { 45 image = "docker.io/jenkins/jenkins:lts-jdk21" 46 force_pull = true 47 command = "jenkins-plugin-cli" 48 args = [ 49 "--plugins", 50 "blueocean", 51 "configuration-as-code", 52 "git", 53 "hashicorp-vault-plugin", 54 "nomad", 55 "pipeline-utility-steps", 56 "docker-workflow", # spawn Jenkins agents in Nomad jobs 57 #"docker-plugin", # spawn Jenkins agents in Docker containers 58 "--plugin-download-directory", 59 "/var/jenkins_home/plugins", 60 ] 61 } 62 63 resources { 64 memory = 512 65 memory_max = 1024 66 cpu = 300 67 } 68 69 lifecycle { 70 hook = "prestart" 71 sidecar = false 72 } 73 } 74 75 task "jenkins" { 76 driver = "podman" 77 78 template { 79 # https://github.com/GastroGee/jenkins-nomad/blob/main/jenkins-controller/nomad.yaml 80 destination = "${NOMAD_TASK_DIR}/jenkins.yaml" 81 data = file("./templates/jenkins.yaml.tmpl") 82 } 83 84 env { 85 JAVA_OPTS = "-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false -Dorg.apache.commons.jelly.tags.fmt.timeZone=Europe/Zurich -Dhudson.model.UsageStatistics.disabled=true -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true" 86 } 87 88 config { 89 image = "docker.io/jenkins/jenkins:lts-jdk21" 90 force_pull = true 91 ports = ["jenkins", "jnlp"] 92 volumes = [ 93 # mount the templated config from the task directory to the container 94 "local/jenkins.yaml:/var/jenkins_home/jenkins.yaml", 95 # mount the Nomad server truststore 96 "/home/jenkins/nomad-agent-ca.p12:/etc/ssl/certs/nomad-agent-ca.p12", 97 # Required to test the functionality of the socket in the settings on 98 # the Jenkins controller (only for Docker cloud, docker-plugin) 99 # https://jenkins.in0rdr.ch/manage/cloud/docker/configure 100 #"/run/user/1312/podman/podman.sock:/home/jenkins/agent/podman.sock" 101 ] 102 } 103 104 volume_mount { 105 volume = "jenkins" 106 destination = "/var/jenkins_home" 107 } 108 109 resources { 110 # https://www.jenkins.io/doc/book/installing/docker/#prerequisites 111 memory = 1024 112 memory_max = 2048 113 cpu = 500 114 } 115 } 116 117 task "nginx" { 118 driver = "podman" 119 120 config { 121 image = "docker.io/library/nginx:stable-alpine" 122 force_pull = true 123 ports = ["https"] 124 volumes = [ 125 # mount the templated config from the task directory to the container 126 "local/jenkins.conf:/etc/nginx/conf.d/jenkins.conf", 127 ] 128 } 129 130 volume_mount { 131 volume = "tls" 132 destination = "/etc/letsencrypt" 133 } 134 135 template { 136 destination = "${NOMAD_TASK_DIR}/jenkins.conf" 137 data = file("./templates/nginx.conf.tmpl") 138 } 139 140 resources { 141 memory = 50 142 memory_max = 256 143 cpu = 200 144 } 145 } 146 } 147 }