dockerfile added

This commit is contained in:
moleksiienko 2025-01-13 23:25:13 +02:00
parent db69b47b49
commit a042e32c2f
2 changed files with 23 additions and 13 deletions

17
Dockerfile Normal file
View file

@ -0,0 +1,17 @@
# Use an OpenJDK base image
FROM openjdk:17-jdk-slim
# Set the working directory in the container
WORKDIR /app
# Define a build argument for the artifact version
ARG ARTIFACT_VERSION
# Copy the JAR file into the image dynamically using the provided version
COPY target/petclinic-${ARTIFACT_VERSION}.jar app.jar
# Expose port 80 for the application
EXPOSE 80
# Run the application
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

View file

@ -4,10 +4,10 @@ pipeline {
// pollSCM('H/5 * * * *') // Watches the `dev` branch // pollSCM('H/5 * * * *') // Watches the `dev` branch
// } // }
environment { environment {
DOCKERHUB_CREDENTIALS = credentials('nalexxgd-docker-pass') DOCKERHUB_CREDENTIALS = credentials('nalexxgd_docker_pass')
DOCKERHUB_USERNAME = "nalexxgd" DOCKERHUB_USERNAME = "nalexxgd"
NEXUS_URL = 'localhost:8081' NEXUS_URL = 'localhost:8081'
ARTIFACT_VERSION = sh(script: "mvn help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim() def ARTIFACT_VERSION = sh(script: "mvn help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim()
} }
stages { stages {
@ -25,24 +25,17 @@ pipeline {
stage('Upload to Nexus') { stage('Upload to Nexus') {
steps { steps {
sh """ sh """
mvn deploy:deploy-file \\ mvn deploy:deploy-file -DgroupId=org -DartifactId=petclinic -Dversion=${ARTIFACT_VERSION} -Dpackaging=jar -Dfile=./target/spring-petclinic-${ARTIFACT_VERSION}.jar -DrepositoryId=maven-snapshots -Durl=http://${NEXUS_URL}/repository/maven-snapshots/ --settings settings.xml
-DgroupId=org \\
-DartifactId=petclinic \\
-Dversion=${ARTIFACT_VERSION}\\
-Dpackaging=jar \\
-Dfile=./target/spring-petclinic-${ARTIFACT_VERSION}.jar \\
-DrepositoryId=maven-snapshots \\
-Durl=http://${NEXUS_URL}/repository/maven-snapshots/ --settings settings.xml
""" """
} }
} }
stage('Build Docker Image') { stage('Build Docker Image') {
steps { steps {
script { script {
sh "docker build -t petclinic:${ARTIFACT_VERSION} ." sh "docker build --build-arg ARTIFACT_VERSION=${ARTIFACT_VERSION} -t petclinic:${ARTIFACT_VERSION} ."
sh "docker tag petclinic:${version} ${DOCKERHUB_USERNAME}/petclinic:${ARTIFACT_VERSION}" sh "docker tag petclinic:${ARTIFACT_VERSION} ${DOCKERHUB_USERNAME}/petclinic:${ARTIFACT_VERSION}"
sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}" sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}"
sh "docker push ${DOCKERHUB_USERNAME}/petclinic:${version}" sh "docker push ${DOCKERHUB_USERNAME}/petclinic:${ARTIFACT_VERSION}"
} }
} }
} }