update build scripts

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2024-10-16 21:57:26 +02:00
parent 837d10a1b9
commit 3ea693a76a
2 changed files with 32 additions and 23 deletions

View File

@@ -1,35 +1,30 @@
FROM maven:3-eclipse-temurin-21-jammy AS build
# Stage that builds the application, a prerequisite for the running stage
FROM eclipse-temurin:21-jdk-noble 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
RUN apt-get update -qq
# Stop running as root at this point
RUN useradd -m vaadin
RUN useradd -m app
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 ./
RUN chown app:app /usr/src/app/
USER app
# Copy all needed project files to a folder
COPY --chown=vaadin:vaadin src src
COPY --chown=app ./.mvn/ .mvn
COPY --chown=app ./mvnw ./pom.xml ./app.json ./
COPY --chown=app ./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
# Build the production package
RUN ./mvnw --batch-mode clean verify -DskipTests
# 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/website.jar
FROM eclipse-temurin:21-jre-noble
RUN useradd -m vaadin
USER vaadin
RUN useradd -m app
USER app
COPY --chown=app --from=build /usr/src/app/target/*.jar /usr/app/website.jar
HEALTHCHECK CMD curl --fail http://localhost:5000/actuator/health/liveness || exit 1
EXPOSE 8080
CMD ["java", "-jar", "/usr/app/website.jar"]

14
app.json Normal file
View File

@@ -0,0 +1,14 @@
{
"healthchecks": {
"web": [
{
"type": "readiness",
"name": "web check",
"description": "Checking if the app responds to the /actuator/health/readiness endpoint",
"path": "/actuator/health/readiness",
"port": 5000,
"attempts": 3
}
]
}
}