setup prod deploy with db
This commit is contained in:
30
Dockerfile
30
Dockerfile
@@ -1 +1,29 @@
|
|||||||
# TODO
|
# 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"]
|
||||||
@@ -1 +1,22 @@
|
|||||||
# TODO
|
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"
|
||||||
|
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -33,6 +33,10 @@
|
|||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user