Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Upgrade carts service to java 18 #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM java:openjdk-8-alpine
FROM openjdk:18-alpine

WORKDIR /usr/src/app
COPY ./target/*.jar ./app.jar
Expand Down
23 changes: 4 additions & 19 deletions docker/carts/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
53 changes: 43 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,55 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<version>3.0.2</version>
<relativePath/>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<java.version>18</java.version>
<prometheus.version>0.0.21</prometheus.version>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>6.0.4</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
Expand All @@ -55,6 +81,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -73,6 +100,11 @@
<version>0.8.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>

<build>
Expand All @@ -81,11 +113,12 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<version>3.0.0-M8</version>
<configuration>
<includes>
<include>**/Unit*.java</include>
Expand All @@ -98,7 +131,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<version>3.0.0-M8</version>
<configuration>
<includes>
<include>**/IT*.java</include>
Expand All @@ -119,7 +152,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<version>0.8.8</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
4 changes: 3 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 -e -DskipTests package

echo $(ls -lt $CODE_DIR/target/*.jar)

cp $CODE_DIR/target/*.jar $CODE_DIR/docker/carts

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/works/weave/socks/cart/CartApplication.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down