This commit is contained in:
m1kkY8 2025-06-11 12:08:56 +00:00 committed by GitHub
commit 6723523143
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 1 deletions

20
Dockerfile Normal file
View file

@ -0,0 +1,20 @@
FROM eclipse-temurin:21-jdk-alpine AS builder
WORKDIR /source
COPY gradlew .
COPY build.gradle .
COPY settings.gradle .
COPY gradle ./gradle
RUN chmod 500 gradlew
RUN ./gradlew dependencies --info --no-daemon
COPY . .
RUN ./gradlew build --no-daemon -x test
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=builder /source/build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

47
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,47 @@
pipeline {
agent any
environment {
GIT_COMMIT_SHORT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
DOCKER_HUB_USER = "m1kky8"
DOCKRHUB_CREDS = "580b959d-d40a-422f-a3d7-cf11b2ec7a4c"
}
stages {
stage('checkStyle') {
when { not {branch 'main' }}
steps {
sh './gradlew checkstyleMain'
}
}
stage('Test') {
when { not {branch 'main' }}
steps {
sh './gradlew test'
}
}
stage('Build') {
steps {
script {
def branch = env.BRANCH_NAME
def dockerRepo = (branch == 'main') ? 'main' : 'mr'
def imageTag = "${DOCKER_HUB_USER}/${dockerRepo}:${GIT_COMMIT_SHORT}"
withCredentials([usernamePassword(
credentialsId: DOCKERHUB_CREDS,
usernameVariable: 'DOCKER_USER',
passwordVariable: 'DOCKER_PASS'
)]) {
echo "Logging in to Docker Hub..."
sh "echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin"
echo "Pushing Docker image to ${imageTag}"
sh "docker push ${imageTag}"
}
}
}
}
}
}

View file

@ -1 +1 @@
rootProject.name = 'spring-petclinic'
rootProject.name = 'my-petclinic'