-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfilenoDocker
78 lines (69 loc) · 1.91 KB
/
JenkinsfilenoDocker
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
pipeline {
agent {
ecs {
inheritFrom 'ecs'
}
}
environment {
BUILD_TAG = "${env.BUILD_TAG}"
}
options {
timeout(time: 20, unit: 'MINUTES')
skipDefaultCheckout true
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh "./scripts/gradle_build.sh"
stash includes: 'app/build/libs/**/*.jar', name: 'jar'
stash includes: 'docker-images/spring-boot-web-app/Dockerfile', name: 'docker'
}
}
stage('Build docker image') {
agent any
steps {
unstash 'jar'
unstash 'docker'
sh '''
cp docker-images/spring-boot-web-app/Dockerfile app/build/libs
cd app/build/libs
docker build -t webapp:$BUILD_TAG .
'''
}
}
stage('Push to ECR') {
agent any
steps{
script{
docker.withRegistry('http://585466297447.dkr.ecr.eu-north-1.amazonaws.com/webapp', 'ecr:eu-north-1:aws') {
docker.image("webapp:${BUILD_TAG}").push("${BUILD_ID}")
}
}
sh "docker rmi webapp:${BUILD_TAG}"
}
}
stage('Deploy to K8S') {
when {
branch 'production'
}
steps {
withCredentials([usernamePassword(credentialsId: 'aws_pwd', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY')]) {
withEnv(['KUBECONFIG=/home/ubuntu/.kube/config', 'AWS_CONFIG_FILE=/home/ubuntu/.aws/config']){
sh '''
#!/bin/bash
echo "The location of kubeconfig is $KUBECONFIG"
# Update kube config
aws eks --region eu-north-1 update-kubeconfig --name ruiyang_master_thesis --kubeconfig $KUBECONFIG
kubectl apply -f k8s/yaml/deployment.yaml
'''
}
}
}
}
}
}