From 4a2838c208422a7c6488009b3e167d8d905aeed0 Mon Sep 17 00:00:00 2001 From: Ivo Spijkerman Date: Thu, 23 Oct 2025 19:26:21 +0200 Subject: [PATCH] setup prod deploy with db --- Dockerfile | 30 +++++++++++++++++++++++++++++- docker-compose.yaml | 23 ++++++++++++++++++++++- pom.xml | 4 ++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f87f5c1..581d892 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,29 @@ -# TODO \ No newline at end of file +# Stage 1: Build stage +FROM maven:3.9-eclipse-temurin-21 AS build + +# Set the working directory inside the container +WORKDIR /app + +# Copy the pom.xml and dependencies (helps in caching dependencies) +COPY pom.xml . + +# Download dependencies (this will cache dependencies in the Docker layer) +RUN mvn dependency:go-offline + +# Copy the rest of the application source code +COPY src ./src + +# Build the Spring Boot app +RUN mvn clean package + +# Stage 2: Run stage +FROM eclipse-temurin:21-jdk AS runtime + +# Copy the built JAR file from the build stage +COPY --from=build /app/target/*.jar /app/app.jar + +# Expose the default Spring Boot port +EXPOSE 8080 + +# Command to run the Spring Boot application +ENTRYPOINT ["java", "-jar", "/app/app.jar"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index f87f5c1..aacff28 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1 +1,22 @@ -# TODO \ No newline at end of file +services: + app: + build: . + ports: + - "8080:8080" + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/mydb + SPRING_DATASOURCE_USERNAME: myuser + SPRING_DATASOURCE_PASSWORD: mypassword + SPRING_JPA_HIBERNATE_DDL_AUTO: update # Automatically create/update DB schema + depends_on: + - db + + db: + image: postgres:15 + environment: + POSTGRES_DB: mydb + POSTGRES_USER: myuser + POSTGRES_PASSWORD: mypassword + ports: + - "5432:5432" + diff --git a/pom.xml b/pom.xml index bf6e3dc..41d8ffe 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,10 @@ com.h2database h2 + + org.postgresql + postgresql + org.projectlombok lombok