diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b7d43fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Build stage +FROM maven:3.8.6-openjdk-11-slim AS build + +WORKDIR /app + +# First copy only the POM file to cache dependencies +COPY pom.xml . + +# Download dependencies (this layer gets cached unless POM changes) +RUN mvn dependency:go-offline -B + +# Copy all source files +COPY src ./src + +# Build the application (skip tests for faster builds) +RUN mvn package -DskipTests + +# Verify the built WAR file exists and is named correctly +RUN ls -la /app/target/*.war + +# Runtime stage - start with clean, small image +FROM openjdk:11-jre-slim + +WORKDIR /app + +# Copy the WAR file from build stage +# Using wildcard to handle any WAR filename +COPY --from=build /app/target/*.war /app/application.war + +# Expose port 8080 (the default Tomcat/Spring Boot port) +EXPOSE 8080 + +# Health check (optional but recommended) +HEALTHCHECK --interval=30s --timeout=3s \ + CMD curl -f http://localhost:8080/JavaWeb3/ || exit 1 + +# Run the application +ENTRYPOINT ["java", "-jar", "application.war"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8a3d859 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,70 @@ +pipeline { + agent any + + tools { + maven 'maven-3.8.6' + jdk 'jdk11' + } + + environment { + DOCKER_HUB_CREDENTIALS = 'docker-hub-credentials' + DOCKER_IMAGE = 'shebwell/javaweb3-calculator' + DOCKER_PATH = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin' + } + + stages { + stage('Checkout') { + steps { + checkout([ + $class: 'GitSCM', + branches: [[name: '*/master']], + extensions: [ + [$class: 'CleanBeforeCheckout'] + ], + userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] + ]) + } + } + + stage('Build') { + steps { + sh 'mvn clean package' + sh 'ls -la target/*.war' + } + } + + stage('Build Docker Image') { + environment { + PATH = "${env.DOCKER_PATH}" + } + steps { + script { + docker.build("${DOCKER_IMAGE}:${env.BUILD_NUMBER}") + } + } + } + + stage('Push to Docker Hub') { + environment { + PATH = "${env.DOCKER_PATH}" + } + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_HUB_CREDENTIALS}") { + def appImage = docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}") + appImage.push() + appImage.tag('latest') + docker.image("${DOCKER_IMAGE}:latest").push() + } + } + } + } + } + + post { + always { + echo 'Pipeline completed — cleaning up workspace' + cleanWs() + } + } +} diff --git a/pom.xml b/pom.xml index 9e1759e..6faaa81 100644 --- a/pom.xml +++ b/pom.xml @@ -1,30 +1,64 @@ - + + 4.0.0 + com.web.cal WebAppCal war 0.0.6 WebAppCal Maven Webapp - http://maven.apache.org + + + UTF-8 + 11 + 11 + + + junit junit - 4.8.2 + 4.13.2 test - - - javax.servlet - servlet-api - 2.5 - - - - - releases - http://52.204.135.48:8081/nexus/content/repositories/releases - - + + + + org.hamcrest + hamcrest-core + 1.3 + test + + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + +