Update Dockerfile

This commit is contained in:
John Hanzu Kim 2025-06-17 09:36:09 +09:00 committed by GitHub
parent 1c461f65f4
commit 42c071fbf0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,17 +1,11 @@
# Multi-stage build for Spring Boot application
FROM gradle:8.13-jdk17 AS builder
# Build arguments
# Build stage
FROM eclipse-temurin:17-jre AS builder
ARG BUILD_LIB_DIR
ARG ARTIFACTORY_FILE
WORKDIR /app
# Copy source code (assumed to be already built)
# The JAR file should be copied from the build context
COPY ${BUILD_LIB_DIR}/${ARTIFACTORY_FILE} app.jar
# Runtime stage
# Run stage
FROM eclipse-temurin:17-jre
# Install necessary packages
@ -20,22 +14,25 @@ RUN apt-get update && apt-get install -y \
netcat-traditional \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser
ENV USERNAME k8s
ENV ARTIFACTORY_HOME /home/${USERNAME}
ENV JAVA_OPTS=""
# Set working directory
WORKDIR /app
# Add a non-root user
RUN groupadd -r ${USERNAME} && useradd -r -g ${USERNAME} ${USERNAME} && \
mkdir -p ${ARTIFACTORY_HOME} && \
chown ${USERNAME}:${USERNAME} ${ARTIFACTORY_HOME}
WORKDIR ${ARTIFACTORY_HOME}
# Copy JAR from builder stage
COPY --from=builder /app/app.jar app.jar
# Change ownership
RUN chown -R appuser:appuser /app
RUN chown ${USERNAME}:${USERNAME} app.jar
# Switch to non-root user
USER appuser
USER ${USERNAME}
# Expose port (will be overridden by environment variables)
# Expose port
EXPOSE 8080
# Health check
@ -43,4 +40,5 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
ENTRYPOINT ["sh", "-c"]
CMD ["java ${JAVA_OPTS} -jar app.jar"]