-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1218 from styk-tv/dockerfile-fix-oct24
dockerfile - fixed pom location error - reduced image size by close to 2/3
- Loading branch information
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
FROM maven:3-openjdk-11-slim | ||
# Stage 1: Build the application using Maven | ||
FROM maven:3-openjdk-11-slim AS build | ||
|
||
# Create a working directory and set permissions | ||
RUN useradd -m robot | ||
RUN mkdir -p /usr/src/app | ||
RUN chown robot /usr/src/app | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Copy the POM and source code to the working directory | ||
COPY pom.xml /usr/src/app | ||
COPY robot-command /usr/src/app/robot-command | ||
COPY robot-core /usr/src/app/robot-core | ||
COPY robot-maven-plugin /usr/src/app/robot-maven-plugin | ||
COPY bin/robot /usr/local/bin/ | ||
COPY robot-mock-plugin /usr/src/app/robot-mock-plugin | ||
|
||
# Change ownership to robot user | ||
RUN chown -R robot:robot /usr/src/app | ||
|
||
# Use the robot user to run Maven | ||
USER robot | ||
WORKDIR /usr/src/app | ||
|
||
# Run the Maven build, skipping tests to speed up the process | ||
RUN mvn install -DskipTests | ||
|
||
USER root | ||
RUN cp bin/robot.jar /usr/local/bin | ||
# Stage 2: Create a smaller runtime container | ||
FROM openjdk:11-jre-slim AS runtime | ||
|
||
# Create a non-root user and set up a working directory | ||
RUN useradd -m robot | ||
RUN mkdir -p /usr/src/app/bin | ||
RUN chown robot /usr/src/app/bin | ||
|
||
# Copy the compiled JAR file from the build stage to the runtime stage | ||
COPY --from=build /usr/src/app/bin/robot.jar /usr/src/app/bin/robot.jar | ||
|
||
# Set robot as the user | ||
USER robot | ||
ENTRYPOINT ["robot"] | ||
|
||
# Set the entrypoint to run the robot.jar | ||
ENTRYPOINT ["java", "-jar", "/usr/src/app/bin/robot.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters