Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 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
8931bc2
locate db host as host.docker.internal
imphilippesimo Aug 31, 2021
263dea8
update m2ch6_1 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'
}
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# Dépôt des sources JAVA pour cours CICD

Sources accompagnant le cours "Continuous Integration, Continuous Delivery"
1/ Mettre en PROD Manuellement

a/ Comprendre le modèle de branching Gitflow

https://nvie.com/posts/a-successful-git-branching-model/

b/ Appliquer:

Se déplacer sur la branche m2ch5 puis :

- Créer une branche de realease à partir de develop

git checkout -b release-0.1.0 develop

git push -u origin release-0.1.0



- Oups il y'a un bug/manquement dans le pipeline:

Les branches release-* hotfix-* doivent être déployées en UAT autant que develop

Corriger => créer un commit, pousser => merger sur develop afin que les autres équipes qui developpent en parralèle
puisse prendre les modifications en compte


- Se déplacer sur main et fusionner la release, créer un tag, puis pousser en PROD

git checkout master
git merge --no-ff release-0.1.0

git push

git tag -a v0.1.0 -m "Very first release of Calculator"

git push origin --tags

- Corriger un bug en prod
Qui veut essayer ?

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