Add Docker support and update Java version to 21

This commit is contained in:
2026-04-28 11:36:47 +02:00
parent 1988d2f017
commit 17f3179ec5
7 changed files with 168 additions and 3 deletions
+11
View File
@@ -9,10 +9,21 @@
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<module name="ListHubBackend" /> <module name="ListHubBackend" />
</profile> </profile>
<profile name="Annotation profile for ListHubBackend" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false">
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar" />
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.30/lombok-1.18.30.jar" />
</processorPath>
<module name="ArtisanConnectBackend" />
</profile>
</annotationProcessing> </annotationProcessing>
</component> </component>
<component name="JavacSettings"> <component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE"> <option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="ArtisanConnectBackend" options="-parameters" />
<module name="ListHubBackend" options="-parameters" /> <module name="ListHubBackend" options="-parameters" />
</option> </option>
</component> </component>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CopilotDiffPersistence">
<option name="pendingDiffs">
<map>
<entry key="$PROJECT_DIR$/src/main/java/_11/asktpk/artisanconnectbackend/ArtisanConnectBackendApplication.java">
<value>
<PendingDiffInfo>
<option name="filePath" value="$PROJECT_DIR$/src/main/java/_11/asktpk/artisanconnectbackend/ArtisanConnectBackendApplication.java" />
<option name="originalContent" value="package _11.asktpk.artisanconnectbackend;&#10;&#10;import jakarta.annotation.PostConstruct;&#10;import org.springframework.boot.SpringApplication;&#10;import org.springframework.boot.autoconfigure.SpringBootApplication;&#10;import org.springframework.core.env.Environment;&#10;&#10;@SpringBootApplication&#10;public class ArtisanConnectBackendApplication {&#10;&#10; private final Environment environment;&#10;&#10; public ArtisanConnectBackendApplication(Environment environment) {&#10; this.environment = environment;&#10; }&#10;&#10; static void main(String[] args) {&#10; SpringApplication.run(ArtisanConnectBackendApplication.class, args);&#10; }&#10;&#10; @PostConstruct&#10; public void logDataSourceUrl() {&#10; System.out.println(&quot;Datasource URL: &quot; + environment.getProperty(&quot;spring.datasource.url&quot;));&#10; }&#10;}&#10;&#10;&#10;" />
<option name="updatedContent" value="package _11.asktpk.artisanconnectbackend;&#10;&#10;import jakarta.annotation.PostConstruct;&#10;import org.springframework.boot.SpringApplication;&#10;import org.springframework.boot.autoconfigure.SpringBootApplication;&#10;import org.springframework.core.env.Environment;&#10;&#10;@SpringBootApplication&#10;public class ArtisanConnectBackendApplication {&#10;&#10; private final Environment environment;&#10;&#10; public ArtisanConnectBackendApplication(Environment environment) {&#10; this.environment = environment;&#10; }&#10;&#10; public static void main(String[] args) {&#10; SpringApplication.run(ArtisanConnectBackendApplication.class, args);&#10; }&#10;&#10; @PostConstruct&#10; public void logDataSourceUrl() {&#10; System.out.println(&quot;Datasource URL: &quot; + environment.getProperty(&quot;spring.datasource.url&quot;));&#10; }&#10;}&#10;&#10;&#10;" />
</PendingDiffInfo>
</value>
</entry>
</map>
</option>
</component>
</project>
+65
View File
@@ -0,0 +1,65 @@
# How to run container
### Build
In the root directory of project there is `Dockerfile` in which image is defined.
<br> Build the image:
```bash
docker build -t listhub:1.0 .
```
Then after building the image you can run it. You will need to define some environment variables.
```bash
docker run -d \
--name listhub_backend \
-p 8080:8080 \
-e JWT_SECRET=<paste_your_secret_here> \
-e DB_URL=jdbc:postgresql://db:5432/postgres \
-e DB_USER=postgres \
-e DB_PASS=postgres \
listhub_backend:1.0
```
or you can use compose file with .env file
```text
// .env
JWT_SECRET=<paste_your_secret_here>
DB_URL=jdbc:postgresql://db:5432/postgres
DB_USER=listhub
DB_PASS=postgres
```
```yaml
# docker-compose.yaml
services:
db:
image: postgres:14
restart: unless-stopped
environment:
POSTGRES_DB: listhub
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
listhub_backend:
build: .
restart: unless-stopped
depends_on:
- db
environment:
DB_URL: jdbc:postgresql://db:5432/listhub
DB_USER: postgres
DB_PASS: postgres
JWT_SECRET: awdpokawodjawoidjawidjoij120391829d3j8a0jd8s9dawd
ports:
- "8080:8080"
volumes:
- listhub_data:/app
volumes:
postgres_data:
listhub_data:
```
+22
View File
@@ -0,0 +1,22 @@
FROM maven:3-amazoncorretto-21-alpine AS builder
WORKDIR /workspace
COPY pom.xml ./
COPY mvnw ./
COPY .mvn .mvn
RUN mvn -B -DskipTests dependency:go-offline
COPY src ./src
RUN mvn -B -DskipTests package
FROM amazoncorretto:21-alpine AS runtime
WORKDIR /app
COPY --from=builder /workspace/target/*.jar /app/app.jar
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Djava.security.egd=file:/dev/./urandom"
EXPOSE 8080
ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar /app/app.jar"]
+31
View File
@@ -0,0 +1,31 @@
services:
db:
image: postgres
restart: unless-stopped
environment:
POSTGRES_DB: listhub
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
listhub_backend:
build: .
restart: unless-stopped
depends_on:
- db
environment:
DB_URL: jdbc:postgresql://db:5432/listhub
DB_USER: postgres
DB_PASS: postgres
JWT_SECRET: awdpokawodjawoidjawidjoij120391829d3j8a0jd8s9dawd
ports:
- "8080:8080"
volumes:
- listhub_data:/app
volumes:
postgres_data:
listhub_data:
+20 -2
View File
@@ -27,7 +27,7 @@
<url/> <url/>
</scm> </scm>
<properties> <properties>
<java.version>25</java.version> <java.version>21</java.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
@@ -70,7 +70,8 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<scope>provided</scope> <version>1.18.30</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@@ -120,6 +121,23 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
<!-- Ensure Lombok annotation processing during Maven compile inside Docker -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
@@ -14,7 +14,7 @@ public class ArtisanConnectBackendApplication {
this.environment = environment; this.environment = environment;
} }
static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ArtisanConnectBackendApplication.class, args); SpringApplication.run(ArtisanConnectBackendApplication.class, args);
} }