Skip to content

Commit dd2df68

Browse files
author
Ivan Franchin
committed
Project upgrade
- Upgrade to Spring Boot 3.4.1; - Upgrade to Mapstruct 1.6.3; - Upgrade to Apache Maven 3.9.9; - Upgrade to Elasticsearch docker image 8.15.4; - Rename docker-build.sh to build-docker-images.sh; - Refactor the way docker images are built; - Refactor docker-compose.yml file; - Add SpringDataWebSupportConfig to fix warning; - Update README.
1 parent 6cb11b2 commit dd2df68

File tree

11 files changed

+69
-44
lines changed

11 files changed

+69
-44
lines changed

.mvn/wrapper/maven-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# "License"); you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
88
#
9-
# https://www.apache.org/licenses/LICENSE-2.0
9+
# http://www.apache.org/licenses/LICENSE-2.0
1010
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
@@ -16,4 +16,4 @@
1616
# under the License.
1717
wrapperVersion=3.3.2
1818
distributionType=only-script
19-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

README.adoc

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ image::documentation/project-diagram.jpeg[]
2323
== Prerequisites
2424

2525
* https://www.oracle.com/java/technologies/downloads/#java21[`Java 21+`]
26-
* https://www.docker.com/[`Docker`]
26+
* Some containerization tool https://www.docker.com[`Docker`], https://podman.io[`Podman`], etc.
2727

2828
== Start Environment
2929

30-
* Open a terminal and navigate to `springboot-elasticsearch-thymeleaf` root folder run:
30+
* Open a terminal and navigate to the `springboot-elasticsearch-thymeleaf` root folder run:
3131
+
3232
[source]
3333
----
@@ -38,14 +38,14 @@ docker compose up -d
3838
+
3939
[source]
4040
----
41-
docker compose ps
41+
docker ps -a
4242
----
4343

4444
== Initialize Elasticsearch
4545

4646
NOTE: In the following steps, we will create an index, an alias and do a reindex using pre-defined scripts. In case you prefer to do it step-by-step calling `Elasticsearch` API, refer to link:create-index-alias-reindex.adoc[Creating indexes, alias and reindexing using Elasticsearch API].
4747

48-
* In a terminal, make sure you are in `springboot-elasticsearch-thymeleaf` root folder;
48+
* In a terminal, make sure you are in the `springboot-elasticsearch-thymeleaf` root folder;
4949

5050
* Run the following script to create the index `ecommerce.products.v1` with the alias `ecommerce.products` (you can use the default values by just pressing `Enter` on every user input):
5151
+
@@ -76,7 +76,7 @@ So, the script `./reindex.sh` aims to fix it, setting the type `keyword` to the
7676

7777
== Running applications using Maven
7878

79-
Below are the steps to start and run the applications using `Maven`. We will need to open a terminal for each one. Make sure you are in `springboot-elasticsearch-thymeleaf` root folder while running the commands.
79+
Below are the steps to start and run the applications using `Maven`. We will need to open a terminal for each one. Make sure you are in the `springboot-elasticsearch-thymeleaf` root folder while running the commands.
8080

8181
* **product-api**
8282
+
@@ -95,12 +95,12 @@ Below are the steps to start and run the applications using `Maven`. We will nee
9595
== Running applications as Docker containers
9696

9797
* Build Docker Images
98-
** In a terminal, make sure you are in `springboot-elasticsearch-thymeleaf` root folder;
98+
** In a terminal, make sure you are in the `springboot-elasticsearch-thymeleaf` root folder;
9999
** Run the following script:
100100
+
101101
[source]
102102
----
103-
./docker-build.sh
103+
./build-docker-images.sh
104104
----
105105

106106
* Environment Variables
@@ -126,7 +126,7 @@ Below are the steps to start and run the applications using `Maven`. We will nee
126126
|===
127127

128128
* Run Docker containers
129-
** In a terminal, make sure you are in `springboot-elasticsearch-thymeleaf` root folder;
129+
** In a terminal, make sure you are in the `springboot-elasticsearch-thymeleaf` root folder;
130130
** Run the following script:
131131
+
132132
[source]
@@ -156,13 +156,13 @@ image::documentation/demo-user-interaction.gif[]
156156

157157
* To stop applications:
158158
** If they were started with `Maven`, go to `product-api` and `product-ui` terminals and press `Ctrl+C`;
159-
** If they were started as Docker containers, go to a terminal and, inside `springboot-elasticsearch-thymeleaf` root folder, run the script below:
159+
** If they were started as Docker containers, go to a terminal and, inside the `springboot-elasticsearch-thymeleaf` root folder, run the script below:
160160
+
161161
[source]
162162
----
163163
./stop-apps.sh
164164
----
165-
* To stop and remove docker compose containers, network and volumes, go to a terminal and, inside `springboot-elasticsearch-thymeleaf` root folder, run the following command:
165+
* To stop and remove docker compose containers, network and volumes, go to a terminal and, inside the `springboot-elasticsearch-thymeleaf` root folder, run the following command:
166166
+
167167
[source]
168168
----
@@ -171,7 +171,7 @@ docker compose down -v
171171

172172
== Cleanup
173173

174-
To remove the Docker images created by this project, go to a terminal and, inside `springboot-elasticsearch-thymeleaf` root folder, run the script below:
174+
To remove the Docker images created by this project, go to a terminal and, inside the `springboot-elasticsearch-thymeleaf` root folder, run the script below:
175175
[source]
176176
----
177177
./remove-docker-images.sh

build-docker-images.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER_IMAGE_PREFIX="ivanfranchin"
4+
APP_VERSION="1.0.0"
5+
6+
PRODUCT_API_APP_NAME="product-api"
7+
PRODUCT_UI_APP_NAME="product-ui"
8+
9+
PRODUCT_API_DOCKER_IMAGE_NAME="${DOCKER_IMAGE_PREFIX}/${PRODUCT_API_APP_NAME}:${APP_VERSION}"
10+
PRODUCT_UI_DOCKER_IMAGE_NAME="${DOCKER_IMAGE_PREFIX}/${PRODUCT_UI_APP_NAME}:${APP_VERSION}"
11+
12+
SKIP_TESTS="true"
13+
14+
./mvnw clean compile jib:dockerBuild \
15+
--projects "$PRODUCT_API_APP_NAME" \
16+
-DskipTests="$SKIP_TESTS" \
17+
-Dimage="$PRODUCT_API_DOCKER_IMAGE_NAME"
18+
19+
./mvnw clean compile jib:dockerBuild \
20+
--projects "$PRODUCT_UI_APP_NAME" \
21+
-DskipTests="$SKIP_TESTS" \
22+
-Dimage="$PRODUCT_UI_DOCKER_IMAGE_NAME"

docker-build.sh

-4
This file was deleted.

docker-compose.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
services:
22

33
elasticsearch:
4-
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
5-
container_name: elasticsearch
6-
restart: unless-stopped
4+
image: 'docker.elastic.co/elasticsearch/elasticsearch:8.15.4'
5+
container_name: 'elasticsearch'
76
ports:
8-
- "9200:9200"
9-
- "9300:9300"
7+
- '9200:9200'
8+
- '9300:9300'
109
environment:
11-
discovery.type: single-node
12-
xpack.security.enabled: false
13-
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
10+
- 'discovery.type=single-node'
11+
- 'xpack.security.enabled=false'
12+
- 'ES_JAVA_OPTS=-Xms512m -Xmx512m'
1413
healthcheck:
15-
test: "curl -f http://localhost:9200 || exit 1"
14+
test: 'curl -f http://localhost:9200 || exit 1'

mvnw

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# "License"); you may not use this file except in compliance
99
# with the License. You may obtain a copy of the License at
1010
#
11-
# https://www.apache.org/licenses/LICENSE-2.0
11+
# http://www.apache.org/licenses/LICENSE-2.0
1212
#
1313
# Unless required by applicable law or agreed to in writing,
1414
# software distributed under the License is distributed on an

mvnw.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@REM "License"); you may not use this file except in compliance
99
@REM with the License. You may obtain a copy of the License at
1010
@REM
11-
@REM https://www.apache.org/licenses/LICENSE-2.0
11+
@REM http://www.apache.org/licenses/LICENSE-2.0
1212
@REM
1313
@REM Unless required by applicable law or agreed to in writing,
1414
@REM software distributed under the License is distributed on an

pom.xml

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.3.2</version>
8+
<version>3.4.1</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111

@@ -18,9 +18,7 @@
1818

1919
<properties>
2020
<java.version>21</java.version>
21-
<jib-maven-plugin.version>3.4.3</jib-maven-plugin.version>
22-
<jdk-image.version>21.0.4</jdk-image.version>
23-
<docker-image.prefix>ivanfranchin</docker-image.prefix>
21+
<jib-maven-plugin.version>3.4.4</jib-maven-plugin.version>
2422
</properties>
2523

2624
<modules>
@@ -34,14 +32,6 @@
3432
<groupId>com.google.cloud.tools</groupId>
3533
<artifactId>jib-maven-plugin</artifactId>
3634
<version>${jib-maven-plugin.version}</version>
37-
<configuration>
38-
<from>
39-
<image>amazoncorretto:${jdk-image.version}</image>
40-
</from>
41-
<to>
42-
<image>${docker-image.prefix}/${project.artifactId}:${project.version}</image>
43-
</to>
44-
</configuration>
4535
</plugin>
4636
</plugins>
4737
</build>

product-api/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<description>Demo project for Spring Boot</description>
1515

1616
<properties>
17-
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
18-
<springdoc-openapi.version>2.6.0</springdoc-openapi.version>
17+
<org.mapstruct.version>1.6.3</org.mapstruct.version>
18+
<springdoc-openapi.version>2.7.0</springdoc-openapi.version>
1919
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
2020
</properties>
2121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ivanfranchin.productapi.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.data.web.config.EnableSpringDataWebSupport;
5+
6+
import static org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO;
7+
8+
/*
9+
The reason this configuration class was added is to prevent the following WARN message from occurring.
10+
11+
WARN Serializing PageImpl instances as-is is not supported, meaning that there is no guarantee about the stability of the resulting JSON structure!
12+
For a stable JSON structure, please use Spring Data's PagedModel (globally via @EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO))
13+
or Spring HATEOAS and Spring Data's PagedResourcesAssembler as documented in https://docs.spring.io/spring-data/commons/reference/repositories/core-extensions.html#core.web.pageables.
14+
*/
15+
@Configuration
16+
@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
17+
public class SpringDataWebSupportConfig {
18+
}

start-apps.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ docker run -d --rm --name product-api \
99
-p 8080:8080 \
1010
-e ELASTICSEARCH_URIS=elasticsearch:9200 \
1111
--network springboot-elasticsearch-thymeleaf_default \
12-
--health-cmd="curl -f http://localhost:8080/actuator/health || exit 1" \
12+
--health-cmd='[ -z "$(echo "" > /dev/tcp/localhost/8080)" ] || exit 1' \
1313
ivanfranchin/product-api:1.0.0
1414

1515
wait_for_container_log "product-api" "Started"
@@ -21,7 +21,7 @@ docker run -d --rm --name product-ui \
2121
-p 9080:8080 \
2222
-e PRODUCT_API_URL=http://product-api:8080 \
2323
--network springboot-elasticsearch-thymeleaf_default \
24-
--health-cmd="curl -f http://localhost:8080/actuator/health || exit 1" \
24+
--health-cmd='[ -z "$(echo "" > /dev/tcp/localhost/9080)" ] || exit 1' \
2525
ivanfranchin/product-ui:1.0.0
2626

2727
wait_for_container_log "product-ui" "Started"

0 commit comments

Comments
 (0)