2025-11-18 20:00:06 +05:30
|
|
|
FROM eclipse-temurin:25-jdk-alpine AS builder
|
|
|
|
|
WORKDIR /workspace
|
|
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
# Copy Maven wrapper and configuration files first for better layer caching
|
2025-11-18 20:00:06 +05:30
|
|
|
COPY mvnw .
|
|
|
|
|
COPY .mvn .mvn
|
|
|
|
|
COPY pom.xml .
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
|
|
|
|
|
# Download dependencies (this layer will be cached if pom.xml doesn't change)
|
|
|
|
|
RUN chmod +x mvnw && ./mvnw dependency:go-offline -B
|
|
|
|
|
|
|
|
|
|
# Copy source code
|
2025-11-18 20:00:06 +05:30
|
|
|
COPY src src
|
|
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
# Build the application
|
|
|
|
|
RUN ./mvnw -B -DskipTests package
|
2025-11-18 20:00:06 +05:30
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
FROM eclipse-temurin:17-jre-alpine
|
2025-11-18 20:00:06 +05:30
|
|
|
WORKDIR /app
|
|
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
# Install wget for healthcheck
|
|
|
|
|
RUN apk add --no-cache wget
|
|
|
|
|
|
|
|
|
|
# Create a non-root user for security
|
|
|
|
|
RUN addgroup -S spring && adduser -S spring -G spring
|
|
|
|
|
|
|
|
|
|
# Set environment variables
|
2025-11-18 20:00:06 +05:30
|
|
|
ENV SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-mysql}
|
|
|
|
|
ENV JAVA_OPTS=""
|
|
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
# Copy the JAR file from builder
|
2025-11-18 20:00:06 +05:30
|
|
|
COPY --from=builder /workspace/target/*.jar app.jar
|
|
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
# Change ownership to non-root user
|
|
|
|
|
RUN chown spring:spring app.jar
|
|
|
|
|
|
|
|
|
|
# Switch to non-root user
|
|
|
|
|
USER spring:spring
|
|
|
|
|
|
|
|
|
|
# Expose the application port
|
2025-11-18 20:00:06 +05:30
|
|
|
EXPOSE 8080
|
|
|
|
|
|
Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds
These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.
Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-14 10:49:10 +05:30
|
|
|
# Add healthcheck
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
|
|
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
|
|
|
|
|
|
|
|
|
|
# Use exec form for better signal handling
|
2025-11-18 20:00:06 +05:30
|
|
|
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
|
|
|
|
|
|