Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into
Browse files Browse the repository at this point in the history
EA3647-update_to_mongo6, switch to mongo 6, JDK17, SpringDoc
  • Loading branch information
GordeaS authored and GordeaS committed Mar 14, 2024
2 parents 0bc9fae + 978e58a commit 3bc8dc7
Show file tree
Hide file tree
Showing 30 changed files with 451 additions and 286 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/build_test_analyse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
# Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 171
uses: actions/setup-java@v3
with:
java-version: 11
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
distribution: 'temurin' #should use the same as in the docker file
java-version: 17
cache: 'maven'
cache-dependency-path: 'sub-project/pom.xml' # optional
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Builds a docker image from a locally built Maven war. Requires 'mvn package' to have been run beforehand
# when needed the image can be switched from jre to jdk, but the jdk has about 200MB
#FROM eclipse-temurin:11-jdk-alpine
FROM eclipse-temurin:11-jre-alpine
#FROM eclipse-temurin:11-jre-alpine
FROM eclipse-temurin:17-jre-alpine
LABEL Author="Europeana Foundation <[email protected]>"

# Configure APM and add APM agent
ENV ELASTIC_APM_VERSION 1.34.1
#disabled by default, to be enabled by kustomize/build params for specific servers only
ENV ELASTIC_APM_ENABLED false
ADD https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/$ELASTIC_APM_VERSION/elastic-apm-agent-$ELASTIC_APM_VERSION.jar /opt/app/elastic-apm-agent.jar

COPY ./set-web/target/set-web-executable.jar /opt/app/set-web-executable.jar
Expand Down
118 changes: 105 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,24 @@

<properties>
<revision>0.12-SNAPSHOT</revision>
<version.java>11</version.java>
<version.javac.release>11</version.javac.release>
<version.log4j2>2.17.2</version.log4j2>
<version.commonsApi>0.3.22-SNAPSHOT</version.commonsApi>
<version.springBoot>2.5.7</version.springBoot>
<version.springBootMongoStarter>2.0.3.RELEASE</version.springBootMongoStarter>
<version.swagger>3.0.0</version.swagger>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.release>${java.version}</maven.compiler.release>

<!-- property to be used for add opens jvm arguments in plugins -->
<java.17.addopens>--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
</java.17.addopens>
<version.commonsApi>0.3.24-SNAPSHOT</version.commonsApi>
<version.springBoot>2.5.14</version.springBoot>

<!-- overwrite version defined in spring boot parent pom -->
<mongodb.version>4.7.2</mongodb.version>
<version.morphia>1.6.1</version.morphia>

<springdoc.version>1.6.14</springdoc.version>

<version.httpClient>3.1</version.httpClient>
<version.javax.annotation>1.3.2</version.javax.annotation>
<version.jettison>1.3</version.jettison>
Expand All @@ -62,7 +73,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- test dependencies -->
<version.testcontainers>1.16.0</version.testcontainers>
<version.testcontainers>1.19.7</version.testcontainers>

<!-- maven plugins -->
<version.maven-surfire-plugin>3.0.0-M6</version.maven-surfire-plugin>
Expand Down Expand Up @@ -98,15 +109,87 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- upgrade mongo driver and morphia to support mongo V6-->
<!-- SG: for some reason, the versions from spring boot take precedence over the versions from api-commons depencies, therefore we need to replicate here the configs from api-commons -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
<version>${mongodb.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>${mongodb.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>${mongodb.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>${mongodb.version}</version>
</dependency>

<dependency>
<groupId>dev.morphia.morphia</groupId>
<artifactId>core</artifactId>
<version>${version.morphia}</version>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</exclusion>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
</exclusion>
</exclusions>
</dependency>



<!-- excude conflicting dependecies for mongo and logging-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>${version.springBoot}</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</exclusion>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
</dependencyManagement>


<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>*.bk</exclude>
</excludes>
</resource>
</resources>
<testResources>
Expand Down Expand Up @@ -146,9 +229,10 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--
<version>${version.spring.boot}</version>
-->
<configuration>
<jvmArguments>${java.17.addopens}</jvmArguments>
</configuration>

<executions>
<execution>
<goals>
Expand All @@ -160,13 +244,15 @@
<!-- For some reason BuildProperties.getName() doesn't return the correct value,
so we set the name under a different property -->
<project.name>${project.name}</project.name>
<!--
<custom.value>123</custom.value>
-->
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe}</version>
<executions>
Expand Down Expand Up @@ -216,6 +302,9 @@
<resource>
<filtering>true</filtering>
<directory>src/integration-test/resources</directory>
<excludes>
<exclude>*.bk</exclude>
</excludes>
</resource>
</resources>
</configuration>
Expand All @@ -242,10 +331,13 @@
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<!--
<configuration>
<source>${version.java}</source>
<target>${version.java}</target>
</configuration>
-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
3 changes: 0 additions & 3 deletions set-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@
</properties>

<dependencies>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${version.log4j2}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${version.log4j2}</version>
</dependency>

<dependency>
Expand Down
18 changes: 16 additions & 2 deletions set-integration-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Test dependencies -->
Expand Down Expand Up @@ -93,13 +99,21 @@
<artifactId>spring-boot-test-autoconfigure</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>mongodb</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
@AutoConfigureMockMvc
@DirtiesContext
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ContextConfiguration(locations = {"classpath:set-web-context.xml"})
@ComponentScan(basePackageClasses = UserSetApp.class)
@ContextConfiguration(locations = {"classpath:set-web-context.xml"})
public abstract class BaseUserSetTestUtils {

protected static final String BASE_URL = "/set/";
Expand Down Expand Up @@ -132,8 +132,10 @@ public abstract class BaseUserSetTestUtils {
private static final MongoContainer MONGO_CONTAINER;

static {
MONGO_CONTAINER = new MongoContainer("admin")
.withLogConsumer(new WaitingConsumer().andThen(new ToStringConsumer()));
// MONGO_CONTAINER = new MongoDBContainer("mongo:6.0.14-jammy")
MONGO_CONTAINER = new MongoContainer("set-api-test")
.withLogConsumer(new WaitingConsumer()
.andThen(new ToStringConsumer()));

MONGO_CONTAINER.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ private MongoContainer(

this.withEnv("MONGO_INITDB_ROOT_USERNAME", adminUsername);
this.withEnv("MONGO_INITDB_ROOT_PASSWORD", adminPassword);
this.withEnv("ANNOTATION_DB", annotationDb);
this.withEnv("MONGO_INITDB_DATABASE", annotationDb);

this.waitingFor(Wait.forLogMessage("(?i).*waiting for connections.*", 1));
this.waitingFor(Wait.forLogMessage("(?i).*Waiting for connections.*", 1));
this.annotationDb = annotationDb;
}

Expand All @@ -52,7 +52,7 @@ public String getConnectionUrl() {
throw new IllegalStateException("MongoDBContainer should be started first");
} else {
String connectionUrl = String.format(
"mongodb://%s:%s@%s:%d/%s?ssl=false",
"mongodb://%s:%s@%s:%d/%s?authSource=admin&ssl=false",
adminUsername, adminPassword, this.getHost(), this.getMappedPort(defaultMongoPort), this.getAnnotationDb());
return connectionUrl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
spring.main.allow-bean-definition-overriding=true
spring.main.allow-bean-definition-overriding=true

#switch Spring boot logging to log4j (see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.logging)
org.springframework.boot.logging.LoggingSystem= org.springframework.boot.logging.log4j2.Log4J2LoggingSystem

## management / actuator / swagger
#springfox.documentation.swagger-ui.enabled=true
management.security.enabled=false

management.endpoints.web.exposure.include=health,info
# for debugging conditioonal annotations locally the following configuration can be used
management.info.build.enabled=true
management.info.git.enabled=true
management.health.probes.enabled=true

## Configurations for swagger console
springdoc.paths-to-exclude=/error
springdoc.show-actuator=true

## server configurations
server.port = 8080
server.error.include-message=always
server.error.include-stacktrace=on_param
server.error.include-exception=false
server.error.see-also=https://pro.europeana.eu/page/apis
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Please note, this file should have unix-based end of line
# Use same version as CloudFoundry deployment
FROM library/mongo:4.4.15
#FROM library/mongo:4.4.15
FROM library/mongo:6.0.14-jammy

EXPOSE 27017

ENV MONGO_INITDB_ROOT_USERNAME admin
ENV MONGO_INITDB_ROOT_PASSWORD password
ENV MONGO_INITDB_ROOT_USERNAME admin_user
ENV MONGO_INITDB_ROOT_PASSWORD admin_password

COPY init-mongo.sh /docker-entrypoint-initdb.d/init-mongo.sh
#MONGO_INITDB_DATABASE

#COPY init-mongo.sh /docker-entrypoint-initdb.d/init-mongo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# The root user is created because of setting the given env variables (e.g. MONGO_INITDB_ROOT_USERNAME), and it is automatically placed in the "admin" db
# The script schould have a unix end of line
# in case of errors use notepad++ to change EOL to unix LF (edit -> EOL Conversion)
mongo -- "$MONGO_INITDB_DATABASE" <<EOF
## DEPRECATED NOT USED ANYMORE BUT KEPT IN THE CASE WILL BE NEEDED IN THE FUTURE
mongosh --eval "$MONGO_INITDB_DATABASE" <<EOF
var rootUser = '$MONGO_INITDB_ROOT_USERNAME';
var rootPassword = '$MONGO_INITDB_ROOT_PASSWORD';
Expand Down
Loading

0 comments on commit 3bc8dc7

Please sign in to comment.