From 2333fe053d9798d8aacfcaea902842d0ae9dd3ad Mon Sep 17 00:00:00 2001 From: Nathan Wanono Date: Sat, 22 Apr 2023 15:18:42 +0200 Subject: [PATCH] Commit initial --- fb-app/.gitignore | 33 ++++++++++++ fb-app/Dockerfile | 29 +++++++++++ fb-app/pom.xml | 51 +++++++++++++++++++ .../fridaybooster/kubernetes/fbapp/FBApp.java | 13 +++++ .../fbapp/controller/TestController.java | 32 ++++++++++++ .../kubernetes/fbapp/model/HostNameInfo.java | 29 +++++++++++ fb-app/src/main/resources/application.yaml | 1 + .../fbapp/TestApplicationTests.java | 13 +++++ test-pod/Dockerfile | 5 ++ 9 files changed, 206 insertions(+) create mode 100644 fb-app/.gitignore create mode 100644 fb-app/Dockerfile create mode 100644 fb-app/pom.xml create mode 100644 fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/FBApp.java create mode 100644 fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/controller/TestController.java create mode 100644 fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/model/HostNameInfo.java create mode 100644 fb-app/src/main/resources/application.yaml create mode 100644 fb-app/src/test/java/com/capgemini/fridaybooster/kubernetes/fbapp/TestApplicationTests.java create mode 100644 test-pod/Dockerfile diff --git a/fb-app/.gitignore b/fb-app/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/fb-app/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/fb-app/Dockerfile b/fb-app/Dockerfile new file mode 100644 index 0000000..5ee1783 --- /dev/null +++ b/fb-app/Dockerfile @@ -0,0 +1,29 @@ +# Image de base +FROM maven:3-eclipse-temurin-17-alpine as build_image + +# Passage dans le repertoire de compilation +WORKDIR /sources + +# Copie des sources +COPY src src +COPY pom.xml pom.xml + +# Lancement du package +RUN mvn package + +# Runtime Image +FROM eclipse-temurin:17-jre-alpine + +# Environment variables +ENV UID=2000 +ENV GID=4000 + +# Changement d'utilisateur +USER ${UID}:${GID} + +# Copie du jar +COPY --from=build_image --chown=${UID}:${GID} /sources/target/fbapp.jar . +RUN ls -l + +# Lancement de l'application +CMD ["java", "-jar", "fbapp.jar"] \ No newline at end of file diff --git a/fb-app/pom.xml b/fb-app/pom.xml new file mode 100644 index 0000000..22a860d --- /dev/null +++ b/fb-app/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + + com.capgemini.fridaybooster.kubernetes + fb-app + 0.0.1-SNAPSHOT + Friday Booster Simple Application + Simple application for simple Kubernetes testing + + jar + + + 17 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + + + fbapp + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/FBApp.java b/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/FBApp.java new file mode 100644 index 0000000..21b1515 --- /dev/null +++ b/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/FBApp.java @@ -0,0 +1,13 @@ +package com.capgemini.fridaybooster.kubernetes.fbapp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FBApp { + + public static void main(String[] args) { + SpringApplication.run(FBApp.class, args); + } + +} diff --git a/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/controller/TestController.java b/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/controller/TestController.java new file mode 100644 index 0000000..2c7a3f0 --- /dev/null +++ b/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/controller/TestController.java @@ -0,0 +1,32 @@ +package com.capgemini.fridaybooster.kubernetes.fbapp.controller; + +import java.net.Inet4Address; +import java.net.UnknownHostException; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.capgemini.fridaybooster.kubernetes.fbapp.model.HostNameInfo; + +import reactor.core.publisher.Mono; + +@RestController +@RequestMapping("/") +public class TestController { + + private final HostNameInfo infos; + + public TestController(@Value("${message}") String message) throws UnknownHostException { + var ip = Inet4Address.getLocalHost().getHostAddress(); + var hostName = Inet4Address.getLocalHost().getHostName(); + + infos = new HostNameInfo(hostName, ip, message); + } + + @GetMapping("/") + public Mono getInfo() { + return Mono.just(infos); + } +} diff --git a/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/model/HostNameInfo.java b/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/model/HostNameInfo.java new file mode 100644 index 0000000..efea44b --- /dev/null +++ b/fb-app/src/main/java/com/capgemini/fridaybooster/kubernetes/fbapp/model/HostNameInfo.java @@ -0,0 +1,29 @@ +package com.capgemini.fridaybooster.kubernetes.fbapp.model; + +public class HostNameInfo { + + private final String hostname; + + private final String ip; + + private final String message; + + public HostNameInfo(String hostname, String ip, String message) { + super(); + this.hostname = hostname; + this.ip = ip; + this.message = message; + } + + public String getHostname() { + return hostname; + } + + public String getIp() { + return ip; + } + + public String getMessage() { + return message; + } +} diff --git a/fb-app/src/main/resources/application.yaml b/fb-app/src/main/resources/application.yaml new file mode 100644 index 0000000..6fe268d --- /dev/null +++ b/fb-app/src/main/resources/application.yaml @@ -0,0 +1 @@ +message: ${ENV_MESSAGE:La variable 'ENV_MESSAGE' n'est pas definie} \ No newline at end of file diff --git a/fb-app/src/test/java/com/capgemini/fridaybooster/kubernetes/fbapp/TestApplicationTests.java b/fb-app/src/test/java/com/capgemini/fridaybooster/kubernetes/fbapp/TestApplicationTests.java new file mode 100644 index 0000000..4be1d97 --- /dev/null +++ b/fb-app/src/test/java/com/capgemini/fridaybooster/kubernetes/fbapp/TestApplicationTests.java @@ -0,0 +1,13 @@ +package com.capgemini.fridaybooster.kubernetes.fbapp; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class TestApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/test-pod/Dockerfile b/test-pod/Dockerfile new file mode 100644 index 0000000..8f16f40 --- /dev/null +++ b/test-pod/Dockerfile @@ -0,0 +1,5 @@ +# Image de base +FROM registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3 + +# Installation de CURL +RUN apt install -y curl