Compare commits
11 Commits
56206c02bb
...
update-cod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9865e9dcc2 | ||
|
|
ca34df2af9 | ||
| b451ad2233 | |||
|
|
8a341c51ee | ||
|
|
b4555aa73f | ||
| 8bf1594329 | |||
|
|
33b24c62d4 | ||
|
|
ac66320f9a | ||
|
|
71cc786ea5 | ||
| b8c9b382d8 | |||
|
|
56aa4c7b3a |
37
Jenkinsfile
vendored
37
Jenkinsfile
vendored
@@ -1,5 +1,8 @@
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'maven-3.9'
|
||||
}
|
||||
stages {
|
||||
stage('Compilation') {
|
||||
steps {
|
||||
@@ -27,11 +30,35 @@ pipeline {
|
||||
}
|
||||
stage('Déploiement') {
|
||||
steps {
|
||||
echo "Démarrage de l'application Spring Boot..."
|
||||
// Arr\u00eater l'application si elle tourne d\u00e9j\u00e0 (pour ne pas dupliquer les instances)
|
||||
sh 'pkill -f "java -jar" || echo "Aucune ancienne instance \u00e0 arr\u00eater"'
|
||||
// D\u00e9marrer la nouvelle version en arri\u00e8re-plan
|
||||
sh 'nohup java -jar target/*.jar --server.port=8081 &'
|
||||
sh '''
|
||||
echo "=== Déploiement simple sur le port 8081 ==="
|
||||
|
||||
cd "$WORKSPACE"
|
||||
|
||||
# 1) Arrêter l'ancienne instance de CE jar (et pas tout java)
|
||||
OLD_PIDS=$(pgrep -f "rock-paper-scissors-0.0.1-SNAPSHOT.jar" || true)
|
||||
if [ -n "$OLD_PIDS" ]; then
|
||||
echo "Arrêt des anciennes instances: $OLD_PIDS"
|
||||
kill $OLD_PIDS || true
|
||||
sleep 5
|
||||
else
|
||||
echo "Aucune ancienne instance à arrêter."
|
||||
fi
|
||||
|
||||
# 2) Vérifier que le jar existe
|
||||
JAR_FILE=target/rock-paper-scissors-0.0.1-SNAPSHOT.jar
|
||||
if [ ! -f "$JAR_FILE" ]; then
|
||||
echo "ERREUR : $JAR_FILE introuvable"
|
||||
exit 1
|
||||
fi
|
||||
echo "Jar sélectionné : $JAR_FILE"
|
||||
|
||||
# 3) Démarrer en arrière-plan, en évitant que Jenkins tue le process
|
||||
echo "Démarrage de l'application..."
|
||||
JENKINS_NODE_COOKIE=dontKillMe nohup java -jar "$JAR_FILE" --server.port=8081 > app.log 2>&1 &
|
||||
|
||||
echo "Déploiement terminé (process lancé en arrière-plan)."
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
176
README.md
Normal file
176
README.md
Normal file
@@ -0,0 +1,176 @@
|
||||
# Travaux Pratiques CI/CD
|
||||
|
||||
Le but de ce TP est d’utiliser un git déjà existant et d’y installer une multibranche pipeline Jenkins.
|
||||
|
||||
## Copier le git du TP sur son profil
|
||||
Se rendre sur : https://grond.iut-fbleau.fr/pierront/rock-paper-scissors
|
||||
|
||||
Faire un fork
|
||||
|
||||
## Créer la VM pour jenkins
|
||||
### Créer la règle pare-feu pour accéder aux ports 8080 et 8081
|
||||
Aller dans la section Pare-Feu
|
||||
|
||||
* Cliquer -> Créer une règle de pare-feu
|
||||
* Nom : jenkins-rule
|
||||
* Sens du trafic : Entrée
|
||||
* Tag cibles : jenkins
|
||||
* Plages IPv4 source : 0.0.0.0/0
|
||||
* Cocher TCP
|
||||
* Ports : 8080, 8081
|
||||
* Puis créer
|
||||
|
||||
---
|
||||
|
||||
* Créer la VM
|
||||
* Configuration de la machine
|
||||
* Nom : jenkins
|
||||
* Région : la plus proche
|
||||
* Série : E2 / e2-medium
|
||||
* Mise en réseau
|
||||
* Cocher Autoriser le trafic HTTP
|
||||
* Cocher Autoriser le trafic HTTPS
|
||||
* Tags réseau : ajouter jenkins
|
||||
* Créer la VM
|
||||
|
||||
---
|
||||
|
||||
## Installation de Jenkins sur la VM
|
||||
|
||||
Installer git
|
||||
```bash
|
||||
sudo apt install -y git
|
||||
```
|
||||
|
||||
Installer Java
|
||||
```bash
|
||||
sudo apt install -y wget apt-transport-https gpg
|
||||
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null
|
||||
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
|
||||
sudo apt update
|
||||
sudo apt install temurin-21-jdk
|
||||
```
|
||||
|
||||
Installer Jenkins
|
||||
```bash
|
||||
sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
|
||||
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
|
||||
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc]" \
|
||||
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
|
||||
/etc/apt/sources.list.d/jenkins.list > /dev/null
|
||||
sudo apt update
|
||||
sudo apt install jenkins
|
||||
```
|
||||
|
||||
Verifier s'il a bien démarrer :
|
||||
`systemctl status jenkins`
|
||||
|
||||
Se rendre sur l'adresse IP de la VM : http://<IP_EXTERNE_VM>:8080
|
||||
|
||||
Vous devriez voir la page d'accueil de Jenkins
|
||||

|
||||
|
||||
* Suivre les instructions pour la creation de compte admin
|
||||
* Selectionner : Install suggested plugins
|
||||
* Créer un nouveau compte admin
|
||||
* Voir cette page
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Configuration de Jenkins avec Gitea
|
||||
|
||||
### Installer le plugin Gitea
|
||||
* Aller dans la section Manage Jenkins **(roue crantée)** -> Plugins
|
||||
* Rechercher Gitea
|
||||
* Installer le plugin
|
||||
|
||||
### Configurer Maven
|
||||
* Aller dans la section Manage Jenkins **(roue crantée)** -> Tools
|
||||
* Add Maven
|
||||
* Nom : maven-3.9
|
||||
* Cocher Install automatically
|
||||
* Version : 3.9.11
|
||||
* Cliquer sur Save
|
||||
|
||||
### Récupérer un token Gitea
|
||||
* Se rendre sur Gitea
|
||||
* Cliquer sur profil -> Settings -> Applications -> Generate new token
|
||||
* Nom du jeton : jenkins-token
|
||||
* Avec ces options :
|
||||

|
||||
* Cliquer sur Generate token
|
||||
* **Copier le token pour ne pas le perdre**
|
||||
### Configurer Jenkins pour utiliser Gitea
|
||||
* Aller dans la section Manage Jenkins -> System
|
||||
* Add Gitea Server
|
||||
* Choisir le nom du serveur (grond)
|
||||
* Metter l'url du serveur : https://grond.iut-fbleau.fr
|
||||
* Cocher Manage hooks
|
||||
* Cliquer sur _Add +_
|
||||
* Kind : Gitea Personal Access Token
|
||||
* Token : celui copié dans la section précédente
|
||||
* ID : gitea-token
|
||||
* Cliquer sur Add
|
||||
* Puis save
|
||||
|
||||
---
|
||||
|
||||
## Création d'un pipeline
|
||||
* Aller dans la section Manage Jenkins -> New Item
|
||||
* Nommer le projet : rock-paper-scissors
|
||||
* Choisir le type de projet : Multibranch Pipeline
|
||||
* Cliquer sur OK
|
||||
* Add a source
|
||||
* Gitea
|
||||
* utiliser le jeton gitea-token
|
||||
* owner : _<votre nom d'utilisateur gitea>_
|
||||
* Choisir le projet : rock-paper-scissors
|
||||
* Choisir le provider : Git
|
||||
* Choisir le repository : https://grond.iut-fbleau.fr/pierront/rock-paper-scissors.git
|
||||
* Cliquer sur Save
|
||||
|
||||
Voir que le scan se passe bien.
|
||||
|
||||
---
|
||||
|
||||
## Tester le pipeline
|
||||
* Aller dans la section Build History -> Build Now
|
||||
* Voir que le pipeline se passe bien
|
||||
|
||||
|
||||
Tester l'application via cette url : http://<IP_EXTERNE_VM>:8081/swagger-ui/index.html
|
||||
---
|
||||
|
||||
## Gestion du Jenkinsfile
|
||||
|
||||
* Regarder les étapes pour comprendre ce que fait le Jenkinsfile
|
||||
|
||||
---
|
||||
|
||||
## Ajouter le puits dans le code java
|
||||
|
||||
Le puits bat la pierre et les ciseaux.
|
||||
Le puits est battu par la feuille.
|
||||
|
||||
Grace à notre pipeline on peut voir le si le code fonctionne bien via les tests unitaires.
|
||||
Puis on peut tester réelement grace au deploiement sur la VM de l'application java.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Sources :
|
||||
* https://adoptium.net/installation/linux/#deb-installation-on-debian-or-ubuntu
|
||||
* https://www.jenkins.io/doc/book/installing/linux/#debianubuntu
|
||||
* https://plugins.jenkins.io/gitea/
|
||||
* https://www.jenkins.io/doc/book/pipeline/jenkinsfile/
|
||||
BIN
assets/gitea_token.png
Normal file
BIN
assets/gitea_token.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
BIN
assets/jenkins_home.png
Normal file
BIN
assets/jenkins_home.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
assets/jenkins_start.png
Normal file
BIN
assets/jenkins_start.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
2
pom.xml
2
pom.xml
@@ -27,7 +27,7 @@
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,17 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBo
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.StatRepository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Stub
|
||||
public record InMemoryStatRepository(Map<String, Integer> stats) implements StatRepository {
|
||||
|
||||
|
||||
private final static HashMap<String, Integer> DEFAULT_STATS = new LinkedHashMap<>(Map.of("joe", 1,"eoj", 3));
|
||||
|
||||
public InMemoryStatRepository() {
|
||||
HashMap<String, Integer> stats1 = new HashMap<>();
|
||||
stats1.put("joe", 1);
|
||||
stats1.put("eoj", 3);
|
||||
this(stats1);
|
||||
this(DEFAULT_STATS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.web;
|
||||
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public record StatBoardReponse(List<Stat> stats) {
|
||||
@@ -9,6 +10,8 @@ public record StatBoardReponse(List<Stat> stats) {
|
||||
public StatBoardReponse(StatBoard statBoard) {
|
||||
this(statBoard.stats().entrySet().stream()
|
||||
.map(Stat::fromMap)
|
||||
.sorted(Comparator.comparingInt(
|
||||
stat -> -stat.wins()))
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.modulith.core.ApplicationModules;
|
||||
|
||||
public class ModulithStructureTests {
|
||||
class ModulithStructureTests {
|
||||
|
||||
@Test
|
||||
void verifyModularStructure() {
|
||||
|
||||
@@ -26,7 +26,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
webEnvironment = RANDOM_PORT
|
||||
)
|
||||
@Import(FakeCpuConfiguration.class)
|
||||
public class RockPaperScissorsPlayApplicationTest {
|
||||
class RockPaperScissorsPlayApplicationTest {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class MoveTest {
|
||||
class MoveTest {
|
||||
|
||||
@Test
|
||||
void should_check_move_size(){
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.RockPaperScissorsPlay;
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.FakeCpuPicker;
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSaver;
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RockPaperScissorsPlayTest {
|
||||
|
||||
@@ -14,7 +14,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
@ApplicationModuleTest(
|
||||
webEnvironment = RANDOM_PORT
|
||||
)
|
||||
public class StatApplicationTest {
|
||||
class StatApplicationTest {
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@@ -27,9 +27,9 @@ public class StatApplicationTest {
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathArrayValue("@.stats").hasSize(2);
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[0].name").isEqualTo("joe");
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[0].wins").isEqualTo(1);
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[1].name").isEqualTo("eoj");
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[1].wins").isEqualTo(3);
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[0].name").isEqualTo("eoj");
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[0].wins").isEqualTo(3);
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathStringValue("@.stats[1].name").isEqualTo("joe");
|
||||
assertThat(json.from(response.getBody())).extractingJsonPathNumberValue("@.stats[1].wins").isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat;
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoard;
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatBoardGetter;
|
||||
import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.spi.stub.InMemoryStatRepository;
|
||||
import java.util.LinkedHashMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -10,12 +11,13 @@ import java.util.HashMap;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class StatBoardGetterTest {
|
||||
class StatBoardGetterTest {
|
||||
|
||||
@Test
|
||||
public void should_get_stat_board() {
|
||||
HashMap<String, Integer> stats = new HashMap<>();
|
||||
stats.put("joe", 1);
|
||||
void should_get_stat_board() {
|
||||
HashMap<String, Integer> stats = new LinkedHashMap<>();
|
||||
stats.put("eoj", 5);
|
||||
stats.put("joe", 1);
|
||||
InMemoryStatRepository statRepository = new InMemoryStatRepository(stats);
|
||||
|
||||
StatBoardGet statBoardGet = new StatBoardGetter(statRepository);
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
@WebMvcTest(StatController.class)
|
||||
@Import(StatConfiguration.class)
|
||||
public class StatControllerTest {
|
||||
class StatControllerTest {
|
||||
|
||||
private static final String STAT_ENDPOINT = "/stat";
|
||||
|
||||
@@ -36,8 +36,8 @@ public class StatControllerTest {
|
||||
mockMvc.perform(get(STAT_ENDPOINT))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.stats").isArray())
|
||||
.andExpect(jsonPath("$.stats[0].name").value("joe"))
|
||||
.andExpect(jsonPath("$.stats[0].wins").value(1));
|
||||
.andExpect(jsonPath("$.stats[0].name").value("eoj"))
|
||||
.andExpect(jsonPath("$.stats[0].wins").value(3));
|
||||
}
|
||||
|
||||
@TestConfiguration
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class StatSaverTest {
|
||||
class StatSaverTest {
|
||||
@ParameterizedTest(name = "name = {0}, initial = {1}, expected = {2}")
|
||||
@CsvSource({"joe,0,1", "eoj,2,3"})
|
||||
void should_save(String name, int initial, int expected) {
|
||||
|
||||
Reference in New Issue
Block a user