diff --git a/src/tech/avroid/kube/PodTemplates.groovy b/src/tech/avroid/kube/PodTemplates.groovy index e5b7c83..bfc1814 100644 --- a/src/tech/avroid/kube/PodTemplates.groovy +++ b/src/tech/avroid/kube/PodTemplates.groovy @@ -1,13 +1,14 @@ package tech.avroid.kube - class PodTemplates implements Serializable { String registry Object script + String cloud List dockerCreds - - public PodTemplates(script, String registry, 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 } @@ -22,6 +23,7 @@ class PodTemplates implements Serializable { public void jnlp(imageVersion='jdk17', body) { this.script.podTemplate( + cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, @@ -42,6 +44,7 @@ class PodTemplates implements Serializable { 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'), @@ -59,6 +62,7 @@ class PodTemplates implements Serializable { public void poetry(imageVersion='1.8.4', body) { this.script.podTemplate( imagePullSecrets: this.dockerCreds, + cloud: this.cloud, containers: [ this.script.containerTemplate( alwaysPullImage: true, @@ -94,11 +98,12 @@ class PodTemplates implements Serializable { 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: "${registry}/docker-hub-proxy/docker:${imageVersion}", + image: "${this.registry}/docker-hub-proxy/docker:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], @@ -129,11 +134,15 @@ class PodTemplates implements Serializable { 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: "${registry}/docker-hub-proxy/alpine/git:${imageVersion}", + image: "${this.registry}/devops/git:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], @@ -162,11 +171,12 @@ class PodTemplates implements Serializable { 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: "${registry}/docker-hub-proxy/alpine/helm:${imageVersion}", + image: "${this.registry}/docker-hub-proxy/alpine/helm:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], @@ -195,12 +205,13 @@ class PodTemplates implements Serializable { 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: "${registry}/docker-hub-proxy/bitnami/kubectl:${imageVersion}", + image: "${this.registry}/docker-hub-proxy/bitnami/kubectl:${imageVersion}", envVars: [ this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), ], @@ -229,6 +240,7 @@ class PodTemplates implements Serializable { public void nodejs(imageVersion='18.16-alpine3.18', body) { this.script.podTemplate( runAsUser: "0", + cloud: this.cloud, imagePullSecrets: this.dockerCreds, containers: [ this.script.containerTemplate( diff --git a/src/tech/avroid/scm/Git.groovy b/src/tech/avroid/scm/Git.groovy index 3dab852..85a2683 100644 --- a/src/tech/avroid/scm/Git.groovy +++ b/src/tech/avroid/scm/Git.groovy @@ -90,6 +90,7 @@ class Git implements Serializable { */ public config(String gitUserName = "jenkins", String gitUserMail = "jenkins@example.com") { script.sh """#!/bin/sh + git config --global --add safe.directory '*' git config user.name ${gitUserName} git config user.email ${gitUserMail} """ @@ -101,7 +102,7 @@ class Git implements Serializable { */ public add(List fileContents = ["."]) { fileContents.each { fileContent -> - script.sh """ + script.sh """#!/bin/sh git add ${fileContent} """ } @@ -112,7 +113,7 @@ class Git implements Serializable { * @param String Message - git commit message */ public commit(String message) { - script.sh """ + script.sh """#!/bin/sh git commit -m "${message}" """ } @@ -121,24 +122,135 @@ class Git implements Serializable { * Method executes command "git push" * @param String branch - ветка, коммит, тег, который пушится. По умолчанию пустая строка */ - public push(String branch = '') { + @Deprecated + public void push(String branch = '') { script.sshagent([this.creds]) { - script.sh """ + script.sh """#!/bin/sh git push ${branch} """ } } + /** + * Method executes command "git push ". + * @param String origin - origin name (default origin) + * @param String branch - git branch. (default 'master') + */ + public void push(Map args) { + Map defaultArgs = [ + origin: 'origin', + branch: 'master', + ] + + defaultArgs.each { k, v -> + if (args[k] == null || args[k] == '' || args[k] == []) { + args[k] = v + } + } + + script.sh """#!/bin/sh + git push ${args.origin} ${args.branch} + """ + } + /** * Method executes command "git checkout". * @param String branch - git branch. If empty, equals this.getBranch() */ + @Deprecated public checkout(String branch = this.getBranch()) { - script.sh """ + script.sh """#!/bin/sh git checkout ${branch} """ } + /** + * Method executes command "git checkout". + * @param String origin - origin name (default origin) + * @param String branch - git branch. (default 'master') + */ + public void checkout(Map args) { + Map defaultArgs = [ + origin: 'origin', + branch: 'master', + ] + + defaultArgs.each { k, v -> + if (args[k] == null || args[k] == '' || args[k] == []) { + args[k] = v + } + } + + script.sh """#!/bin/sh + git checkout --track ${args.origin}/${args.branch} + """ + } + + /** + * Method executes command "git fetch ". + * @param String origin - origin name (default origin) + * @param String branch - git branch. (default 'master') + */ + public void fetch(Map args = [:]) { + Map defaultArgs = [ + origin: 'origin', + branch: 'master', + ] + + defaultArgs.each { k, v -> + if (args[k] == null || args[k] == '' || args[k] == []) { + args[k] = v + } + } + + script.sh """#!/bin/sh + git fetch ${args.origin} ${args.branch} + """ + } + + /** + * Method executes command "git merge /". + * @param String origin - origin name (default origin) + * @param String branch - git branch. (default 'master') + */ + public void merge(Map args = [:]) { + Map defaultArgs = [ + origin: 'origin', + branch: 'master', + ] + + defaultArgs.each { k, v -> + if (args[k] == null || args[k] == '' || args[k] == []) { + args[k] = v + } + } + + script.sh """#!/bin/sh + git merge ${args.origin}/${args.branch} + """ + } + + /** + * Method executes command "git remote add ". + * @param String origin - origin name (default origin) + * @param String url - remote git url + */ + public void remote(Map args = [:]) { + Map defaultArgs = [ + origin: 'origin', + ] + + defaultArgs.each { k, v -> + if (args[k] == null || args[k] == '' || args[k] == []) { + args[k] = v + } + } + + script.sh """#!/bin/sh + git remote add ${args.origin} ${args.url} + """ + } + /** * Method executes command "git log". * @param Map args: