Skip to content

Commit 40bf89c

Browse files
committed
add actuator & logs & docker-compose & healthcheck
1 parent 4c7cc46 commit 40bf89c

File tree

10 files changed

+69
-20
lines changed

10 files changed

+69
-20
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ build/
3232
### VS Code ###
3333
.vscode/
3434

35-
36-
### cert ###
37-
certs
35+
### custom ###
36+
certs
37+
*.log
38+
*.gz

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ _Changes alias_
5252
_You can allow use of https://127.0.0.1:8080/ping api from browser, if property set server.ssl.client-auth=want_
5353

5454
_Run [cert.sh](./cert.sh) for generating localhost demo certificates_
55-
_Run [docker.sh](./docker.sh) to create Docker image and run docker container_
56-
_Run [run.sh](./run.sh) to create certs, prepare docker files, run docker_
55+
_Run [jar.sh](./jar.sh) to compile & extract .jar for docker image_
56+
_Run [docker.sh](./docker.sh) to create Docker image and run docker container_
57+
_Run: docker-compose.
58+
`docker-compose -p test up --force-recreate --build`
59+
Make sure cert __ext__ flag ip set correctly_
5760

58-
To change certs in container
61+
To change certs in container
5962
[docker run -v /host/path/to/certs:/container/path/to/certs -d IMAGE_ID "update-ca-certificates"](https://stackoverflow.com/questions/26028971/docker-container-ssl-certificates)
6063

6164

docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "3.8"
2+
services:
3+
testserver:
4+
build:
5+
context: ./
6+
dockerfile: app.Dockerfile
7+
restart: always
8+
ports:
9+
- "8080:8080/tcp"
10+
- "8081:8081/tcp"
11+
environment:
12+
SERVER_ADDRESS: 0.0.0.0
13+
SERVER_PORT: 8080
14+
MANAGEMENT_PORT: 8081
15+
healthcheck:
16+
test: "curl --fail --silent localhost:8081/actuator/health | grep UP || exit 1"
17+
interval: 20s
18+
timeout: 5s
19+
retries: 5
20+
start_period: 40s

docker.conf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
EXT_IP=0.0.0.0
2-
PORT=8080
2+
PORT=8080
3+
MANAGEMENT_PORT=8081

docker.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
#https://spring.io/guides/gs/spring-boot-docker/
44

55
docker build -f app.Dockerfile -t example/app:latest .
6-
7-
winpty docker run -it --rm -e SERVER_PORT=8080 -e SERVER_ADDRESS="${EXT_IP}" -p "${PORT}":8080 --name testserver example/app
6+
#winpty for windows docker flag -i
7+
winpty docker run -it --rm \
8+
-e SERVER_ADDRESS="${EXT_IP}" \
9+
-e SERVER_PORT=8080 \
10+
-e MANAGEMENT_SERVER_PORT=8081 \
11+
-p "${MANAGEMENT_PORT}":8081 \
12+
-p "${PORT}":8080 \
13+
--name testserver \
14+
example/app

jar.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/bash
2+
mvn clean install
3+
mkdir target/dependency
4+
cd target/dependency || exit
5+
jar -xf ../*.jar
6+
cd ../../

pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<groupId>org.springframework.boot</groupId>
2222
<artifactId>spring-boot-starter-webflux</artifactId>
2323
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-actuator</artifactId>
27+
</dependency>
2428
<dependency>
2529
<groupId>org.springframework.boot</groupId>
2630
<artifactId>spring-boot-devtools</artifactId>

run.sh

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#! /bin/bash
22
. ./docker.conf
3-
3+
echo "Creating certs"
44
bash cert.sh "san=ip:${EXT_IP}"
5-
6-
mvn clean install
7-
mkdir target/dependency
8-
cd target/dependency || exit
9-
jar -xf ../*.jar
10-
cd ../../
11-
#create docker image and run container
5+
echo "Compiling and extracting jar"
6+
bash jar.sh
7+
echo "Creating docker image and running container"
128
bash docker.sh

src/main/java/edu/strauteka/example/ExampleApplication.java

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ public static void main(String[] args) {
1616
log.info("Starting exit...");
1717
ctx.close();
1818
}));
19-
20-
2119
}
2220
}

src/main/resources/application.properties

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,17 @@ spring.jmx.enabled=false
3131

3232
#suspend debug
3333
logging.level.org.springframework.test.context=WARN
34-
logging.level.org.springframework.boot.test.context=WARN
34+
logging.level.org.springframework.boot.test.context=WARN
35+
36+
37+
#https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html
38+
management.endpoints.web.exposure.include=health,info,beans,logfile
39+
# /actuator without ssl
40+
management.server.port=8081
41+
management.server.ssl.enabled=false
42+
43+
logging.level.web=debug
44+
logging.file.name=logfile.log
45+
logging.file.path=./
46+
logging.logback.rollingpolicy.max-history=5
47+
logging.logback.rollingpolicy.max-file-size=1MB

0 commit comments

Comments
 (0)