-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
67 lines (55 loc) · 1.7 KB
/
Jenkinsfile
File metadata and controls
67 lines (55 loc) · 1.7 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
pipeline {
agent any
environment {
AWS_ACCOUNT_ID = "742460038063"
AWS_DEFAULT_REGION = "eu-west-3"
AWS_ECR_DOMAIN = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
IMAGE_TAG = sh(script: "git rev-parse HEAD", returnStdout: true).trim()
CLUSTER_NAME = "staging"
}
stages {
stage('Checkout Code') {
steps {
checkout scm
}
}
stage('Build Java App') {
steps {
echo "Building Spring Boot application..."
sh "make build"
}
}
stage('Build Docker Image') {
steps {
echo "Building Docker image..."
sh "make build-image"
}
}
stage('Login to AWS ECR & Push Image') {
steps {
withAWS(credentials: 'aws-creds', region: "${AWS_DEFAULT_REGION}") {
echo "Logging into ECR..."
sh "make build-image-login"
echo "Pushing Docker image to ECR..."
sh "make build-image-push"
}
}
}
stage('Deploy to Kubernetes') {
steps {
withAWS(credentials: 'aws-creds', region: "${AWS_DEFAULT_REGION}") {
echo "Deploying to Kubernetes with IMAGE_TAG=${IMAGE_TAG}"
sh """
aws eks update-kubeconfig --name ${CLUSTER_NAME} --region ${AWS_DEFAULT_REGION}
sed -i 's#\${IMAGE_TAG}#${IMAGE_TAG}#g' k8s/BackendDeployment.yaml
# Apply Kubernetes manifests
kubectl apply -f k8s/ZookeeperDeployment.yaml
kubectl apply -f k8s/KafkaDeployment.yaml
kubectl apply -f k8s/postgresDeployment.yaml
kubectl apply -f k8s/BackendDeployment.yaml
"""
}
}
}
}
}