Skip to content

Commit

Permalink
feat: enable cloud native on oracle-api (#1327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Campos authored Jul 3, 2024
1 parent 69f57d2 commit a909731
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 38 deletions.
22 changes: 14 additions & 8 deletions oracle-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
FROM openjdk:17.0.2 AS build
FROM ghcr.io/graalvm/native-image:22.3.3 AS build

# Build
# Copy
WORKDIR /app
COPY . ./
RUN ./mvnw --no-transfer-progress --update-snapshots clean package -Dtests.skip=true -Dskip.unit.tests=true -Dspring-boot.run.profiles=prod && \
javac HealthCheck.java InstallCert.java
COPY pom.xml mvnw ./
COPY src ./src
COPY .mvn/ ./.mvn
COPY InstallCert.java .

# Build
RUN ./mvnw package -Pnative -DskipTests -Dskip.unit.tests=true -Dspring-boot.run.profiles=prod && \
javac InstallCert.java

### Deployer
FROM eclipse-temurin:17.0.11_9-jdk-jammy AS deploy

# Java vars
ENV LANG en_CA.UTF-8
ENV LANGUAGE en_CA.UTF-8
ENV LC_ALL en_CA.UTF-8
ENV LANG=en_CA.UTF-8
ENV LANGUAGE=en_CA.UTF-8
ENV LC_ALL=en_CA.UTF-8

# Setup package/archive and supporting files
WORKDIR /usr/share/service/
Expand Down
29 changes: 0 additions & 29 deletions oracle-api/HealthCheck.java

This file was deleted.

1 change: 1 addition & 0 deletions oracle-api/dockerfile-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ java \
-Djava.security.egd=file:/dev/./urandom \
${JAVA_OPTS} \
-jar \
-Dspring.profiles.active=prod \
/usr/share/service/artifacts/nr-spar-oracle-api.jar
2 changes: 1 addition & 1 deletion oracle-api/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ parameters:
- name: CPU_REQUEST
value: 100m
- name: CPU_LIMIT
value: 175m
value: 300m
- name: MEMORY_REQUEST
value: 300Mi
- name: MEMORY_LIMIT
Expand Down
58 changes: 58 additions & 0 deletions oracle-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<sonar.organization>bcgov-sonarcloud</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<oci.revision>${project.version}</oci.revision>
<hibernate.version>6.4.4.Final</hibernate.version>
</properties>

<profiles>
Expand All @@ -65,6 +67,39 @@
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>

<!-- cloud native -->
<profile>
<id>native</id>
<properties>
<build.profile.id>native</build.profile.id>
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
<jacoco.skip>true</jacoco.skip>
</properties>
<build>
<plugins>
<!--
GraalVM: Cloud Native support
More: https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Even more: https://graalvm.github.io/native-build-tools/latest/maven-plugin.html
-->
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
Expand Down Expand Up @@ -151,6 +186,29 @@

<build>
<plugins>
<!--
Hibernate: Configs for Hibernate Cloud Native compatibility
More: https://vladmihalcea.com/maven-gradle-hibernate-enhance-plugin/
-->
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions oracle-api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Server and application
spring.application.name = spar-oracle-api
server.port = ${SERVER_PORT:8090}
server.error.include-message = always
server.shutdown = graceful
app.version = @project.version@

# OpenSearch settings
Expand Down Expand Up @@ -41,6 +43,11 @@ spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
# Actuator and ops
management.endpoint.health.show-details = always

# Native Cloud
springdoc.enable-native-support = true
# https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.2
quarkus.native.additional-build-args=-march=native

# Others
nr-spar-oracle-api.version = ${NR_SPAR_ORACLE_API_VERSION:local}
server.allowed.cors.origins = ${ALLOWED_ORIGINS:#{'http://localhost:300*, http://127.*'}}
Expand Down

0 comments on commit a909731

Please sign in to comment.