update dockerfile

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2024-05-27 23:35:13 +02:00
parent 9350ed6c25
commit 35ebc02877
6 changed files with 56 additions and 299 deletions

View File

@@ -1,4 +1,33 @@
FROM eclipse-temurin:21-jre
COPY target/*.jar app.jar
FROM maven:3-eclipse-temurin-21-jammy as build
# Install nodejs
RUN apt-get update
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install nodejs -y
# Stop running as root at this point
RUN useradd -m vaadin
WORKDIR /usr/src/app/
RUN chown vaadin:vaadin /usr/src/app/
USER vaadin
# Copy pom.xml and prefetch dependencies so a repeated build can continue from the next step with existing dependencies
COPY --chown=vaadin pom.xml ./
# Copy all needed project files to a folder
COPY --chown=vaadin:vaadin src src
# Build the production package, assuming that we validated the version before so no need for running tests again
RUN mvn clean package -DskipTests -Pproduction --batch-mode
# Running stage: the part that is used for running the application
FROM eclipse-temurin:21-jre-jammy
COPY --from=build /usr/src/app/target/*.jar /usr/app/app.jar
RUN useradd -m vaadin
USER vaadin
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
CMD java -jar /usr/app/app.jar