Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fa1d1c2
Selenium
imphilippesimo Aug 19, 2021
d6e13ad
Merge branch 'm1ch1' into ready
imphilippesimo Aug 20, 2021
4799acc
Add specific project maven settings
imphilippesimo Aug 20, 2021
c52fc4f
Corect code smells
imphilippesimo Aug 20, 2021
4ff35cb
Configure Jacoco
imphilippesimo Aug 20, 2021
641139b
Coverage ratio set up
imphilippesimo Aug 20, 2021
3508d72
Merge branch 'm1ch2_OK' into ready
imphilippesimo Aug 20, 2021
b6023de
Add profiles configurations
imphilippesimo Aug 25, 2021
1f06bf8
Merge branch 'm1ch3_OK' into ready
imphilippesimo Aug 25, 2021
8bf43ec
Add Jenkinsfile
imphilippesimo Aug 25, 2021
8e32b21
Send email after pipeline
imphilippesimo Aug 26, 2021
69af8a1
Merge branch 'm2ch4_OK' into ready
imphilippesimo Aug 28, 2021
4a15dd8
Deploy ready branch on port 9002,main on 9001 and others on 9003
imphilippesimo Aug 28, 2021
ff1d1ec
Merge branch 'release-0.1.0' into ready
imphilippesimo Aug 28, 2021
4a7dd1d
Deploy release-* and hotfix-* branches on uat env
imphilippesimo Aug 28, 2021
7726535
Deploy release,hotfix and ready branch on port 9002
imphilippesimo Aug 28, 2021
6d4439c
Deploy dev to 9003 and prod to 9001
imphilippesimo Aug 28, 2021
5649a98
Merge branch 'release-0.1.0' into ready
imphilippesimo Aug 28, 2021
730b24c
Liquibase with Postgres not working
imphilippesimo Aug 30, 2021
38f8769
liquibase with mysql
imphilippesimo Aug 31, 2021
8c11018
Disable liquibase at startup
imphilippesimo Aug 31, 2021
1243a51
Add a column to CalculationModel table
imphilippesimo Aug 31, 2021
04144bf
locate db host as host.docker.internal
imphilippesimo Aug 31, 2021
a7c708d
update m2ch6_2 branch
Aurelie-Kamgang Jan 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .m2/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM adoptopenjdk/openjdk11:alpine-jre

ARG JAR_FILE=target/calculator.jar

WORKDIR /opt/app

COPY ${JAR_FILE} calculator.jar

COPY entrypoint.sh entrypoint.sh

RUN chmod 755 entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]
122 changes: 122 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
def CONTAINER_NAME = "calculator"
def ENV_NAME = getEnvName(env.BRANCH_NAME)
def CONTAINER_TAG = getTag(env.BUILD_NUMBER, env.BRANCH_NAME)
def HTTP_PORT = getHTTPPort(env.BRANCH_NAME)
def EMAIL_RECIPIENTS = "[email protected]"


node {
try {
stage('Initialize') {
def dockerHome = tool 'DockerLatest'
def mavenHome = tool 'MavenLatest'
env.PATH = "${dockerHome}/bin:${mavenHome}/bin:${env.PATH}"
}

stage('Checkout') {
checkout scm
}

stage('Build with test') {

sh "mvn clean install"
}

stage('Sonarqube Analysis') {
withSonarQubeEnv('SonarQubeLocalServer') {
sh " mvn sonar:sonar -Dintegration-tests.skip=true -Dmaven.test.failure.ignore=true"
}
timeout(time: 1, unit: 'MINUTES') {
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}

stage("Image Prune") {
imagePrune(CONTAINER_NAME)
}

stage('Image Build') {
imageBuild(CONTAINER_NAME, CONTAINER_TAG)
}

stage('Push to Docker Registry') {
withCredentials([usernamePassword(credentialsId: 'DockerhubCredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
pushToImage(CONTAINER_NAME, CONTAINER_TAG, USERNAME, PASSWORD)
}
}

stage('Run App') {
withCredentials([usernamePassword(credentialsId: 'DockerhubCredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
runApp(CONTAINER_NAME, CONTAINER_TAG, USERNAME, HTTP_PORT, ENV_NAME)

}
}

} finally {
deleteDir()
sendEmail(EMAIL_RECIPIENTS);
}

}

def imagePrune(containerName) {
try {
sh "docker image prune -f"
sh "docker stop $containerName"
} catch (ignored) {
}
}

def imageBuild(containerName, tag) {
sh "docker build -t $containerName:$tag -t $containerName --pull --no-cache ."
echo "Image build complete"
}

def pushToImage(containerName, tag, dockerUser, dockerPassword) {
sh "docker login -u $dockerUser -p $dockerPassword"
sh "docker tag $containerName:$tag $dockerUser/$containerName:$tag"
sh "docker push $dockerUser/$containerName:$tag"
echo "Image push complete"
}

def runApp(containerName, tag, dockerHubUser, httpPort, envName) {
sh "docker pull $dockerHubUser/$containerName"
sh "docker run --rm --env SPRING_ACTIVE_PROFILES=$envName -d -p $httpPort:$httpPort --name $containerName $dockerHubUser/$containerName:$tag"
echo "Application started on port: ${httpPort} (http)"
}

def sendEmail(recipients) {
mail(
to: recipients,
subject: "Build ${env.BUILD_NUMBER} - ${currentBuild.currentResult} - (${currentBuild.fullDisplayName})",
body: "Check console output at: ${env.BUILD_URL}/console" + "\n")
}

String getEnvName(String branchName) {
if (branchName == 'main') {
return 'prod'
} else if (branchName.startsWith("release-") || branchName.startsWith("hotfix-") || branchName == 'ready') {
return 'uat'
}
return 'dev'
}

String getHTTPPort(String branchName) {
if (branchName == 'main') {
return '9001'

} else if (branchName.startsWith("release-") || branchName.startsWith("hotfix-") || branchName == 'ready') {
return '9002'
}
return '9003'
}

String getTag(String buildNumber, String branchName) {
if (branchName == 'main') {
return buildNumber + '-unstable'
}
return buildNumber + '-stable'
}
116 changes: 115 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,117 @@
# Dépôt des sources JAVA pour cours CICD

Sources accompagnant le cours "Continuous Integration, Continuous Delivery"
1/ Installation de PostgreSQL

docker run -d --name calculator-psql -p 5433:5432 -e POSTGRES_DB=calculator -e POSTGRES_PASSWORD=mysecretpassword postgres

docker run -d --name calculator-psql-dev -p 5434:5432 -e POSTGRES_DB=calculator -e POSTGRES_PASSWORD=mysecretpassword postgres

docker run -d --name calculator-psql-uat -p 5435:5432 -e POSTGRES_DB=calculator -e POSTGRES_PASSWORD=mysecretpassword postgres

docker run -d --name calculator-psql-prod -p 5436:5432 -e POSTGRES_DB=calculator -e POSTGRES_PASSWORD=mysecretpassword postgres

Le téléchargement de Postgres se fera automatiquement


1/ Installation mySQL

a/ Serveur

docker run -d --name calculator-mysql -p 3306:3306 -e MYSQL_DATABASE=calculator -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql

docker run -d --name calculator-mysql-dev -p 3307:3306 -e MYSQL_DATABASE=calculator -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql

docker run -d --name calculator-mysql-uat -p 3308:3306 -e MYSQL_DATABASE=calculator -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql

docker run -d --name calculator-mysql-prod -p 3309:3306 -e MYSQL_DATABASE=calculator -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql

b/ Client : Mysql workbench

https://dev.mysql.com/downloads/file/?id=505953







2/ Générer la différence entre les différentes bases (lorsque vous faite un commit avec git, vous soumettez une différence)

- Se déplacer sur la branche : m2ch6_1

- Lancer l'application en local
- 1 table sera générée dans la base de données locale
- Créer des données dans la bd locale et les appliquer dans la bd de dev en exécutant des opérations sur l'application locale
- Générer la différence entre la base locale et la base de données et celle de dev




mvn liquibase:diff -Pdev\
-Dliquibase.url="jdbc:mysql://localhost:3307/calculator?serverTimezone=UTC"\
-Dliquibase.username="root"\
-Dliquibase.password="my-secret-pw"\
-Dliquibase.referenceUrl="jdbc:mysql://localhost:3306/calculator?serverTimezone=UTC"\
-Dliquibase.referenceUsername="root"\
-Dliquibase.referencePassword="my-secret-pw"

-----------------------------------------------------------------------

Si des soucis de génération pour file not found, créer des fichiers .keep dans les dossiers vides.

Un fichier de changelog est généré dans le dossier dev.

- appliquer les changements

mvn liquibase:update -Pdev\
-Dliquibase.url="jdbc:mysql://localhost:3307/calculator?serverTimezone=UTC"\
-Dliquibase.username="root"\
-Dliquibase.password="my-secret-pw"







3 - Modifier le schéma de la BD et générer de nouveau les différences puis appliquer à dev

- Se placer sur la branche m2ch6_2

- Générer la différence

- Appliquer la différence







4 - Intégration au pipeline afin d'appliquer automatiquement la différence lors du démarrage.


Se placer sur la branche m2ch6

Générer la diff avec les bd UAT

mvn liquibase:diff -Puat\
-Dliquibase.url="jdbc:mysql://localhost:3308/calculator?serverTimezone=UTC"\
-Dliquibase.username="root"\
-Dliquibase.password="my-secret-pw"\
-Dliquibase.referenceUrl="jdbc:mysql://localhost:3306/calculator?serverTimezone=UTC"\
-Dliquibase.referenceUsername="root"\
-Dliquibase.referencePassword="my-secret-pw"


Générer la diff avec la bd PROD

mvn liquibase:diff -Puat\
-Dliquibase.url="jdbc:mysql://localhost:3309/calculator?serverTimezone=UTC"\
-Dliquibase.username="root"\
-Dliquibase.password="my-secret-pw"\
-Dliquibase.referenceUrl="jdbc:mysql://localhost:3306/calculator?serverTimezone=UTC"\
-Dliquibase.referenceUsername="root"\
-Dliquibase.referencePassword="my-secret-pw"

Pousser les changements et mettre en PROD tel que vu au chapître précédent
Empty file added derby.log
Empty file.
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "The app is starting ..."
exec java -jar -Dspring.profiles.active=${SPRING_ACTIVE_PROFILES} "calculator.jar"
Loading