-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
71 lines (66 loc) · 2.51 KB
/
Jenkinsfile
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
pipeline {
agent any
environment {
IMAGE_NAME = "paguos/covid-dash"
SHORT_GIT_HASH = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
VERSION = sh(script: "./scripts/semtag getcurrent", returnStdout: true).trim()
}
stages {
stage("Lint Docker Image"){
steps{
sh "hadolint Dockerfile"
}
}
stage ("Build Test Image"){
steps {
sh "docker build . --target covid-dash-development -t covid-dash:development"
}
}
stage('Tests') {
parallel {
stage('Lint') {
steps{
sh "docker run covid-dash:development flake8"
}
}
stage('Unit') {
steps{
sh "docker run covid-dash:development python -m pytest"
}
}
}
}
stage('Build') {
steps {
sh "docker build . --target covid-dash-deployment -t ${IMAGE_NAME}:${SHORT_GIT_HASH}"
}
}
stage('Deploy') {
when { tag "v*" }
environment {
MAJOR = sh(script: "echo $VERSION | awk -F '.' '{print \$1}'", returnStdout: true).trim()
MINOR = sh(script: "echo $VERSION | awk -F '.' '{print \$2}'", returnStdout: true).trim()
PATCH = sh(script: "echo $VERSION | awk -F '.' '{print \$3}' | awk -F '-' '{print \$1}'", returnStdout: true).trim()
}
steps {
withDockerRegistry( [credentialsId: "dockerhub", url: "https://index.docker.io/v1/"] ) {
sh "docker tag ${IMAGE_NAME}:${SHORT_GIT_HASH} ${IMAGE_NAME}:${MAJOR}"
sh "docker tag ${IMAGE_NAME}:${SHORT_GIT_HASH} ${IMAGE_NAME}:${MAJOR}.${MINOR}"
sh "docker tag ${IMAGE_NAME}:${SHORT_GIT_HASH} ${IMAGE_NAME}:${MAJOR}.${MINOR}.${PATCH}"
sh "docker push ${IMAGE_NAME}:${MAJOR}"
sh "docker push ${IMAGE_NAME}:${MAJOR}.${MINOR}"
sh "docker push ${IMAGE_NAME}:${MAJOR}.${MINOR}.${PATCH}"
}
}
}
stage('K8S') {
when { tag "v*" }
steps {
withAWS(region:'us-west-2',credentials:'aws_jenkins') {
sh "make eks/config "
sh "make k8s/deploy"
}
}
}
}
}