Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 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
82dcb22
Activate liquibase only for dev, uat and prod profiles
imphilippesimo Aug 31, 2021
cdb013b
locate db host as host.docker.internal
imphilippesimo Aug 31, 2021
a080f0a
update m1ch2 3 4 6 branche
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'
}
190 changes: 189 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,191 @@
# Dépôt des sources JAVA pour cours CICD

Sources accompagnant le cours "Continuous Integration, Continuous Delivery"


1/ Préparer les machines distantes



a/ Démarrer 2 machine linux


i/
docker run -it --name mysql-alpine-dev --rm alpine-ssh-server

docker run -it --name mysql-alpine-uat --rm alpine-ssh-server

Pour chacune des machines:

Modifier le mot de passe root:

passwd
my-secret-pw



Démarrez le service ssh:

/etc/init.d/sshd restart


Vérifier l'état du service SSH

netstat -atunp
Si aucun service n'est en mode LISTEN sur le port 22 alors redémarrez


Noter l'adresse IP de l'interface eth0:
ifconfig

172.17.0.4

172.17.0.5



============ (pas nécessaire sauf si vous partez d'une machine alpine simple) ===========

b/ Install OpenSSH et ses outils pour la communication via SSH

apk add python3
apk add openssh
apk add nano


c/ Démarrer le serveur ssh:

apk add openrc

rc-update add sshd

/etc/init.d/sshd start

touch /run/openrc/softlevel

/etc/init.d/sshd start

rc-status

netstat -atunp

--
nano /etc/ssh/sshd_config

Append (a)

PermitRootLogin Yes

exit(esc) => :wq

/etc/init.d/sshd restart
--

Modifier le mot de passe root:

passwd
my-secret-pw

========================================================



======== Pas nécessaire, je l'ai utilisée pour sauvegarder les machines déjà configurées ==================

c/ Clone the previously created machine for the second machine

docker commit d3e616f327a4 alpine-ssh-server


docker tag alpine-ssh-server imzerofiltre/alpine-ssh-server

docker push imzerofiltre/alpine-ssh-server

=================================================




2/ Préparer la machine de contrôle


a/ Démarrer une machine linux

docker run -it --name ansible-controller alpine




b/ Install OpenSSH for SSH comminucation between the remote and the controller

apk add openssh



Ajouter les clés de chaque machine en tant que serveurs connus

ssh @IP machine distante


c/ Générer une paire de clé privé/publique à utiliser en lieu et place du mot de passe



ssh-keygen
(Utiliser les valeurs par défaut en tapant juste entrer jusqu'à la fin)


c/ Importer la clé publique SSH de la machine de contrôle:

ssh-copy-id @IP machine distante

ssh @IP machine distante => désormais plus de clé demandée.

b/ Installer Ansible

apk add ansible

Vérifier l'installation avec:

ansible --version




d/ Définissions l'inventaire (inventory)

apk add nano

mkdir /etc/ansible
nano /etc/ansible/host


[database]
172.17.0.9
172.17.0.10


Ecrire le playbook

nano /etc/ansible/install-db.yaml

- name: install db servers play
hosts: databases
tasks:
- name: Install server and client
command: apk add mysql mysql-client

- name: Pause 10 seconds for installation process to finish
pause: seconds=10

- name: Setup database
command: /etc/init.d/mariadb setup

- name: Start the server
command: /etc/init.d/mariadb start



Démarrer le playbook :

ansible-playbook -i /etc/ansible/host /etc/ansible/install-db.yaml

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