Skip to content

Commit 228b058

Browse files
committed
Fix Dockerfile for k8s mvnw Not Found Error , Optimize Image Size with Multi-Stage Build and SERVER_HOST
1 parent a133cdc commit 228b058

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

k8s/docker/Dockerfile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
1-
FROM eclipse-temurin:17-jdk
1+
# Build Stage
2+
FROM eclipse-temurin:17-jdk AS build
23
MAINTAINER daynnnnn
34

5+
# Setting environment variables
46
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
57

8+
# Arguments for database configuration
69
ARG DB_HOST
710
ARG DB_USERNAME
811
ARG DB_PASSWORD
912
ARG DB_DATABASE
1013
ARG DB_PORT
1114

15+
# Set the working directory for the build stage
1216
WORKDIR /code
1317

18+
# Copy project files to the build stage
1419
ADD /src /code/src
1520
ADD /website /code/website
1621
ADD /pom.xml /code/pom.xml
22+
ADD mvnw /code/mvnw
23+
ADD .mvn /code/.mvn
1724

25+
# Replace placeholders in pom.xml with actual environment values
1826
RUN sed -i 's|${db.ip}|${env.DB_HOST}|g' pom.xml
1927
RUN sed -i 's|${db.port}|${env.DB_PORT}|g' pom.xml
2028
RUN sed -i 's|${db.user}|${env.DB_USERNAME}|g' pom.xml
2129
RUN sed -i 's|${db.password}|${env.DB_PASSWORD}|g' pom.xml
2230
RUN sed -i 's|${db.schema}|${env.DB_DATABASE}|g' pom.xml
31+
RUN sed -i 's|${server.host}|${env.SERVER_HOST}|g' pom.xml
2332

33+
# Make the Maven wrapper executable
34+
RUN chmod +x mvnw
35+
36+
# Build the project
2437
RUN ./mvnw clean package -Pkubernetes -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"
2538

26-
CMD java -jar target/steve.jar
39+
# Release Stage
40+
FROM eclipse-temurin:17-jdk AS release
41+
42+
# Copy only the generated jar file from the build stage
43+
COPY --from=build /code/target /app
44+
45+
# Expose any necessary ports (example: 8080)
46+
EXPOSE 8080
2747

48+
# Define the entrypoint for the release stage
49+
CMD ["java", "-jar", "/app/steve.jar"]

0 commit comments

Comments
 (0)