From e97864a2518a4de76773ce7e8755e389462cea71 Mon Sep 17 00:00:00 2001 From: Urban Modig Date: Fri, 12 Sep 2025 13:10:48 +0200 Subject: [PATCH] Docker --- .dockerignore | 8 ++++++++ Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0c7d89e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +target/ +.git/ +.gitignore +.idea/ +.vscode/ +**/*.iml +secrets/ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..110898a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# -------- Build stage -------- +FROM maven:3.9.9-eclipse-temurin-21 AS build +WORKDIR /app + +# Cache dependencies +COPY pom.xml . +RUN mvn -q -DskipTests dependency:go-offline + +# Build +COPY src ./src +RUN mvn -q -DskipTests package + +# -------- Runtime stage -------- +FROM eclipse-temurin:21-jre-jammy + +# Timezone & JVM defaults +ENV TZ=Europe/Stockholm +# Ensure JVM uses Stockholm time regardless of container TZ config +ENV JAVA_TOOL_OPTIONS="-Duser.timezone=Europe/Stockholm" +# Sensible container-aware memory settings (tweak as you like) +ENV JAVA_OPTS="-XX:MaxRAMPercentage=75" + +# Non-root user +RUN useradd -ms /bin/bash spring +WORKDIR /app +COPY --from=build /app/target/electricityalert-*.jar /app/app.jar +RUN chown -R spring:spring /app +USER spring + +# App port +EXPOSE 8080 + +# Spring profile can be overridden at runtime: -e SPRING_PROFILES_ACTIVE=prod +ENV SPRING_PROFILES_ACTIVE=prod + +# Pass secrets as env vars (see your application.properties) +# -e TELEGRAM_BOT_TOKEN=... -e TELEGRAM_CHAT_ID=... -e GRAPHQL_ACCESS_TOKEN=... +ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar /app/app.jar"]