mirror of
https://github.com/won-ktds/smarketing-backend.git
synced 2025-12-06 07:06:24 +00:00
Update Dockerfile
This commit is contained in:
parent
1c461f65f4
commit
42c071fbf0
@ -1,17 +1,11 @@
|
|||||||
# Multi-stage build for Spring Boot application
|
# Build stage
|
||||||
FROM gradle:8.13-jdk17 AS builder
|
FROM eclipse-temurin:17-jre AS builder
|
||||||
|
|
||||||
# Build arguments
|
|
||||||
ARG BUILD_LIB_DIR
|
ARG BUILD_LIB_DIR
|
||||||
ARG ARTIFACTORY_FILE
|
ARG ARTIFACTORY_FILE
|
||||||
|
|
||||||
WORKDIR /app
|
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
|
COPY ${BUILD_LIB_DIR}/${ARTIFACTORY_FILE} app.jar
|
||||||
|
|
||||||
# Runtime stage
|
# Run stage
|
||||||
FROM eclipse-temurin:17-jre
|
FROM eclipse-temurin:17-jre
|
||||||
|
|
||||||
# Install necessary packages
|
# Install necessary packages
|
||||||
@ -20,22 +14,25 @@ RUN apt-get update && apt-get install -y \
|
|||||||
netcat-traditional \
|
netcat-traditional \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Create non-root user
|
ENV USERNAME k8s
|
||||||
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
ENV ARTIFACTORY_HOME /home/${USERNAME}
|
||||||
|
ENV JAVA_OPTS=""
|
||||||
|
|
||||||
# Set working directory
|
# Add a non-root user
|
||||||
WORKDIR /app
|
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 JAR from builder stage
|
||||||
COPY --from=builder /app/app.jar app.jar
|
COPY --from=builder /app/app.jar app.jar
|
||||||
|
RUN chown ${USERNAME}:${USERNAME} app.jar
|
||||||
# Change ownership
|
|
||||||
RUN chown -R appuser:appuser /app
|
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER appuser
|
USER ${USERNAME}
|
||||||
|
|
||||||
# Expose port (will be overridden by environment variables)
|
# Expose port
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Health check
|
# 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
|
CMD curl -f http://localhost:8080/actuator/health || exit 1
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
ENTRYPOINT ["sh", "-c"]
|
||||||
|
CMD ["java ${JAVA_OPTS} -jar app.jar"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user