Go to file
stef d324ffd7fc first commit 2023-12-17 14:44:22 +01:00
bmi first commit 2023-12-17 14:44:22 +01:00
README.md first commit 2023-12-17 14:44:22 +01:00

README.md

References

Doc: https://blog.tericcabrel.com/ deploy-spring-boot-application-docker-nginx-reverse-proxy/ jvm: https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb

https://www.linuxcapable.com/how-to-install-apache-maven-on-debian-linux/

sudo apt install maven
mvn -version
Apache Maven 3.8.7
Maven home: /usr/share/maven
Java version: 17.0.9, vendor: Debian, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "6.1.0-16-amd64", arch: "amd64", family: "unix"
git clone https://github.com/tericcabrel/bmi.git

cd bmi

Modifier main/ressources/application.properties server.port=8000 => server.port=7000

stef@swarm-node01:~/javaapp/bmi$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< com.tericcabrel:bmi >-------------------------
[INFO] Building bmi 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.6.7:run (default-cli) > test-compile @ bmi >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ bmi ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ bmi ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ bmi ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /home/stef/javaapp/bmi/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ bmi ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.6.7:run (default-cli) < test-compile @ bmi <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.7:run (default-cli) @ bmi ---
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.7)

2023-12-17 14:15:01.370  INFO 8027 --- [           main] com.tericcabrel.bmi.BmiApplication       : Starting BmiApplication using Java 17.0.9 on swarm-node01 with PID 8027 (/home/stef/javaapp/bmi/target/classes started by stef in /home/stef/javaapp/bmi)
2023-12-17 14:15:01.373  INFO 8027 --- [           main] com.tericcabrel.bmi.BmiApplication       : No active profile set, falling back to 1 default profile: "default"
2023-12-17 14:15:02.178  INFO 8027 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 7000 (http)
2023-12-17 14:15:02.187  INFO 8027 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-12-17 14:15:02.188  INFO 8027 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.62]
2023-12-17 14:15:02.264  INFO 8027 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-12-17 14:15:02.265  INFO 8027 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 846 ms
2023-12-17 14:15:02.708  INFO 8027 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2023-12-17 14:15:02.809  INFO 8027 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 7000 (http) with context path ''
2023-12-17 14:15:02.818  INFO 8027 --- [           main] com.tericcabrel.bmi.BmiApplication       : Started BmiApplication in 1.88 seconds (JVM running for 2.4)

Test app:

http://192.168.88.51:7000/ ok

Dockerison

cat > Dockerfile << _EOF_
FROM maven:3.8.3-jdk-11-slim AS build
RUN mkdir /project
COPY . /project
WORKDIR /project
RUN mvn clean package
FROM adoptopenjdk/openjdk11:jre-11.0.15_10-alpine
RUN mkdir /app
RUN addgroup -g 1001 -S stef
RUN adduser -S stef -u 1001
COPY --from=build /project/target/bmi-1.0.jar /app/bmi.jar
WORKDIR /app
RUN chown -R stef:stef /app
CMD java $JAVA_OPTS -jar bmi.jar
 _EOF_
docker build -t stef/javaapp:v1 .

Test Docker images

docker run -it --rm -p 7000:7000 --name bmiapp stef/javaapp:v1
stef@swarm-node01:~/javaapp/bmi$  docker run -it --rm -p 7000:7000 --name bmiapp stef/javaapp:v1

 .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
 '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::                (v2.6.7)

2023-12-17 13:26:00.113  INFO 1 --- [           main] com.tericcabrel.bmi.BmiApplication       : Starting BmiApplication v1.0 using Java 11.0.15 on cfa0f0ed85d2 with PID 1 (/app/bmi.jar started by root in /app)
2023-12-17 13:26:00.121  INFO 1 --- [           main] com.tericcabrel.bmi.BmiApplication       : No active profile set, falling back to 1 default profile: "default"
2023-12-17 13:26:01.798  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 7000 (http)
2023-12-17 13:26:01.829  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-12-17 13:26:01.830  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.62]
2023-12-17 13:26:01.993  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-12-17 13:26:01.993  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1774 ms
2023-12-17 13:26:03.130  INFO 1 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2023-12-17 13:26:03.373  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 7000 (http) with context path ''
2023-12-17 13:26:03.399  INFO 1 --- [           main] com.tericcabrel.bmi.BmiApplication       : Started BmiApplication in 4.125 seconds (JVM running for 4.879)