Skip to content

Commit 1c545fd

Browse files
authored
Merge pull request #1611 from MingShyanWei/master
Fix Dockerfile for k8s mvnw Not Found Error , Optimize Image Size with Multi-Stage Build and SERVER_HOST
2 parents 0ea9f6f + 833cc08 commit 1c545fd

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

k8s/docker/Dockerfile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
1-
FROM eclipse-temurin:17-jdk
1+
FROM eclipse-temurin:21-jdk AS base
22
MAINTAINER daynnnnn
33

4+
# Setting environment variables
45
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
56

7+
# Arguments for database configuration
68
ARG DB_HOST
79
ARG DB_USERNAME
810
ARG DB_PASSWORD
911
ARG DB_DATABASE
1012
ARG DB_PORT
1113

14+
# Build Stage
15+
FROM base as build
16+
17+
# Set the working directory for the build stage
1218
WORKDIR /code
1319

20+
# Copy project files to the build stage
1421
ADD /src /code/src
1522
ADD /website /code/website
1623
ADD /pom.xml /code/pom.xml
24+
ADD mvnw /code/mvnw
25+
ADD .mvn /code/.mvn
1726

27+
# Replace placeholders in pom.xml with actual environment values
1828
RUN sed -i 's|${db.ip}|${env.DB_HOST}|g' pom.xml
1929
RUN sed -i 's|${db.port}|${env.DB_PORT}|g' pom.xml
2030
RUN sed -i 's|${db.user}|${env.DB_USERNAME}|g' pom.xml
2131
RUN sed -i 's|${db.password}|${env.DB_PASSWORD}|g' pom.xml
2232
RUN sed -i 's|${db.schema}|${env.DB_DATABASE}|g' pom.xml
33+
RUN sed -i 's|${server.host}|${env.SERVER_HOST}|g' pom.xml
34+
35+
# Make the Maven wrapper executable
36+
RUN chmod +x mvnw
2337

38+
# Build the project
2439
RUN ./mvnw clean package -Pkubernetes -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"
2540

26-
CMD java -jar target/steve.jar
41+
# Release Stage
42+
FROM base AS release
43+
44+
# Copy relevant files from the build stage
45+
COPY --from=build /code/target/steve.jar /app/steve.jar
46+
COPY --from=build /code/target/libs /app/libs
47+
48+
# Expose any necessary ports (example: 8080)
49+
EXPOSE 8080
2750

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

k8s/yaml/Deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
value: ""
2929
- name: DB_DATABASE
3030
value: ""
31+
- name: SERVER_HOST
32+
value: "0.0.0.0"
3133
- name: ADMIN_USERNAME
3234
value: ""
3335
- name: ADMIN_PASSWORD

0 commit comments

Comments
 (0)