From 228b0585e6ce445b8dbbd9c99ccfefe1ab033c13 Mon Sep 17 00:00:00 2001 From: caspar Date: Mon, 28 Oct 2024 13:46:04 +0800 Subject: [PATCH 1/2] Fix Dockerfile for k8s mvnw Not Found Error , Optimize Image Size with Multi-Stage Build and SERVER_HOST --- k8s/docker/Dockerfile | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/k8s/docker/Dockerfile b/k8s/docker/Dockerfile index a5e5965ac..0b664d540 100644 --- a/k8s/docker/Dockerfile +++ b/k8s/docker/Dockerfile @@ -1,27 +1,49 @@ -FROM eclipse-temurin:17-jdk +# Build Stage +FROM eclipse-temurin:17-jdk AS build MAINTAINER daynnnnn +# Setting environment variables ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 +# Arguments for database configuration ARG DB_HOST ARG DB_USERNAME ARG DB_PASSWORD ARG DB_DATABASE ARG DB_PORT +# Set the working directory for the build stage WORKDIR /code +# Copy project files to the build stage ADD /src /code/src ADD /website /code/website ADD /pom.xml /code/pom.xml +ADD mvnw /code/mvnw +ADD .mvn /code/.mvn +# Replace placeholders in pom.xml with actual environment values RUN sed -i 's|${db.ip}|${env.DB_HOST}|g' pom.xml RUN sed -i 's|${db.port}|${env.DB_PORT}|g' pom.xml RUN sed -i 's|${db.user}|${env.DB_USERNAME}|g' pom.xml RUN sed -i 's|${db.password}|${env.DB_PASSWORD}|g' pom.xml RUN sed -i 's|${db.schema}|${env.DB_DATABASE}|g' pom.xml +RUN sed -i 's|${server.host}|${env.SERVER_HOST}|g' pom.xml +# Make the Maven wrapper executable +RUN chmod +x mvnw + +# Build the project RUN ./mvnw clean package -Pkubernetes -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2" -CMD java -jar target/steve.jar +# Release Stage +FROM eclipse-temurin:17-jdk AS release + +# Copy only the generated jar file from the build stage +COPY --from=build /code/target /app + +# Expose any necessary ports (example: 8080) +EXPOSE 8080 +# Define the entrypoint for the release stage +CMD ["java", "-jar", "/app/steve.jar"] From 34e0aa3f9d1269bdc906c62606b224253daa893b Mon Sep 17 00:00:00 2001 From: caspar Date: Mon, 28 Oct 2024 14:02:46 +0800 Subject: [PATCH 2/2] Add SERVER_HOST to Deployment.yaml --- k8s/yaml/Deployment.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/k8s/yaml/Deployment.yaml b/k8s/yaml/Deployment.yaml index cf7be5386..9301b0c0f 100644 --- a/k8s/yaml/Deployment.yaml +++ b/k8s/yaml/Deployment.yaml @@ -28,6 +28,8 @@ spec: value: "" - name: DB_DATABASE value: "" + - name: SERVER_HOST + value: "0.0.0.0" - name: ADMIN_USERNAME value: "" - name: ADMIN_PASSWORD