dockerfile
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
# Multi-stage build for Spring Boot application
|
||||
FROM maven:3.9.6-openjdk-21-slim AS build
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy pom.xml and download dependencies
|
||||
COPY pom.xml .
|
||||
RUN mvn dependency:go-offline -B
|
||||
|
||||
# Copy source code
|
||||
COPY src ./src
|
||||
|
||||
# Build the application
|
||||
RUN mvn clean package -DskipTests
|
||||
|
||||
# Runtime stage
|
||||
FROM openjdk:21-jre-slim
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Create non-root user for security
|
||||
RUN groupadd -r konturai && useradd -r -g konturai konturai
|
||||
|
||||
# Install necessary packages
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the JAR file from build stage
|
||||
COPY --from=build /app/target/konturai-*.jar app.jar
|
||||
|
||||
# Change ownership to non-root user
|
||||
RUN chown konturai:konturai app.jar
|
||||
|
||||
# Switch to non-root user
|
||||
USER konturai
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8080
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/actuator/health || exit 1
|
||||
|
||||
# Set JVM options for containerized environment
|
||||
ENV JAVA_OPTS="-Xmx512m -Xms256m -XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
|
||||
|
||||
# Run the application
|
||||
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
|
||||
Reference in New Issue
Block a user