Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions eureka/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Spring Boot Admin - Eureka Example

Allows to run Spring Boot Admin and two sample apps (hello world, health simulator) with service discovery via eureka.

This Readme will guide you through all setup steps for the infrastructure.

## Prerequisites

- Java
- Maven
- Docker and Docker Compose

## Run Everything
You can run the whole build and start all apps in docker containers with the following script or follow the step-by-step guide below.
```bash
chmod u+x buildAndRunAll.sh
./buildAndRunAll.sh
```
Eureka UI: http://localhost:8761/

Admin UI: http://localhost:8080/

## Stop Everything
```bash
docker-compose down -v
```
5 changes: 5 additions & 0 deletions eureka/apps/eureka/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.idea
*.iml
*.log
*.gz
8 changes: 8 additions & 0 deletions eureka/apps/eureka/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://hub.docker.com/_/eclipse-temurin/
FROM eclipse-temurin:17

VOLUME /tmp

COPY target/app.jar /opt/app/app.jar

CMD ["bash", "-c", "java $JAVA_OPTS -jar /opt/app/app.jar"]
6 changes: 6 additions & 0 deletions eureka/apps/eureka/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Build App
mvn package
# Build Docker Image
docker build --tag eureka-server .
73 changes: 73 additions & 0 deletions eureka/apps/eureka/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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>3.2.1</version>
</parent>

<groupId>de.codecentric</groupId>
<artifactId>eureka-server</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<version>1.0.0-SNAPSHOT</version>
<description>Eureka Server</description>

<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>

<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
<!-- Build-Info for Info-Actuator -->
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GIT-Info for Info-Actuator -->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<configuration>
<offline>true</offline>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.codecentric.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class);
}
}
45 changes: 45 additions & 0 deletions eureka/apps/eureka/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
server:
port: 8761
spring:
application: # Application-Info for the Info-Actuator
name: "@pom.artifactId@"
eureka:
client:
registerWithEureka: true
fetchRegistry: false
management: # Actuator Configuration
server:
port: 8081
endpoints:
web:
exposure:
include: "*"
endpoint: # Health-Actuator
health:
show-details: always
probes:
enabled: true
env: # Environment-Actuator
show-values: always
configprops: # Configuration-Actuator
show-values: always
info: # Info-Actuator
java:
enabled: true
os:
enabled: true
build:
enabled: true
env:
enabled: true
git:
enabled: true
info: # Application-Info for the Info-Actuator
group: "@pom.groupId@"
artifact: "@pom.artifactId@"
description: "@pom.description@"
version: "@pom.version@"
spring-boot: "@pom.parent.version@"
# Tags for the Spring Boot Admin UI
tags:
spring-boot: "@pom.parent.version@"
5 changes: 5 additions & 0 deletions eureka/apps/hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.idea
*.iml
*.log
*.gz
8 changes: 8 additions & 0 deletions eureka/apps/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://hub.docker.com/_/eclipse-temurin/
FROM eclipse-temurin:17

VOLUME /tmp

COPY target/app.jar /opt/app/app.jar

CMD ["bash", "-c", "java $JAVA_OPTS -jar /opt/app/app.jar"]
6 changes: 6 additions & 0 deletions eureka/apps/hello-world/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Build App
mvn package
# Build Docker Image
docker build --tag hello-world-eureka .
84 changes: 84 additions & 0 deletions eureka/apps/hello-world/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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>3.2.1</version>
</parent>

<groupId>de.codecentric</groupId>
<artifactId>hello-world-eureka</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<version>1.0.0-SNAPSHOT</version>
<description>Hello World</description>

<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>

<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
<!-- Build-Info for Info-Actuator -->
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GIT-Info for Info-Actuator -->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<configuration>
<offline>true</offline>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.codecentric.helloworld;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorld {

@GetMapping("/")
public String hello() {
return "Hello World!";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.codecentric.helloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;

@SpringBootApplication
public class HelloWorldApplication {

public static void main(String... args) {
var app = new SpringApplication(HelloWorldApplication.class);
// Buffering for Startup-Actuator
app.setApplicationStartup(new BufferingApplicationStartup(2048));
app.run();
}

}
54 changes: 54 additions & 0 deletions eureka/apps/hello-world/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
server:
port: 8080
spring:
application: # Application-Info for the Info-Actuator
name: "@pom.artifactId@"
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
startup: ${random.int} #needed to trigger info and endpoint update after restart
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management: # Actuator Configuration
server:
port: 8081
endpoints:
web:
exposure:
include: "*"
endpoint: # Health-Actuator
health:
show-details: always
probes:
enabled: true
env: # Environment-Actuator
show-values: always
configprops: # Configuration-Actuator
show-values: always
info: # Info-Actuator
java:
enabled: true
os:
enabled: true
build:
enabled: true
env:
enabled: true
git:
enabled: true
info: # Application-Info for the Info-Actuator
group: "@pom.groupId@"
artifact: "@pom.artifactId@"
description: "@pom.description@"
version: "@pom.version@"
spring-boot: "@pom.parent.version@"
# Tags for the Spring Boot Admin UI
tags:
spring-boot: "@pom.parent.version@"
logging: # Logging-File for the Logfile-Actuator
file:
name: "hello-world.log"
5 changes: 5 additions & 0 deletions eureka/apps/spring-boot-admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.idea
*.iml
*.log
*.gz
8 changes: 8 additions & 0 deletions eureka/apps/spring-boot-admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://hub.docker.com/_/eclipse-temurin/
FROM eclipse-temurin:17

VOLUME /tmp

COPY target/app.jar /opt/app/app.jar

CMD ["bash", "-c", "java $JAVA_OPTS -jar /opt/app/app.jar"]
6 changes: 6 additions & 0 deletions eureka/apps/spring-boot-admin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Build App
mvn package
# Build Docker Image
docker build --tag spring-boot-admin-eureka .
Loading