URL-4 Added Dockerfiles for all Services
This commit is contained in:
54
services/shortener-service/Dockerfile
Normal file
54
services/shortener-service/Dockerfile
Normal file
@@ -0,0 +1,54 @@
|
||||
# Build stage
|
||||
FROM gradle:8.10.1-jdk21 AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Gradle wrapper and build files for dependency caching
|
||||
COPY gradle/ gradle/
|
||||
COPY gradlew gradlew.bat ./
|
||||
COPY build.gradle settings.gradle ./
|
||||
|
||||
# Copy source code
|
||||
COPY services/shortener-service/build.gradle ./services/shortener-service/
|
||||
COPY services/shortener-service/src ./services/shortener-service/src/
|
||||
|
||||
# Build the application
|
||||
RUN chmod +x gradlew
|
||||
RUN ./gradlew :services:shortener-service:bootJar --no-daemon
|
||||
|
||||
# Runtime stage
|
||||
FROM eclipse-temurin:21-jre-jammy AS runtime
|
||||
|
||||
# Install curl for health checks (minimal size impact)
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create non-root user
|
||||
RUN groupadd -r spring && useradd -r -g spring spring
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the JAR from build stage
|
||||
COPY --from=build /app/services/shortener-service/build/libs/*.jar app.jar
|
||||
|
||||
# Change ownership to non-root user
|
||||
RUN chown spring:spring app.jar
|
||||
|
||||
# Switch to non-root user
|
||||
USER spring:spring
|
||||
|
||||
# Expose application port
|
||||
EXPOSE 8080
|
||||
|
||||
# Health check for Kubernetes (can be overridden by K8s probes)
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/actuator/health || exit 1
|
||||
|
||||
# Optimize JVM for containers
|
||||
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -XX:+UseG1GC"
|
||||
|
||||
# Run the application
|
||||
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
|
||||
|
||||
Reference in New Issue
Block a user