This commit is contained in:
Urban Modig
2025-09-12 13:10:48 +02:00
parent 2a7fe41b0b
commit e97864a251
2 changed files with 46 additions and 0 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
target/
.git/
.gitignore
.idea/
.vscode/
**/*.iml
secrets/
.env

38
Dockerfile Normal file
View File

@ -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"]