-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
82 lines (63 loc) · 2.3 KB
/
Dockerfile
File metadata and controls
82 lines (63 loc) · 2.3 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
FROM eclipse-temurin:25.0.2_10-jre
LABEL maintainer="dedicatedcode"
LABEL org.opencontainers.image.source="https://github.com/dedicatedcode/paikka"
LABEL org.opencontainers.image.description="Paikka - a specialized reverse geocoding service designed to provide high-performance location resolution"
LABEL org.opencontainers.image.licenses="MIT"
# Create a non-root user and group
RUN userdel ubuntu
RUN adduser paikka --uid 1000
# add osmium-tool and other needed applications
RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get -yq install osmium-tool wget util-linux
# Set environment variables
ENV SPRING_PROFILES_ACTIVE=docker
ENV APP_HOME=/app
ENV DATA_DIR=/data
ENV STATS_DIR=/stats
# Create application directory
RUN mkdir -p $APP_HOME && \
chown -R paikka:paikka $APP_HOME
WORKDIR $APP_HOME
# Copy the application jar
COPY --chown=paikka:paikka target/*.jar $APP_HOME/app.jar
COPY scripts/* $APP_HOME/
RUN ln -s $APP_HOME/filter_osm.sh /usr/bin/prepare
RUN ln -s $APP_HOME/import.sh /usr/bin/import
RUN chmod +x /usr/bin/prepare
RUN chmod +x /usr/bin/import
# 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 paikka user/group to UID:$APP_UID / GID:$APP_GID"
groupmod -g $APP_GID paikka
usermod -u $APP_UID paikka
chown -R paikka:paikka $APP_HOME
fi
mkdir -p $DATA_DIR
chown -R paikka:paikka $DATA_DIR
mkdir -p $STATS_DIR
chown -R paikka:paikka $STATS_DIR
# Switch to data directory
cd $DATA_DIR
# Check if the first argument is a known script
if [ "$1" = "prepare" ]; then
echo "Running script: $1"
shift
exec runuser -u paikka -- prepare "$@"
elif [ "$1" = "import" ]; then
echo "Running script: $1"
shift
exec runuser -u paikka -- import --jar-file "$APP_HOME/app.jar" "$@"
fi
# Default: Execute the Java application
exec runuser -u paikka -- 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=20 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
# Run as root initially to allow UID/GID changes
USER root
ENTRYPOINT ["/entrypoint.sh"]