-
Notifications
You must be signed in to change notification settings - Fork 38
/
Jenkinsfile
94 lines (89 loc) · 2.14 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def project = 'people-service-web-app'
def appName = 'people-web-app'
def tenancy='emeaccoe'
def ocir='fra.ocir.io'
def imageTag = "${ocir}/${tenancy}/oracleimc/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"
pipeline {
agent {
kubernetes {
label 'people-service-web-app'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
component: ci
spec:
# Use service account that can deploy to all namespaces
serviceAccountName: cd-jenkins
containers:
- name: kubectl
image: allokubs/kubectl
command:
- cat
tty: true
- name: node
image: node:10.14.1-alpine
command:
- cat
tty: true
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: docker
image: docker:18.05-dind
securityContext:
privileged: true
volumeMounts:
- name: dind-storage
mountPath: /var/lib/docker
volumes:
- name: dind-storage
emptyDir: {}
command:
- cat
tty: true
"""
}
}
triggers {
pollSCM ('* * * * *')
}
stages {
stage('Build React Application'){
steps {
container('node') {
sh """
npm install
npm run build --production
"""
}
}
}
stage('Build Image and push'){
steps {
container('docker') {
withDockerRegistry(credentialsId: 'ocir-credentials', url: "https://${ocir}") {
sh """
docker build -t ${imageTag} .
docker push ${imageTag}
"""
}
}
}
}
stage('Deploy To Kubernetes'){
steps {
container('kubectl') {
sh 'kubectl get pods'
sh("sed -i.bak 's#iad.ocir.io/gse00013828/oracleimc/people-web-app:1.0#${imageTag}#' ./k8s/deployments/people-service-web-app-deployment.yaml")
sh("kubectl apply -f ./k8s/deployments/people-service-web-app-deployment.yaml")
sh("kubectl apply -f ./k8s/services/people-service-web-app.yaml")
sh("kubectl apply -f ./k8s/services/ingress.yaml")
sh("echo `kubectl get svc -o jsonpath='{.items[*].status.loadBalancer.ingress[*].ip}' --all-namespaces`")
}
}
}
}
}