# OpenRailRouting - Railway routing engine based on GraphHopper
# Build from source since no official Docker image exists

FROM maven:3.9-eclipse-temurin-21 AS builder

# Install Node.js for frontend build
RUN apt-get update && apt-get install -y --no-install-recommends \
    nodejs npm \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /build

# Clone and build OpenRailRouting
RUN git clone --depth 1 https://github.com/geofabrik/OpenRailRouting.git . && \
    git submodule update --init --recursive && \
    mvn clean package -DskipTests -q

# Runtime image
FROM eclipse-temurin:21-jre

WORKDIR /app

# Install curl for healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
    rm -rf /var/lib/apt/lists/*

# Copy built JAR (shaded uber-jar)
COPY --from=builder /build/target/railway_routing-1.0.0.jar /app/railway_routing.jar

# Create data directory
RUN mkdir -p /data

VOLUME /data

EXPOSE 8988

ENTRYPOINT ["java", "-jar", "/app/railway_routing.jar"]
CMD ["serve", "/app/config.yml"]
