Skip to content

Commit

Permalink
Merge pull request #1218 from styk-tv/dockerfile-fix-oct24
Browse files Browse the repository at this point in the history
dockerfile - fixed pom location error - reduced image size by close to 2/3
  • Loading branch information
jamesaoverton authored Oct 10, 2024
2 parents 148c92b + 13a89c9 commit 633404c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
33 changes: 27 additions & 6 deletions Dockerfile
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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Other build options:
- `mvn clean verify` rebuilds the package and runs integration tests against it, with reports in `[module]/target/failsafe-reports`
- `mvn site` generates Javadoc in `target/site` and `[module]/target/site`

Alternatively, you can use [Docker](https://www.docker.com) with the provided [Dockerfile](Dockerfile) to build and run ROBOT from within a container. First build an image with `docker build --tag robot .` then run ROBOT from the container with the usual command-line arguments: `docker run --rm robot --help`.
Alternatively, you can use [Docker](https://www.docker.com) with the provided [Dockerfile](Dockerfile) to build and run ROBOT from within a container. First build an image with `docker build --tag robot:latest .` then run ROBOT from the container with the usual command-line arguments: `docker run --rm robot --help`.


## Code Style
Expand Down

0 comments on commit 633404c

Please sign in to comment.