From bb5887991b153c3ab78f41b5d0c0d389c319c1eb Mon Sep 17 00:00:00 2001 From: Pete Stevenson Date: Mon, 16 May 2022 14:48:14 -0700 Subject: [PATCH 1/3] Upgrade to Java 18. Signed-off-by: Pete Stevenson --- pom.xml | 48 ++++++++++++++++--- .../weave/socks/cart/CartApplication.java | 2 - 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 8f1ef5182..cd35fd868 100644 --- a/pom.xml +++ b/pom.xml @@ -14,28 +14,60 @@ org.springframework.boot spring-boot-starter-parent - 2.0.4.RELEASE + 2.4.0 + UTF-8 - 1.8 + 18 0.0.21 + + org.hibernate.validator + hibernate-validator + + + com.h2database + h2 + + + org.springframework.boot + spring-boot-starter-data-jpa + 2.6.7 + + + org.springframework + spring-core + 5.3.19 + + + javax.validation + validation-api + 2.0.1.Final + + + org.mongodb + mongo-java-driver + 3.12.10 + + + junit + junit + 4.13.2 + test + org.springframework.boot spring-boot-starter-data-rest + 2.6.6 org.springframework.boot spring-boot-starter-data-mongodb - - - org.springframework.cloud - spring-cloud-starter-zipkin - 1.1.0.RELEASE + 2.6.6 io.prometheus @@ -55,6 +87,7 @@ org.springframework.data spring-data-rest-hal-browser + 3.3.9.RELEASE org.springframework.boot @@ -81,6 +114,7 @@ org.springframework.boot spring-boot-maven-plugin + 1.5.22.RELEASE org.apache.maven.plugins diff --git a/src/main/java/works/weave/socks/cart/CartApplication.java b/src/main/java/works/weave/socks/cart/CartApplication.java index 51d9a8d45..edef51ae7 100644 --- a/src/main/java/works/weave/socks/cart/CartApplication.java +++ b/src/main/java/works/weave/socks/cart/CartApplication.java @@ -1,11 +1,9 @@ package works.weave.socks.cart; -import io.prometheus.client.spring.boot.EnablePrometheusEndpoint; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@EnablePrometheusEndpoint public class CartApplication { public static void main(String[] args) { SpringApplication.run(CartApplication.class, args); From 5fa21d82073c34e2f4c68d7a1f9ada400369b15b Mon Sep 17 00:00:00 2001 From: Pete Stevenson Date: Mon, 16 May 2022 14:52:01 -0700 Subject: [PATCH 2/3] Use maven on Java v18 for Java upgrade. Signed-off-by: Pete Stevenson --- scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index 7f6271768..ef8955c96 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -24,7 +24,7 @@ else fi CODE_DIR=$(cd $SCRIPT_DIR/..; pwd) echo $CODE_DIR -$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.6-jdk-11 mvn -q -DskipTests package +$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.8.5-openjdk-18 mvn -q -DskipTests package cp $CODE_DIR/target/*.jar $CODE_DIR/docker/carts From 3fc84994de066d882fb8685b4c35cddf1afc8d52 Mon Sep 17 00:00:00 2001 From: Ryan Cheng Date: Thu, 26 Jan 2023 16:22:55 -0800 Subject: [PATCH 3/3] Upgrade to java 18 and fix dependencies and api changes --- Dockerfile | 2 +- docker/carts/Dockerfile | 23 +++------------- pom.xml | 27 +++++++++---------- scripts/build.sh | 4 ++- .../configuration/MongoConfiguration.java | 10 ------- .../middleware/HTTPMonitoringInterceptor.java | 4 +-- 6 files changed, 23 insertions(+), 47 deletions(-) diff --git a/Dockerfile b/Dockerfile index bf46d5e41..cbdbda91e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM java:openjdk-8-alpine +FROM openjdk:18-alpine WORKDIR /usr/src/app COPY ./target/*.jar ./app.jar diff --git a/docker/carts/Dockerfile b/docker/carts/Dockerfile index 3938aff44..d8631177b 100644 --- a/docker/carts/Dockerfile +++ b/docker/carts/Dockerfile @@ -1,24 +1,9 @@ -FROM weaveworksdemos/msd-java:jre-latest +FROM openjdk:18-jdk-alpine WORKDIR /usr/src/app COPY *.jar ./app.jar -RUN chown -R ${SERVICE_USER}:${SERVICE_GROUP} ./app.jar +RUN chown -R root:root ./app.jar -USER ${SERVICE_USER} - -ARG BUILD_DATE -ARG BUILD_VERSION -ARG COMMIT - -LABEL org.label-schema.vendor="Weaveworks" \ - org.label-schema.build-date="${BUILD_DATE}" \ - org.label-schema.version="${BUILD_VERSION}" \ - org.label-schema.name="Socks Shop: Cart" \ - org.label-schema.description="REST API for Cart service" \ - org.label-schema.url="https://github.com/microservices-demo/carts" \ - org.label-schema.vcs-url="github.com:microservices-demo/carts.git" \ - org.label-schema.vcs-ref="${COMMIT}" \ - org.label-schema.schema-version="1.0" - -ENTRYPOINT ["/usr/local/bin/java.sh","-jar","./app.jar", "--port=80"] +USER root +ENTRYPOINT ["java","-jar","./app.jar", "--port=8080"] diff --git a/pom.xml b/pom.xml index cd35fd868..92d889404 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.0 + 3.0.2 @@ -36,23 +36,18 @@ org.springframework.boot spring-boot-starter-data-jpa - 2.6.7 + 3.0.2 org.springframework spring-core - 5.3.19 + 6.0.4 javax.validation validation-api 2.0.1.Final - - org.mongodb - mongo-java-driver - 3.12.10 - junit junit @@ -62,12 +57,11 @@ org.springframework.boot spring-boot-starter-data-rest - 2.6.6 + 3.0.2 org.springframework.boot spring-boot-starter-data-mongodb - 2.6.6 io.prometheus @@ -106,6 +100,11 @@ 0.8.4 test + + javax.servlet + javax.servlet-api + 4.0.1 + @@ -114,12 +113,12 @@ org.springframework.boot spring-boot-maven-plugin - 1.5.22.RELEASE + 3.0.2 org.apache.maven.plugins maven-surefire-plugin - 2.19.1 + 3.0.0-M8 **/Unit*.java @@ -132,7 +131,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.18.1 + 3.0.0-M8 **/IT*.java @@ -153,7 +152,7 @@ org.jacoco jacoco-maven-plugin - 0.7.6.201602180812 + 0.8.8 prepare-agent diff --git a/scripts/build.sh b/scripts/build.sh index ef8955c96..ee014c417 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -24,7 +24,9 @@ else fi CODE_DIR=$(cd $SCRIPT_DIR/..; pwd) echo $CODE_DIR -$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.8.5-openjdk-18 mvn -q -DskipTests package +$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.8.5-openjdk-18 mvn -q -e -DskipTests package + +echo $(ls -lt $CODE_DIR/target/*.jar) cp $CODE_DIR/target/*.jar $CODE_DIR/docker/carts diff --git a/src/main/java/works/weave/socks/cart/configuration/MongoConfiguration.java b/src/main/java/works/weave/socks/cart/configuration/MongoConfiguration.java index 89688859d..9dd41bbe8 100644 --- a/src/main/java/works/weave/socks/cart/configuration/MongoConfiguration.java +++ b/src/main/java/works/weave/socks/cart/configuration/MongoConfiguration.java @@ -5,17 +5,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.mongodb.MongoClientOptions; - @Configuration @AutoConfigureBefore(MongoAutoConfiguration.class) public class MongoConfiguration { - - @Bean - public MongoClientOptions optionsProvider() { - MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder(); - optionsBuilder.serverSelectionTimeout(10000); - MongoClientOptions options = optionsBuilder.build(); - return options; - } } diff --git a/src/main/java/works/weave/socks/cart/middleware/HTTPMonitoringInterceptor.java b/src/main/java/works/weave/socks/cart/middleware/HTTPMonitoringInterceptor.java index 728b3423f..105c8e8ad 100644 --- a/src/main/java/works/weave/socks/cart/middleware/HTTPMonitoringInterceptor.java +++ b/src/main/java/works/weave/socks/cart/middleware/HTTPMonitoringInterceptor.java @@ -13,8 +13,8 @@ import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.util.HashSet; import java.util.Set;