-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a60b5c4
Showing
62 changed files
with
15,021 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/*.iml | ||
**/.idea | ||
**/*.vagrant | ||
**/*-cloudimg-console.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Workshop for deploying classic simple application | ||
|
||
Small project SpringBoot/Angular just for testing purpose | ||
|
||
## Goal | ||
|
||
Deploy this small project into a Kubernetes cluster | ||
|
||
## How | ||
|
||
1. Create docker image for `backend` and `frontend` | ||
2. Push to a docker registry | ||
3. Write kubernetes descriptor for `backend` and `frontend` | ||
4. Apply descriptors | ||
|
||
### Tips | ||
|
||
♻ Don't hesitate to modify some code if necessary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/** | ||
!**/src/test/** | ||
|
||
### 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/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.3.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.github.pcavezzan.kubernetes.workshop</groupId> | ||
<artifactId>backend</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>Spring Boot Angular - Backend</name> | ||
<description>Backend JAVA for this small project Spring Boot Angular to deploy on Kubernetes</description> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/com/github/pcavezzan/kubernetes/workshop/BackendApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.web.ServerProperties; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
@SpringBootApplication | ||
@Slf4j | ||
public class BackendApplication { | ||
|
||
@Value("${backend.messages.welcome}") | ||
private String welcomeMsg; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(BackendApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public String serverHostName(ServerProperties serverProperties) { | ||
InetAddress address = serverProperties.getAddress(); | ||
if (address == null) { | ||
// We did not set any binding address | ||
try { | ||
address = InetAddress.getLocalHost(); | ||
} catch (UnknownHostException e) { | ||
log.warn("Could not get address from localhost, will use loopback instead"); | ||
address = InetAddress.getLoopbackAddress(); | ||
} | ||
} | ||
return address.getHostName(); | ||
} | ||
|
||
@Bean | ||
public MessageService messageService(String serverHostName) { | ||
return new MessageService(welcomeMsg, serverHostName); | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/github/pcavezzan/kubernetes/workshop/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import lombok.Data; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Data | ||
class Message { | ||
private final String payload; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/com/github/pcavezzan/kubernetes/workshop/MessageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
class MessageService { | ||
|
||
private final String welcomeMsg; | ||
private final String serverHostName; | ||
|
||
public Message getWelcomeMsg() { | ||
return new Message(welcomeMsg); | ||
} | ||
|
||
public Message getServerHostName() { | ||
return new Message(serverHostName); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/github/pcavezzan/kubernetes/workshop/WelcomeResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.net.InetAddress; | ||
|
||
@RestController | ||
@RequestMapping("/welcome") | ||
@Slf4j | ||
class WelcomeResource { | ||
|
||
@Autowired | ||
private MessageService messageService; | ||
|
||
@Autowired | ||
private String serverHostName; | ||
|
||
@GetMapping | ||
public Message get() { | ||
log.info("{} - incoming request for getting message", serverHostName); | ||
return messageService.getWelcomeMsg(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/com/github/pcavezzan/kubernetes/workshop/WhoamiResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/whoami") | ||
@Slf4j | ||
public class WhoamiResource { | ||
|
||
@Autowired | ||
private MessageService messageService; | ||
|
||
@GetMapping | ||
public Message get() { | ||
return messageService.getServerHostName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
spring.application.name=backend | ||
|
||
backend.messages.welcome=Hello World inside ${spring.application.name} |
15 changes: 15 additions & 0 deletions
15
backend/src/test/java/com/github/pcavezzan/kubernetes/workshop/BackendApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
class BackendApplicationTest { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/test/java/com/github/pcavezzan/kubernetes/workshop/MessageServiceITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
class MessageServiceITCase { | ||
|
||
@Autowired | ||
private MessageService messageService; | ||
|
||
@Test | ||
void getWelcomeMsgShouldReturnHelloWorld() { | ||
final Message welcomeMsg = messageService.getWelcomeMsg(); | ||
assertThat(welcomeMsg).isEqualTo(new Message("** Hello World **")); | ||
} | ||
|
||
@Test | ||
void getServerHostNameShouldReturnLocalhost() { | ||
final Message serverHostName = messageService.getServerHostName(); | ||
assertThat(serverHostName).isEqualTo(new Message("localhost")); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/test/java/com/github/pcavezzan/kubernetes/workshop/MessageServiceTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MessageServiceTestCase { | ||
|
||
private final MessageService messageService = new MessageService("Foo Bar", "localhost"); | ||
|
||
@Test | ||
void getWelcomeMsg() { | ||
assertThat(messageService.getWelcomeMsg()).isEqualTo(new Message("Foo Bar")); | ||
} | ||
|
||
@Test | ||
void getServerHostName() { | ||
assertThat(messageService.getServerHostName()).isEqualTo(new Message("localhost")); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/test/java/com/github/pcavezzan/kubernetes/workshop/WelcomeResourceITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
public class WelcomeResourceITCase { | ||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
public void getShouldReturnHelloWorld() throws Exception { | ||
final ResultActions resultActions = this.mockMvc.perform(get("/welcome")); | ||
|
||
resultActions.andExpect(status().isOk()) | ||
.andExpect(content().string(equalTo("{\"payload\":\"** Hello World **\"}"))); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
backend/src/test/java/com/github/pcavezzan/kubernetes/workshop/WelcomeResourceTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.pcavezzan.kubernetes.workshop; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(WelcomeResource.class) | ||
public class WelcomeResourceTestCase { | ||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private MessageService service; | ||
|
||
@Test | ||
public void getShouldReturnHelloWorld() throws Exception { | ||
when(service.getWelcomeMsg()).thenReturn(new Message("Hello World")); | ||
|
||
final ResultActions resultActions = this.mockMvc.perform(get("/welcome")); | ||
|
||
resultActions.andExpect(status().isOk()) | ||
.andExpect(content().string(equalTo("{\"payload\":\"Hello World\"}"))); | ||
} | ||
|
||
} |
Oops, something went wrong.