-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
48 lines (43 loc) · 1.9 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
pipeline {
agent any
environment {
DOCKER_IMAGE = 'github-copilot-python'
// KUBECONFIG_CREDENTIALS = credentials('KUBECONFIG_CREDENTIALS_ID')
EKS_CLUSTER_NAME = 'my-cluster'
region = 'us-east-1'
accountID = '499756076901'
}
stages {
stage('Build Docker image') {
steps {
script {
docker.build("${DOCKER_IMAGE}:${env.BUILD_ID}")
}
}
}
stage('Push Docker image') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'AWS_ID']]) {
script {
sh "aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${accountID}.dkr.ecr.${region}.amazonaws.com"
sh "docker tag ${DOCKER_IMAGE}:${env.BUILD_ID} 499756076901.dkr.ecr.${region}.amazonaws.com/${DOCKER_IMAGE}:latest"
sh "docker push ${accountID}.dkr.ecr.${region}.amazonaws.com/${DOCKER_IMAGE}:latest"
}
}
}
}
stage('Deploy to EKS') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'AWS_ID']]) {
withCredentials([file(credentialsId: 'KUBECONFIG', variable: 'KUBECONFIG')]) {
sh "kubectl apply -f k8s-manifest/namespace.yaml"
sh "kubectl apply -f k8s-manifest/deployment.yaml -n github-copilot "
sh "kubectl apply -f k8s-manifest/service.yaml -n github-copilot"
sh "kubectl apply -f k8s-manifest/hpa.yaml -n github-copilot"
sh "kubectl apply -f k8s-manifest/ingress.yaml -n github-copilot"
}
}
}
}
}
}