-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile-production-deploy
52 lines (45 loc) · 2.06 KB
/
Jenkinsfile-production-deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
podTemplate(label: 'sanqueries-production-deploy', containers: [
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.23.14', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'docker', image: 'docker', ttyEnabled: true, command: 'cat', envVars: [
envVar(key: 'DOCKER_HOST', value: 'tcp://docker-host-docker-host.default.svc.cluster.local:2375')
]),
containerTemplate(name: 'awscli', image: 'mikesir87/aws-cli', ttyEnabled: true, command: 'cat', envVars: [
envVar(key: 'AWS_DEFAULT_REGION', value: 'eu-central-1'),
secretEnvVar(key: 'AWS_ACCESS_KEY_ID', secretName: 'ecr-keys-env', secretKey: 'awsAccessKeyId'),
secretEnvVar(key: 'AWS_SECRET_ACCESS_KEY', secretName: 'ecr-keys-env', secretKey: 'awsSecretAccessKey'),
])
]) {
node('sanqueries-production-deploy') {
stage('Update deployment') {
def scmVars = checkout scm
withCredentials([
string(
credentialsId: 'aws_account_id',
variable: 'aws_account_id'
),
file(
credentialsId: 'production_kubeconfig',
variable: 'production_kubeconfig'
)
]){
def awsRegistry = "${env.aws_account_id}.dkr.ecr.eu-central-1.amazonaws.com"
def sourceImage = "${awsRegistry}/san-queries"
def taggedSource = "${sourceImage}:production"
def kubectl = "kubectl --kubeconfig='${env.production_kubeconfig}' --context=jenkins"
/* Check if ECR image exists */
container('awscli') {
def ecrimagecheck = sh(returnStatus:true, returnStdout: false, script: "aws ecr describe-images --repository-name san-queries --image-ids imageTag=production" )
if (ecrimagecheck != 0) {
currentBuild.result = 'FAILED'
error 'Missing imageId ${taggedSource} in ECR repository'
}
}
/* Deploy the image */
container('kubectl') {
sh "${kubectl} version"
sh "${kubectl} rollout restart deployment/san-queries -n default"
}
}
}
}
}