Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dockerfile for k8s mvnw Not Found Error , Optimize Image Size with Multi-Stage Build and SERVER_HOST #1611

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions k8s/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fixed directly into the sources


# 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"]
2 changes: 2 additions & 0 deletions k8s/yaml/Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down