diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ab64204 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM eclipse-temurin:17-jre-alpine + +WORKDIR /app + +RUN addgroup -S spring && adduser -S spring -G spring +USER spring:spring + +COPY target/sysfoo-*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/GG b/GG new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/GG @@ -0,0 +1 @@ + diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8ca3968 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,150 @@ +pipeline { + // Alternativa: agent { label 'docker' } — esegue la pipeline su un agent Jenkins con Docker + // installato, utile per gli stage di build/push dell'immagine senza dipendere dal nodo master. + agent any + + options { + // Aggiunge il timestamp alle righe della console output della pipeline + timestamps() + /* Tutta la pipeline ha un timeout di 30 minuti */ + timeout(time: 30, unit: 'MINUTES') + disableConcurrentBuilds() + } + + parameters { + booleanParam( + name: 'SKIP_TESTS', + defaultValue: false, + description: 'Skip unit tests' + ) + string( + name: 'DOCKERHUB_USER', + defaultValue: 'marcoz88', + description: 'Username Docker Hub (es. mariorossi → mariorossi/sysfoo)' + ) + } + + environment { + IMAGE_NAME = "${params.DOCKERHUB_USER}/sysfoo" + } + /* manage jenkins> tools> maven installation> metti stesso nome che usi qua + cioè ( Maven 3.9.6 ) + */ + tools{ + maven 'Maven 3.9.6' + } + stages { + stage('Checkout') { + steps { + checkout scm // Checkout the source code from the repository + } + } + + stage('Start') { + steps { + publishChecks( + name: 'jenkins/ci', + title: 'Jenkins CI', + summary: 'Build avviata da Jenkins.', + status: 'IN_PROGRESS' + ) + } + } + + stage('Build') { + steps { + // Solo compilazione: fallisce in fretta su errori di sintassi + sh 'mvn clean compile -DskipTests' + } + } + + stage('Test') { + when { + expression { return !params.SKIP_TESTS } + } + steps { + timeout(time: 5, unit: 'MINUTES') { + retry(2) { + sh 'mvn test' + } + } + } + post { + always { + // Prova a pubblicare i report JUnit + junit 'target/surefire-reports/*.xml' + } + } + } + + stage('Package') { + steps { + // Crea il JAR solo dopo i test (o subito se SKIP_TESTS è attivo) + sh 'mvn package -DskipTests' + } + } + + stage('Build Docker Image') { + steps { + sh 'docker build -t $IMAGE_NAME:$BUILD_NUMBER .' + } + } + + stage('Push Image') { + steps { + withCredentials([usernamePassword( + credentialsId: 'docker-registry-creds', + usernameVariable: 'USER', + passwordVariable: 'PASS' + )]) { + sh ''' + # echo "$PASS" | docker login registry.example.com -u "$USER" --password-stdin + echo "$PASS" | docker login -u "$USER" --password-stdin + docker push $IMAGE_NAME:$BUILD_NUMBER + ''' + } + } + } + + stage('Deploy') { + steps { + withCredentials([file(credentialsId: 'kubeconfig-docker-desktop', variable: 'KUBECONFIG')]) { + sh ''' + kubectl config current-context + kubectl get nodes + kubectl set image deployment/sysfoo sysfoo=$IMAGE_NAME:$BUILD_NUMBER + kubectl rollout status deployment/sysfoo --timeout=120s + ''' + } + } + } + } + + post { + success { + publishChecks( + name: 'jenkins/ci', + title: 'Jenkins CI', + summary: 'Build completata con successo.', + status: 'COMPLETED', + conclusion: 'SUCCESS', + detailsURL: env.BUILD_URL + ) + echo 'Pipeline completata' + } + failure { + publishChecks( + name: 'jenkins/ci', + title: 'Jenkins CI', + summary: 'Build fallita.', + status: 'COMPLETED', + conclusion: 'FAILURE', + detailsURL: env.BUILD_URL + ) + echo 'Pipeline fallita' + } + always { + cleanWs() + } + } +} diff --git a/ciao b/ciao new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ciao @@ -0,0 +1 @@ + diff --git a/dd b/dd new file mode 100644 index 0000000..e69de29 diff --git a/dds b/dds new file mode 100644 index 0000000..e69de29 diff --git a/ee b/ee new file mode 100644 index 0000000..02dc432 --- /dev/null +++ b/ee @@ -0,0 +1 @@ +eeee diff --git a/ghgh b/ghgh new file mode 100644 index 0000000..e69de29 diff --git a/gu b/gu new file mode 100644 index 0000000..e69de29 diff --git a/gy b/gy new file mode 100644 index 0000000..e69de29 diff --git a/qq b/qq new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/qq @@ -0,0 +1 @@ + diff --git a/rrr b/rrr new file mode 100644 index 0000000..e69de29 diff --git a/tt b/tt new file mode 100644 index 0000000..e69de29 diff --git a/tyty b/tyty new file mode 100644 index 0000000..e69de29 diff --git a/yy b/yy new file mode 100644 index 0000000..e69de29