-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marcus Fihlon <[email protected]>
- Loading branch information
Showing
1 changed file
with
17 additions
and
20 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,36 +1,33 @@ | ||
# Stage that builds the application, a prerequisite for the running stage | ||
FROM maven:3-openjdk-21-slim AS build | ||
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - | ||
RUN apt-get update -qq \ | ||
&& apt-get install -y -qq --no-install-recommends nodejs \ | ||
&& apt-get clean | ||
FROM eclipse-temurin:21 AS build | ||
|
||
# Stop running as root at this point | ||
RUN useradd -m myuser | ||
RUN useradd -m apus | ||
WORKDIR /usr/src/app/ | ||
RUN chown myuser:myuser /usr/src/app/ | ||
USER myuser | ||
RUN chown apus:apus /usr/src/app/ | ||
USER apus | ||
|
||
# Copy pom.xml and prefetch dependencies so a repeated build can continue from the next step with existing dependencies | ||
COPY --chown=myuser pom.xml ./ | ||
RUN mvn dependency:go-offline -Pproduction | ||
COPY --chown=apus pom.xml ./ | ||
COPY --chown=apus mvnw ./ | ||
COPY --chown=apus .mvn .mvn | ||
RUN ./mvnw dependency:go-offline -Pproduction | ||
|
||
# Copy all needed project files to a folder | ||
COPY --chown=myuser:myuser src src | ||
COPY --chown=myuser:myuser frontend frontend | ||
COPY --chown=myuser:myuser package.json ./ | ||
|
||
# Using * after the files that are autogenerated so that so build won't fail if they are not yet created | ||
COPY --chown=myuser:myuser package-lock.json* pnpm-lock.yaml* webpack.config.js* ./ | ||
COPY --chown=apus:apus src src | ||
COPY --chown=apus:apus frontend frontend | ||
COPY --chown=apus:apus package.json ./ | ||
|
||
# Using * after the files that are autogenerated so that the build won't fail if they are not yet created | ||
COPY --chown=apus:apus package-lock.json* pnpm-lock.yaml* webpack.config.js* ./ | ||
|
||
# Build the production package, assuming that we validated the version before so no need for running tests again | ||
RUN mvn clean package -DskipTests -Pproduction | ||
RUN ./mvnw clean package -DskipTests -Dcheckstyle.skip -Pproduction | ||
|
||
# Running stage: the part that is used for running the application | ||
FROM openjdk:21-jdk-slim | ||
FROM eclipse-temurin:21 | ||
COPY --from=build /usr/src/app/target/*.jar /usr/app/app.jar | ||
RUN useradd -m myuser | ||
USER myuser | ||
RUN useradd -m apus | ||
USER apus | ||
EXPOSE 8080 | ||
CMD java -jar /usr/app/app.jar |