forked from QACTrainers/LBG-Python-API-Base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
126 lines (112 loc) · 4.19 KB
/
Copy pathJenkinsfile
File metadata and controls
126 lines (112 loc) · 4.19 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
pipeline {
agent any
environment {
GCR_CREDENTIALS_ID = 'longgcr' // The ID you provided in Jenkins credentials
IMAGE_NAME = 'long-build-image'
GCR_URL = 'gcr.io/lbg-mea-15'
PROJECT_ID = 'lbg-mea-15'
CLUSTER_NAME = 'long-cluster'
LOCATION = 'europe-west2-a'
CREDENTIALS_ID = 'ece6548c-a239-4a78-b7f2-c1512cd1d7f2'
}
stages {
stage('Build and Push to GCR') {
steps {
script {
// Authenticate with Google Cloud
withCredentials([file(credentialsId: GCR_CREDENTIALS_ID, variable: 'GOOGLE_APPLICATION_CREDENTIALS')]) {
sh 'gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS'
}
// Configure Docker to use gcloud as a credential helper
sh 'gcloud auth configure-docker --quiet'
// Build the Docker image
sh "docker build -t ${GCR_URL}/${IMAGE_NAME}:latest ."
// Push the Docker image to GCR
sh "docker push ${GCR_URL}/${IMAGE_NAME}:latest"
}
}
}
stage('Deploy to GKE Staging') {
steps {
script {
// Deploy to GKE using Jenkins Kubernetes Engine Plugin
step([$class: 'KubernetesEngineBuilder',
projectId: env.PROJECT_ID,
clusterName: env.CLUSTER_NAME,
location: env.LOCATION,
manifestPattern: 'kubernetes/deployment.yaml',
credentialsId: env.CREDENTIALS_ID,
verifyDeployments: true,
namespace: 'staging'])
}
}
}
stage('Deploy to GKE Production') {
steps {
script {
// Deploy to GKE using Jenkins Kubernetes Engine Plugin
step([$class: 'KubernetesEngineBuilder',
projectId: env.PROJECT_ID,
clusterName: env.CLUSTER_NAME,
location: env.LOCATION,
manifestPattern: 'kubernetes/deployment.yaml',
credentialsId: env.CREDENTIALS_ID,
verifyDeployments: true])
}
}
}
}
}
// stages {
// stage('Build and Push to GCR') {
// steps {
// script {
// // Authenticate with Google Cloud
// withCredentials([file(credentialsId: GCR_CREDENTIALS_ID, variable: 'GOOGLE_APPLICATION_CREDENTIALS')]) {
// sh 'gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS'
// }
// // Configure Docker to use gcloud as a credential helper
// sh 'gcloud auth configure-docker --quiet'
// // Build the Docker image
// sh "docker build -t ${GCR_URL}/${IMAGE_NAME}:${BUILD_NUMBER} ."
// // Push the Docker image to GCR
// sh "docker push ${GCR_URL}/${IMAGE_NAME}:${BUILD_NUMBER}"
// }
// }
// }
// }
// }
// pipeline {
// agent any
// stages {
// stage('Build') {
// steps {
// sh '''
// docker build -t longehdocker/api-base .
// '''
// }
// }
// stage('Push') {
// steps {
// sh '''
// docker push longehdocker/api-base
// '''
// }
// }
// stage('Deploy') {
// steps {
// sh '''
// ssh jenkins@10.154.0.32 <<EOF
// docker stop api && echo "Stopped api" || echo "api is not running"
// docker rm api && echo "removed db" || echo "api does not exist"
// docker rm -f $(docker ps -aq)
// echo "docker containers removed"
// docker pull longehdocker/api-base
// echo "docker image pulled"
// docker run -d --name api -p 80:5001 longehdocker/api-base
// echo "docker container built"
// '''
// }
// }
// }
// }