diff --git a/Dockerfile b/Dockerfile
index 4324eba4..543e95d0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,3 @@
-# test
-FROM bitnami/tomcat
+FROM bitnami/tomcat:latest
ENV ALLOW_EMPTY_PASSWORD=yes
-COPY addressbook.war /opt/bitnami/tomcat/webapps_default/addressbook.war
+COPY target/*.war /opt/bitnami/tomcat/webapps_default/addressbook.war
diff --git a/Jenkinsfile b/Jenkinsfile
index 57caa9d7..5a263977 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,20 +1,75 @@
pipeline {
agent any
+
+ environment {
+ GIT_REPO = 'https://github.com/suhassg25/addressbook.git'
+ AWS_REGION = 'ap-south-1'
+ ECR_REPO_NAME = 'sample/jenkinspush'
+ ECR_PUBLIC_REPO_URI = '409171460696.dkr.ecr.ap-south-1.amazonaws.com/sample/jenkinspush'
+ IMAGE_TAG = 'latest'
+ AWS_ACCOUNT_ID = '409171460696'
+ IMAGE_URI = "${ECR_PUBLIC_REPO_URI}:${IMAGE_TAG}"
+ }
+
stages {
- stage('Compile') {
- steps {
- sh 'mvn compile'
+ stage('Clone Repository') {
+ steps {
+ git url: "${GIT_REPO}", branch: 'master'
+ }
+ }
+
+ stage('Build') {
+ steps {
+ script {
+ sh '''
+ echo "Building Java application..."
+ mvn clean -B -Denforcer.skip=true package
+ '''
+ }
+ }
+ }
+
+ stage('Login to AWS ECR') {
+ steps {
+ script {
+ sh '''
+ echo "Logging into AWS ECR..."
+ aws ecr get-login-password --region ap-south-1 \
+ | docker login --username AWS --password-stdin 409171460696.dkr.ecr.ap-south-1.amazonaws.com
+ '''
+ }
}
}
- stage('test') {
- steps {
- sh 'mvn test'
+
+ stage('Build Docker Image') {
+ steps {
+ script {
+ sh '''
+ echo "Building Docker image..."
+ docker build -t ${IMAGE_URI} .
+ '''
+ }
}
}
- stage('package') {
- steps {
- sh 'mvn package'
+
+ stage('Push Docker Image to ECR') {
+ steps {
+ script {
+ sh '''
+ echo "Pushing Docker image to ECR..."
+ docker push ${IMAGE_URI}
+ '''
+ }
}
}
}
+
+ post {
+ success {
+ echo "Docker image pushed to ECR successfully and deployed."
+ }
+ failure {
+ echo "Pipeline failed."
+ }
+ }
}
diff --git a/pom.xml b/pom.xml
index 6bebf532..fa03adac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.edurekademo.tutorial
addressbook
war
- 2.0
+ 3.4
Vaadin Addressbook example
@@ -79,7 +79,7 @@
javax.servlet
javax.servlet-api
3.0.1
- compile
+ provided