-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (44 loc) · 1.73 KB
/
Dockerfile
File metadata and controls
58 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
FROM eclipse-temurin:25-jre-alpine-3.22
LABEL maintainer="dedicatedcode"
LABEL org.opencontainers.image.source="https://github.com/dedicatedcode/reitti"
LABEL org.opencontainers.image.description="Reitti - Personal Location Tracking & Analysis"
LABEL org.opencontainers.image.licenses="MIT"
# Create a non-root user and group
RUN addgroup -S reitti -g 1000 && adduser -S reitti -u 1000 -G reitti
# Set environment variables
ENV SPRING_PROFILES_ACTIVE=docker
ENV APP_HOME=/app
ENV DATA_DIR=/data
# Create application directory
RUN mkdir -p $APP_HOME && \
chown -R reitti:reitti $APP_HOME
WORKDIR $APP_HOME
# Copy the application jar
COPY --chown=reitti:reitti target/*.jar $APP_HOME/app.jar
# Create a script to start the application with configurable UID/GID
RUN cat <<'EOF' > /entrypoint.sh
#!/bin/sh
if [ -n "$APP_UID" ] && [ -n "$APP_GID" ]; then
echo "Changing reitti user/group to UID:$APP_UID / GID:$APP_GID"
apk add --no-cache shadow
groupmod -g $APP_GID reitti
usermod -u $APP_UID reitti
chown -R reitti:reitti $APP_HOME
fi
mkdir -p $DATA_DIR
chown -R reitti:reitti $DATA_DIR
# Execute
exec su-exec reitti java $JAVA_OPTS -jar $APP_HOME/app.jar -Dspring.profiles.active=docker "$@"
EOF
RUN chmod +x /entrypoint.sh
# Expose the application port
EXPOSE 8080
# Add healthcheck
HEALTHCHECK --interval=5s --timeout=3s --start-period=1s --retries=5 \
CMD sh -c 'curl -f --max-time 2 "http://localhost:8080${BASE_PATH}/actuator/health" || (echo "Health check failed" && exit 1)'
# Install su-exec for proper user switching and wget for healthcheck
RUN apk add --no-cache su-exec curl attr
RUN setfattr -n user.pax.flags -v "mr" /opt/java/openjdk/bin/java
# Run as root initially to allow UID/GID changes
USER root
ENTRYPOINT ["/entrypoint.sh"]