Release / build (push) Successful in 4m45s
A redeploy no longer ends the games in progress. The server writes the open rooms (players, tokens, host, and each game as its seed and moves) to $DATA_DIR/rooms.json every few seconds when something changed and once more on shutdown (SIGTERM via Ktor's shutdown hook), and loads them before it accepts connections. Clients reconnect with their saved token and get the same table back; bots wait 30 s for them after a restart. Saves older than 10 minutes are ignored, and a game the new rules cannot replay leaves the room in the lobby. The image sets DATA_DIR=/data (owned by the bela user) and the compose file mounts the bela-data named volume on it. Also fixes a flaky test: the guest ignored its first table, so the game waited forever whenever the random dealer made the guest call first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.9 KiB
Docker
62 lines
2.9 KiB
Docker
# Single Bela image: builds the web app (Kotlin/Wasm) and the game server (Ktor), then ships one runtime
|
|
# container where the server runs the online rooms (WebSocket /ws) and serves the web app at /.
|
|
# Build context is the repo root. The Android app is not built here (-PbelaNoAndroid=true).
|
|
|
|
# ---- 1. Build the web bundle and the server ----
|
|
FROM eclipse-temurin:21-jdk-noble AS build
|
|
# Kotlin/Wasm downloads its own Node.js for webpack; Node needs libatomic.
|
|
RUN apt-get update && apt-get install -y --no-install-recommends libatomic1 && rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /src
|
|
ENV GRADLE_OPTS="-Dorg.gradle.daemon=false" \
|
|
BELA_GRADLE_FLAGS="-PbelaNoAndroid=true --no-configuration-cache"
|
|
|
|
# Wrapper and build scripts first: the Gradle distribution, plugins and dependencies are a cached layer
|
|
# that survives source-only changes.
|
|
COPY gradlew settings.gradle.kts build.gradle.kts gradle.properties ./
|
|
COPY gradle ./gradle
|
|
COPY engine/build.gradle.kts engine/
|
|
COPY shared/build.gradle.kts shared/
|
|
COPY web/build.gradle.kts web/
|
|
COPY server/build.gradle.kts server/
|
|
RUN chmod +x gradlew && ./gradlew $BELA_GRADLE_FLAGS help
|
|
|
|
COPY . .
|
|
# The wrapper may arrive without its executable bit (a checkout on Windows).
|
|
RUN chmod +x gradlew
|
|
# The commit count numbers the release like the Android app (0.1.2 = commit 12); CI passes it in because
|
|
# .git is not part of the build context.
|
|
ARG BELA_VERSION_CODE=1
|
|
RUN ./gradlew $BELA_GRADLE_FLAGS -PbelaVersionCode=$BELA_VERSION_CODE \
|
|
:engine:jvmTest :server:test :web:wasmJsBrowserDistribution :server:installDist \
|
|
# Pre-compressed copies: the server sends the .gz to browsers that accept it (the wasm shrinks ~3x).
|
|
&& find web/build/dist/wasmJs/productionExecutable -type f \
|
|
\( -name '*.wasm' -o -name '*.js' -o -name '*.mjs' -o -name '*.html' -o -name '*.webmanifest' -o -name '*.ttf' \) \
|
|
-exec gzip -9 -k {} \;
|
|
|
|
# ---- 2. Runtime ----
|
|
FROM eclipse-temurin:21-jre-noble AS runtime
|
|
# Latest OS security patches on top of the base image. OS_PATCHES (the build date, from CI) re-runs this
|
|
# layer daily, so a CVE fixed upstream does not linger in a cached layer.
|
|
ARG OS_PATCHES=0
|
|
RUN echo "OS patches as of ${OS_PATCHES}" \
|
|
&& apt-get update \
|
|
&& apt-get upgrade -y \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& useradd --system --uid 10001 --no-create-home bela \
|
|
# The open rooms are saved here across restarts; mount a volume on it (docker-compose.yml) to keep them.
|
|
&& mkdir /data && chown bela:bela /data
|
|
|
|
WORKDIR /app
|
|
COPY --from=build /src/server/build/install/server ./server
|
|
COPY --from=build /src/web/build/dist/wasmJs/productionExecutable ./web
|
|
|
|
ENV PORT=8080 \
|
|
WEB_ROOT=/app/web \
|
|
DATA_DIR=/data \
|
|
JAVA_OPTS="-XX:MaxRAMPercentage=75 -XX:+UseSerialGC -XX:+ExitOnOutOfMemoryError"
|
|
USER bela
|
|
EXPOSE 8080
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
|
CMD curl -fsS http://localhost:8080/health || exit 1
|
|
ENTRYPOINT ["/app/server/bin/server"]
|