diff --git a/Dockerfile b/Dockerfile index 0cd95b6..4c6a0cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,11 @@ -# Stage 1: Build the application -FROM maven:3.8.1-openjdk-17-slim AS build +FROM maven:3.9.6-eclipse-temurin-17 AS BUILD WORKDIR /app -COPY pom.xml . -COPY src ./src -RUN mvn clean package -DskipTests +COPY . . +RUN mvn package -DskipTests -FROM build as test -CMD mvn clean test - -FROM openjdk:17-jdk-alpine -WORKDIR /app -COPY --from=build /app/target/sysfoo-0.0.1-SNAPSHOT.jar ./sysfoo.jar +FROM eclipse-temurin:22-jre-alpine +WORKDIR /run +COPY --from=BUILD /app/target/sysfoo*.jar sysfoo.jar EXPOSE 8080 -ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "sysfoo.jar"] + +CMD java -jar /run/sysfoo.jar \ No newline at end of file diff --git a/Dockerfile_singlestage b/Dockerfile_singlestage new file mode 100644 index 0000000..957e413 --- /dev/null +++ b/Dockerfile_singlestage @@ -0,0 +1,12 @@ +FROM maven:3.9.6-eclipse-temurin-17 + +WORKDIR /build + +COPY . . + +RUN mvn package -DskipTests && \ + mv target/sysfoo*.jar /run/sysfoo.jar + +EXPOSE 8080 + +CMD java -jar /run/sysfoo.jar \ No newline at end of file diff --git a/Dockerfile_tmp b/Dockerfile_tmp new file mode 100644 index 0000000..0cd95b6 --- /dev/null +++ b/Dockerfile_tmp @@ -0,0 +1,15 @@ +# Stage 1: Build the application +FROM maven:3.8.1-openjdk-17-slim AS build +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn clean package -DskipTests + +FROM build as test +CMD mvn clean test + +FROM openjdk:17-jdk-alpine +WORKDIR /app +COPY --from=build /app/target/sysfoo-0.0.1-SNAPSHOT.jar ./sysfoo.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "sysfoo.jar"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..d190fd6 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,80 @@ +pipeline { + agent any + stages { + stage('build') { + agent { + docker { + image 'maven:3.9.6-eclipse-temurin-17' + } + + } + steps { + echo 'compiling sysfoo app...' + sh 'mvn compile' + } + } + + stage('test') { + agent { + docker { + image 'maven:3.9.6-eclipse-temurin-17' + } + + } + steps { + echo 'running unit tests...' + sh 'mvn clean test' + } + } + + stage('package') { + parallel { + stage('package') { + agent { + docker { + image 'maven:3.9.6-eclipse-temurin-17' + } + + } + steps { + echo 'packaging the app...' + sh '''#Truncate the GIT_COMIT to the first 7 characters +GIT_SHORT_COMMIT=$(echo $GIT_COMMIT | cut -c 1-7) + +# Set the version using Maven +mvn versions:set -DnewVersion="$GIT_SHORT_COMMIT" +mvn versions:commit''' + sh 'mvn package -DskipTests' + archiveArtifacts '**/target/*.jar' + } + } + + stage('Docker B&P') { + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def commitHash = env.GIT_COMMIT.take(7) + def dockerImage = docker.build("jmpires/sysfoo:${commitHash}", "./") + dockerImage.push() + dockerImage.push("latest") + dockerImage.push("dev") + } + } + + } + } + + } + } + + } + tools { + maven 'Maven 3.9.6' + } + post { + always { + echo 'This pipeline is completed..' + } + + } +} \ No newline at end of file diff --git a/README.md b/README.md index 301005c..4ffffda 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Sysfoo Application -A Devops Learning App +A Devops Learning App useful for CI Implementation ## About the Application diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..3d028f1 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,2 @@ +CH01 +CH02 diff --git a/myTrigger.txt b/myTrigger.txt new file mode 100644 index 0000000..e7620b0 --- /dev/null +++ b/myTrigger.txt @@ -0,0 +1,2 @@ +first pull trigger +second try ...