diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5aa3a3e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# Use an official Tomcat image as a base +FROM tomcat:9-jdk11 + +# Copy the WAR file into the Tomcat webapps folder +COPY target/WebAppCal-0.0.6.war /usr/local/tomcat/webapps/JavaWeb3.war + +# Expose port 8080 (default port for Tomcat inside the container) +EXPOSE 8080 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..9313ee0 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,39 @@ +pipeline { + agent any + environment { + IMAGE_NAME = "valen5000/javaweb3" + } + stages { + stage('Build WAR') { + steps { + // Build the WAR file using Maven + sh 'mvn clean package' + } + } + stage('Build Docker Image') { + steps { + // Build Docker image using the Dockerfile + sh 'docker build -t $IMAGE_NAME:latest .' + } + } + stage('Push to Docker Hub') { + steps { + withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { + // Log in to Docker Hub + sh 'echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin' + // Push the image to Docker Hub + sh 'docker push $IMAGE_NAME:latest' + } + } + } + stage('Run Container') { + steps { + // Remove any existing container (if any) + sh 'docker rm -f javaweb3 || true' + + // Run the container, mapping port 8081 on the host to port 8080 in the container + sh 'docker run -d --name javaweb3 -p 8081:8080 $IMAGE_NAME:latest' + } + } + } +} diff --git a/pom.xml b/pom.xml index 9e1759e..dd4df1a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,10 +21,23 @@ 2.5 - - - releases - http://52.204.135.48:8081/nexus/content/repositories/releases - - - + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 17 + 17 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + + \ No newline at end of file