Skip to content

Commit

Permalink
💚 fix building Apus using Docker
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Mar 29, 2024
1 parent 2eaa5fa commit 120a60e
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions Dockerfile
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

0 comments on commit 120a60e

Please sign in to comment.