77# Railway Interlocking Simulator
88#
99# Dockerization: 2025
10+ # Optimized: 2026-01 (BuildKit cache mounts, layer optimization)
1011#
1112# Multi-stage build for interlockSim with GUI support
1213# Dependency management: Apache Ivy
1314#
1415
16+ # syntax=docker/dockerfile:1.4
17+
18+ # ============================================
19+ # Stage 1: Reference pre-built jDisco image
20+ # ============================================
21+ # Build jdisco separately: docker compose build jdisco
22+ # This avoids duplicating jdisco/Dockerfile logic here
23+ FROM jdisco:latest AS jdisco-builder
24+
1525# ============================================
16- # Stage 1 : Build with JDK 6 and Ant
26+ # Stage 2 : Build interlockSim
1727# ============================================
1828FROM debian:buster-slim AS builder
1929
20- # Debian Buster is archived - update sources to use archive.debian.org
30+ # Debian Buster is archived - update sources
2131RUN sed -i 's|http://deb.debian.org|http://archive.debian.org|g' /etc/apt/sources.list && \
2232 sed -i 's|http://security.debian.org|http://archive.debian.org|g' /etc/apt/sources.list && \
2333 sed -i '/buster-updates/d' /etc/apt/sources.list
2434
25- # Install OpenJDK 11, Maven, wget, and unzip
35+ # Install build tools
2636RUN apt-get update && apt-get install -y \
2737 openjdk-11-jdk \
28- maven \
2938 wget \
3039 unzip \
3140 && rm -rf /var/lib/apt/lists/*
3241
33- # Set Java 11 as default but configure compiler for Java 6 compatibility
3442ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
3543ENV PATH=$JAVA_HOME/bin:$PATH
3644
37- # Install Apache Ant 1.10.14 (required for junitlauncher task)
45+ # Install Apache Ant 1.10.14
3846RUN wget -q https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.14-bin.zip && \
3947 unzip -q apache-ant-1.10.14-bin.zip && \
4048 mv apache-ant-1.10.14 /opt/ant && \
@@ -43,23 +51,30 @@ RUN wget -q https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.14-bin.
4351ENV ANT_HOME=/opt/ant
4452ENV PATH=$ANT_HOME/bin:$PATH
4553
46- # Build jDisco dependency first
47- WORKDIR /build/jdisco
48- COPY jdisco/ /build/jdisco/
49- RUN mvn clean install
50-
51- # Then build interlockSim
5254WORKDIR /build/interlockSim
5355
54- # Copy source files and build configuration
55- COPY src/ /build/interlockSim/src/
56+ # Copy jDisco from previous stage
57+ COPY --from=jdisco-builder /root/.m2/repository/ /root/.m2/repository/
58+
59+ # Layer 1: Copy ONLY dependency metadata files
60+ # This layer caches unless these files change
5661COPY build.xml /build/interlockSim/
5762COPY ivy.xml /build/interlockSim/
5863COPY ivysettings.xml /build/interlockSim/
5964
60- # Build the project (compiles code, runs tests)
61- # Ivy downloads dependencies automatically during resolve phase
62- RUN ant clean build
65+ # Layer 2: Resolve Ivy dependencies with BuildKit cache mount
66+ # This layer caches dependencies across builds
67+ RUN --mount=type=cache,target=/root/.ivy2 \
68+ ant resolve
69+
70+ # Layer 3: Copy source code
71+ # This is the layer that changes most frequently
72+ COPY src/ /build/interlockSim/src/
73+
74+ # Layer 4: Build and test
75+ # Ivy cache persists, so no re-downloads
76+ RUN --mount=type=cache,target=/root/.ivy2 \
77+ ant clean build
6378
6479# Create JAR with manifest
6580RUN ant pack
@@ -70,7 +85,7 @@ RUN ls -lh /build/interlockSim/jar/interlockSim.jar && \
7085 jar tf /build/interlockSim/jar/interlockSim.jar | head -20
7186
7287# ============================================
73- # Stage 2 : Runtime with JRE and X11 support
88+ # Stage 3 : Runtime with JRE and X11 support
7489# ============================================
7590FROM debian:buster-slim AS runner
7691
0 commit comments