Skip to content
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
32 changes: 15 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: SonarCloud

on:
push:
branches:
- main
- main_5

env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
Expand All @@ -14,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0 # Shallow clones should be disabled for better analysis relevancy
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand All @@ -39,30 +41,24 @@ jobs:
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Raouf25_Spring-Boot-efficient-search-API

docker:
# docker-repository: https://hub.docker.com/r/raouf25/spring-boot-efficient-search-api
name: Build & push in Docker Hub
name: Build & push to Docker Hub
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
- name: Build Docker image
run: docker build -t raouf25/spring-boot-efficient-search-api .
- name: Push to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
raouf25/spring-boot-efficient-search-api:1.0.0
raouf25/spring-boot-efficient-search-api:latest
- name: Docker push
run: |
docker push raouf25/spring-boot-efficient-search-api:latest
docker tag raouf25/spring-boot-efficient-search-api registry.fly.io/spring-boot-efficient-search-api
docker images | grep "spring-boot-efficient"

deploy:
environment:
Expand All @@ -74,4 +70,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
- run: |
flyctl deploy -i registry.fly.io/spring-boot-efficient-search-api

103 changes: 20 additions & 83 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,83 +1,20 @@
#
# Build stage
#
FROM maven:3.8.7-eclipse-temurin-19 AS MAVEN_BUILD
COPY pom.xml /build/
COPY . /build/
WORKDIR /build/
#The option "--quiet" is used to limit the output to only warnings and errors (1)
RUN mvn clean package -DskipTests --quiet

#
# Package stage
#
# base image to build a JRE
FROM amazoncorretto:19.0.2-alpine AS deps

# Identify dependencies (2)
COPY --from=MAVEN_BUILD ./build/target/*-SNAPSHOT.jar /app/app.jar
RUN mkdir /app/unpacked && \
cd /app/unpacked && \
unzip ../app.jar && \
cd .. && \
$JAVA_HOME/bin/jdeps \
--ignore-missing-deps \
--print-module-deps \
-q \
--recursive \
--multi-release 17 \
--class-path="./unpacked/BOOT-INF/lib/*" \
--module-path="./unpacked/BOOT-INF/lib/*" \
./app.jar > /deps.info && \
rm -rf ./unpacked

# base image to build a JRE
FROM amazoncorretto:19.0.2-alpine AS corretto-jdk

# required for strip-debug to work
RUN apk add --no-cache binutils

# copy module dependencies info
COPY --from=deps /deps.info /deps.info

# Build small JRE image (3)
RUN $JAVA_HOME/bin/jlink \
--verbose \
--add-modules $(cat /deps.info) \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /customjre

## run this command with this option to display dependencies
## docker build -t spring-boot-efficient-search-api-custom-5 . --progress plain
RUN file0="$(cat /deps.info)" && echo $file0

# main app image
FROM alpine:latest
ENV JAVA_HOME=/jre
ENV PATH="${JAVA_HOME}/bin:${PATH}"

# copy JRE from the base image
COPY --from=corretto-jdk /customjre $JAVA_HOME

# Add app user
ARG APPLICATION_USER=appuser
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER

# Configure working directory
RUN mkdir /app && \
chown -R $APPLICATION_USER /app

# Set the working directory
WORKDIR /app

# Copy the built JAR file from the build stage
COPY --chown=1000:1000 --from=MAVEN_BUILD /build/target/spring-boot-efficient-search-api-0.0.1-SNAPSHOT.jar /app/app.jar

# Expose port 8080
EXPOSE 8080

# Run the JAR file as the entrypoint
ENTRYPOINT [ "/jre/bin/java", "-jar", "/app/app.jar" ]
# Using Oracle GraalVM for JDK 21
FROM container-registry.oracle.com/graalvm/native-image:21-ol8 AS builder

# Set the working directory to /home/app
WORKDIR /build

# Copy the source code into the image for building
COPY . /build

# Build
RUN ./mvnw --no-transfer-progress native:compile -Pnative -DskipTests

# The deployment Image
FROM container-registry.oracle.com/os/oraclelinux:8-slim

EXPOSE 8080

# Copy the native executable into the containers
COPY --from=builder /build/target/spring-boot-efficient-search-api app
ENTRYPOINT ["/app"]
19 changes: 0 additions & 19 deletions Dockerfile_default

This file was deleted.

37 changes: 0 additions & 37 deletions jdeps/Dockerfile

This file was deleted.

31 changes: 30 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Demo project for Spring Boot efficient search api</description>

<properties>
<java.version>19</java.version>
<java.version>21</java.version>

<!-- SonarCloud -->
<sonar.organization>raouf25-github</sonar.organization>
Expand Down Expand Up @@ -91,14 +91,43 @@
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.165</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- a voir https://medium.com/ekino-france/native-image-with-spring-boot-70f32788528c-->
<!-- mvn -Pnative spring-boot:build-image-->
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</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.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mak.springbootefficientsearchapi.configuration;

import net.kaczmarzyk.spring.data.jpa.nativeimage.SpecificationArgumentResolverHintRegistrar;
import net.kaczmarzyk.spring.data.jpa.web.SpecificationArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -10,6 +12,10 @@

@Configuration
@EnableTransactionManagement
// Doc: https://github.com/tkaczmarzyk/specification-arg-resolver/blob/master/README_native_image.md
@ImportRuntimeHints({SpecificationArgumentResolverHintRegistrar.class,
ProjectSpecificationArgumentResolverProxyHintRegistrar.class}) //support for reflection //support for dynamic proxy

public class JpaConfiguration implements WebMvcConfigurer {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mak.springbootefficientsearchapi.configuration;

import net.kaczmarzyk.spring.data.jpa.nativeimage.SpecificationArgumentResolverProxyHintRegistrar;

class ProjectSpecificationArgumentResolverProxyHintRegistrar extends SpecificationArgumentResolverProxyHintRegistrar {
protected ProjectSpecificationArgumentResolverProxyHintRegistrar() {
super(
"com.mak.springbootefficientsearchapi.controller" // the name of package containing the interfaces with specification definitions
);
}
}