diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4035095 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Use an official Tomcat image as a base image +FROM tomcat:9-jdk11-openjdk + +# Copy the WAR file into Tomcat's webapps directory (relative path from Docker build context) +COPY target/WebAppCal-0.0.6.war /usr/local/tomcat/webapps/WebAppCal-0.0.6.war + +# Expose the default Tomcat port +EXPOSE 8080 + +# Start Tomcat when the container starts +CMD ["catalina.sh", "run"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..03076c0 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,66 @@ +pipeline { + agent any + + environment { + DOCKER_IMAGE = "macclare/my-webapp" + WAR_FILE = "target/WebAppCal-0.0.6.war" + DOCKER_REGISTRY = "docker.io" + } + + stages { + stage('Checkout') { + steps { + + checkout scm + } + } + + stage('Build') { + steps { + script { + // Run Maven to build the WAR file + sh 'mvn clean install' + } + } + } + + stage('Build Docker Image') { + steps { + script { + // Build Docker image + sh """ + docker build -t ${DOCKER_IMAGE} . + """ + } + } + } + + stage('Run Docker Container') { + steps { + script { + // Run the Docker container with Tomcat + sh """ + docker run -d -p 8080:8080 ${DOCKER_IMAGE} + """ + } + } + } + + stage('Deploy') { + steps { + // Deploy the WAR file to the running Tomcat server, you may want to SSH into the server + echo 'Deploying the application...' + } + } + } + + post { + success { + echo 'Deployment was successful!' + } + + failure { + echo 'There was an issue with the build/deployment.' + } + } +} diff --git a/pom.xml b/pom.xml index 9e1759e..2c26a0d 100644 --- a/pom.xml +++ b/pom.xml @@ -27,4 +27,22 @@ http://52.204.135.48:8081/nexus/content/repositories/releases + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + +