[DO-1617] add 2 pod templates and add Terraform class (!64)
Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/64 Reviewed-by: Vasiliy Chipizhin <vasiliy.chipizhin@avroid.team> Reviewed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team> Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
This commit is contained in:
@@ -237,6 +237,74 @@ class PodTemplates implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public void terraform(imageVersion='1.10.5', body) {
|
||||
this.script.podTemplate(
|
||||
cloud: this.cloud,
|
||||
runAsUser: "0",
|
||||
containers: [
|
||||
this.script.containerTemplate(
|
||||
alwaysPullImage: true,
|
||||
name: 'terraform',
|
||||
image: "${this.registry}/docker-hub-proxy/hashicorp/terraform:${imageVersion}",
|
||||
envVars: [
|
||||
this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'),
|
||||
],
|
||||
ttyEnabled: true,
|
||||
command: "cat",
|
||||
resourceRequestCpu: '500m',
|
||||
resourceLimitCpu: '500m',
|
||||
resourceRequestMemory: '2Gi',
|
||||
resourceLimitMemory: '12Gi',
|
||||
workingDir: '/jenkins',
|
||||
),
|
||||
],
|
||||
instanceCap: 1,
|
||||
showRawYaml: false,
|
||||
volumes: [
|
||||
this.script.emptyDirVolume(memory: false, mountPath: '/tmp'),
|
||||
],
|
||||
workspaceVolume: this.script.emptyDirWorkspaceVolume(false),
|
||||
)
|
||||
|
||||
{
|
||||
body.call()
|
||||
}
|
||||
}
|
||||
|
||||
public void vault(imageVersion='1.17.6-0', body) {
|
||||
this.script.podTemplate(
|
||||
cloud: this.cloud,
|
||||
imagePullSecrets: this.dockerCreds,
|
||||
containers: [
|
||||
this.script.containerTemplate(
|
||||
alwaysPullImage: true,
|
||||
name: 'vault',
|
||||
image: "${this.registry}/devops/vault:${imageVersion}",
|
||||
envVars: [
|
||||
this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'),
|
||||
],
|
||||
ttyEnabled: true,
|
||||
command: "cat",
|
||||
resourceRequestCpu: '300m',
|
||||
resourceLimitCpu: '300m',
|
||||
resourceRequestMemory: '1Gi',
|
||||
resourceLimitMemory: '12Gi',
|
||||
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",
|
||||
|
||||
49
src/tech/avroid/terraform/Terraform.groovy
Normal file
49
src/tech/avroid/terraform/Terraform.groovy
Normal file
@@ -0,0 +1,49 @@
|
||||
package tech.avroid.terraform
|
||||
|
||||
/**
|
||||
* Class for work with Terraform
|
||||
*/
|
||||
class Terraform implements Serializable {
|
||||
|
||||
private Script script
|
||||
|
||||
Terraform(Map args = [:]) {
|
||||
this.script = args.script
|
||||
}
|
||||
|
||||
/**
|
||||
* Method terraform init
|
||||
* @return exit code
|
||||
*/
|
||||
public Integer init() {
|
||||
return this.script.sh(
|
||||
script: "set +x && source .creds && terraform init",
|
||||
returnStatus: true
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Method terraform plan
|
||||
*/
|
||||
public void plan() {
|
||||
script.sh "terraform plan"
|
||||
}
|
||||
|
||||
/**
|
||||
* Method cheking status plan
|
||||
* @return exit code
|
||||
*/
|
||||
public Integer checkStatusPlan(Boolean debug = false) {
|
||||
String hideOutput = '> /dev/null'
|
||||
|
||||
if (debug) {
|
||||
hideOutput = ''
|
||||
}
|
||||
|
||||
return this.script.sh(
|
||||
script: "set +x && source .creds && terraform plan " +
|
||||
"-lock=false -detailed-exitcode -input=false ${hideOutput}",
|
||||
returnStatus: true
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user