package tech.avroid.kube class PodTemplates implements Serializable { String registry Object script String cloud List dockerCreds // TODO: delete default cloud after k8s cluster migration public PodTemplates(script, String registry, List dockerCreds, String cloud='avroid') { this.script = script this.cloud = cloud this.registry = registry this.dockerCreds = dockerCreds } protected rawYaml() { return """spec: tolerations: - key: node-role.kubernetes.io/build-node effect: NoSchedule """ } public void jnlp(imageVersion='jdk17', body) { this.script.podTemplate( cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'jnlp', image: "${this.registry}/docker-hub-proxy/jenkins/inbound-agent:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], resourceRequestCpu: '50m', resourceRequestMemory: '256Mi', resourceLimitCpu: '2', resourceLimitMemory: '4Gi', workingDir: '/jenkins', ), ], instanceCap: 2, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.cache'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.ssh'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.npm'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.config'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.composer'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.local'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), yaml: this.rawYaml(), ) { body.call() } } public void poetry(imageVersion='1.8.4', body) { this.script.podTemplate( imagePullSecrets: this.dockerCreds, cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'poetry', image: "${this.registry}/devops/poetry:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], shell: '/bin/sh', ttyEnabled: true, command: 'cat', resourceRequestCpu: '100m', resourceRequestMemory: '64Mi', resourceLimitCpu: '100m', resourceLimitMemory: '64Gi', workingDir: '/jenkins', ), ], instanceCap: 1, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), yaml: this.rawYaml(), ) { body.call() } } public void docker(imageVersion='27.3.1-dind',body) { this.script.podTemplate( imagePullSecrets: this.dockerCreds, cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'docker', image: "${this.registry}/docker-hub-proxy/docker:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], ttyEnabled: true, command: '/usr/local/bin/dockerd-entrypoint.sh', privileged: true, resourceRequestCpu: '500m', resourceLimitCpu: '4', resourceRequestMemory: '512Mi', resourceLimitMemory: '3Gi', workingDir: '/jenkins', ), ], instanceCap: 1, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/var/lib/docker'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.local'), this.script.emptyDirVolume(memory: false, mountPath: '/home/jenkins/.cache'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), ) { body.call() } } public void git(imageVersion='v2.45.2', body) { this.script.podTemplate( runAsUser: "1000", runAsGroup: "1000", imagePullSecrets: this.dockerCreds, cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'git', image: "${this.registry}/devops/git:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], ttyEnabled: true, command: "cat", resourceRequestCpu: '100m', resourceLimitCpu: '100m', resourceRequestMemory: '32Mi', resourceLimitMemory: '32Mi', workingDir: '/jenkins', ), ], instanceCap: 1, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), ) { body.call() } } public void helm(imageVersion='3.16.3', body) { this.script.podTemplate( serviceAccount: 'jenkins-deploy', cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'helm', image: "${this.registry}/docker-hub-proxy/alpine/helm:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], ttyEnabled: true, command: "cat", resourceRequestCpu: '100m', resourceLimitCpu: '100m', resourceRequestMemory: '256Mi', resourceLimitMemory: '256Mi', workingDir: '/jenkins', ), ], instanceCap: 1, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), ) { body.call() } } public void kubectl(imageVersion='1.31.3', body) { this.script.podTemplate( serviceAccount: 'jenkins-deploy', cloud: this.cloud, runAsUser: "0", containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'kubectl', image: "${this.registry}/docker-hub-proxy/bitnami/kubectl:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], ttyEnabled: true, command: "cat", resourceRequestCpu: '100m', resourceLimitCpu: '100m', resourceRequestMemory: '256Mi', resourceLimitMemory: '256Mi', workingDir: '/jenkins', ), ], instanceCap: 1, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), ) { body.call() } } public void nodejs(imageVersion='18.16-alpine3.18', body) { this.script.podTemplate( runAsUser: "0", cloud: this.cloud, imagePullSecrets: this.dockerCreds, containers: [ this.script.containerTemplate( alwaysPullImage: true, name: 'nodejs', image: "${this.registry}/devops/node:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], ttyEnabled: true, command: "cat", resourceRequestCpu: '100m', resourceLimitCpu: '100m', resourceRequestMemory: '1024Mi', resourceLimitMemory: '1024Mi', workingDir: '/jenkins', ), ], instanceCap: 1, showRawYaml: false, volumes: [ this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), ], workspaceVolume: this.script.emptyDirWorkspaceVolume(false), ) { body.call() } } }