Files
romm/docker/Dockerfile
Georges-Antoine Assi c413c066c6 refactor(docker): supervise the container with s6-overlay (#4019)
* refactor(docker): supervise the container with s6-overlay

The init script was a hand-rolled supervisor: PID files, /proc polling, a
5s watchdog loop and a trap-based shutdown. Its shutdown wait was unbounded,
so a process that refused to exit stranded PID 1 and left the container up
and serving nothing, which no restart policy can detect.

s6-rc replaces it with a declared service graph. Ordering and readiness
gates that were sequential bash become dependencies, and the failure modes
become configuration:

- timeout-kill bounds SIGTERM before SIGKILL, and flag-timeout-killpg
  escalates to the whole process group.
- S6_BEHAVIOUR_IF_STAGE2_FAILS=2 exits the container when a startup step
  fails, so the restart policy retries instead of the container wedging.
- valkey gets --shutdown-on-sigterm force, so it stops refusing to exit
  when the snapshot it writes on shutdown cannot be written.

A crashed service is now restarted on its own instead of taking the whole
container down. Its leftover children are swept first, because children
reparented from a hard-killed master keep holding its listening sockets and
would make every replacement fail to bind.

Optional services have no conditional mechanism in s6-rc, so they start,
check their environment variable, and take themselves down with s6-svc -O.

Running with a read-only root filesystem now needs /run mounted exec, since
s6 executes its generated stage scripts from there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(docker): always start the RQ scheduler under s6

The s6 service carried over the four-flag ENABLE_SCHEDULED_* gate from the
init script, which #4033 has since removed on master. Since this branch
deletes that script, the fix would be lost on rebase.

Nothing else respects the condition: startup.py registers the netplay,
upload-tmp and zip-cache cleanups unconditionally, three more flags gate
periodic tasks absent from the list, and the watcher defers its rescans
through the scheduler. Any of those leaves jobs in the scheduler registry
with no process to run them, and a stuck delayed scan_platforms entry reads
to the concurrent scan guard as a scan already queued, refusing every
manual scan.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(docker): port master's init changes to the s6 services

Master reworked docker/init_scripts/init while this branch replaced it,
so carry those changes into the s6-rc services:

- Replace rq-scheduler with `rq cron` (romm-rq-cron) on tasks.cron_config.
- Add romm-rq-scan-worker (scans queue) and romm-rq-streaming-worker
  (streaming queue, down unless config.yml enables streaming).
- Run every worker with --with-scheduler and the RomMRedis connection
  class, passing the Redis URL through RQ_REDIS_URL so the password stays
  off the command line, and read REDIS_SSL as a boolean.
- Bring gunicorn's flags in line: --no-control-socket, a private-range
  FORWARDED_ALLOW_IPS default, 4 workers and a 65s keep-alive.
- Check the sync folder and SSH keys path in romm-init, and switch the
  features off through the container environment when they're unusable.
- Accept the backend's truthy values for the watcher flags.
- Point the serving-layer guard tests at the gunicorn run script and
  drop the PID-file tests, which guarded the bash watchdog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(docker): guard the s6-overlay service tree

Check that every service is in the user bundle, depends on something
that exists, and that every longrun has its finish sweep, kill timeout
and process-group flag. Also check that the dev entrypoint starts the
same RQ workers and cron scheduler as the image, since it keeps its own
launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(dev): pass the image's RQ flags in the dev entrypoint

The dev image's RQ cron scheduler and workers ran without the RomMRedis
connection class, and the workers without --results-ttl, so they kept
redis-py's maintenance notification probe and RQ's default result TTL.
The s6 guard test now compares each rq command's flags with the image's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(docker): address Greptile review on the s6 service tree

- Cut the s6 script comments to two lines, keeping the reason each
  helper exists.
- Compare the values of the dev entrypoint's RQ options with the
  image's, not only their names, allowing for the dev image's path,
  PID files and LOGLEVEL default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(docker): check every s6 service stays up after boot

The heartbeat only proves gunicorn and nginx came up. Enable both watchers
and require each longrun in the s6 tree to report up for 15s straight, so a
crashing or restart-looping worker, cron, valkey or watcher fails the job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(docker): enable streaming so its worker is checked too

The streaming worker turns itself off when streaming.enabled is false in
config.yml, which the services check read as a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-24 08:29:06 -05:00

436 lines
18 KiB
Docker

# syntax=docker/dockerfile:1
# Stages:
# - python-runtime: Patch the Python image's libraries before they ship
# - frontend-build: Build frontend
# - backend-build: Build backend environment
# - rahasher-build: Build RAHasher
# - sigil-build: Build sigil Python bindings (title ID extraction)
# - gme-build: Build libgme to WebAssembly (chiptune soundtracks)
# - rom-converto-fetch: Fetch the rom-converto CLI (ROM conversion and metadata)
# - s6-overlay-fetch: Fetch the s6-overlay process supervisor
# - emulator-stage: Fetch and extract emulators
# - nginx-build: Build nginx modules
# - production-stage: Setup frontend and backend
# - slim-image: Slim image with only the necessary files
# - full-image: Full image with emulator stage
# ARGUMENT DECLARATIONS
ARG ALPINE_VERSION=3.24
ARG ALPINE_DIGEST=sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
# Pins the base image tag, so it cannot read ../.python-version; keep the two in sync.
ARG PYTHON_VERSION=3.14
ARG PYTHON_ALPINE_DIGEST=sha256:5862d971d1f0ae26b258cefa4e893556b1d3aba81bd2ff30888704ad378bab67
# Build stages get pip from CPython's bundled ensurepip, which lags pip's security releases.
ARG PIP_VERSION=26.2.2
ARG NODE_VERSION=26.13
ARG NODE_ALPINE_DIGEST=sha256:6bd9ab43c0ec0190ca7b2d193906cb8b7edf6e7f4afa43ddeccd6452710bffb5
ARG NGINX_VERSION=1.30.7
ARG NGINX_SHA256=bef154735288bc38d99fac41ae63730684bcc661503673a04a0f9bc526ba8598
ARG UV_VERSION=0.13.4
ARG UV_SHA256=0cb69bb18ffcd57db04f045010b0234132a111da70dde5a393d26ad288d38e13
ARG EMSDK_VERSION=4.0.12
ARG EMSDK_AMD64_SHA256=744fb6a68941970951bacf9d6632041a0398260492232691ef22bbf54b0585c6
ARG EMSDK_ARM64_SHA256=369a4cb655aa1066e6e450dde774243c502d999b1d93fb4890a9d1428daa9280
ARG GME_VERSION=0.6.5
ARG GME_COMMIT=9e23d10f9fd2a6a2f33b10912dd8dc7153258995
ARG S6_OVERLAY_VERSION=3.2.3.2
ARG S6_OVERLAY_NOARCH_SHA256=5379750ed30a84bbd2e2dd74847ba6b5bd29cd0b2e3ea2ec58049b57eb2eda12
ARG S6_OVERLAY_X86_64_SHA256=e6befcc96a437a3831386ecfc51808c5d3e939dc5fe3c02ae9284599e8aa2408
ARG S6_OVERLAY_AARCH64_SHA256=b17f17a82e7a515c682a91edaf2ffdabb73f891981b6c1fd712115693a2f8b4c
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}@${PYTHON_ALPINE_DIGEST} AS python-alias
ARG PIP_VERSION
RUN pip install --no-cache-dir --upgrade pip==${PIP_VERSION}
# PATCHED PYTHON RUNTIME
# production-stage copies /usr/lib from here over its own, so these libraries
# need the same patches, or the stale ones land in the final image. Kept apart
# from python-alias so that busting this layer's cache (see `no-cache-filters`
# in build.yml) does not also rebuild the venv and the sigil bindings.
# The app uses a separate virtual environment at /src/.venv.
FROM python-alias AS python-runtime
ARG PYTHON_VERSION
RUN apk upgrade --no-cache && \
rm -rf /usr/local/bin/pip* /usr/local/lib/python${PYTHON_VERSION}/site-packages/pip*
# FRONTEND BUILD
# Built on the native build platform: the output (/front/dist) is static JS/CSS,
# fully architecture-independent, so there is no need to emulate the target arch.
FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-alpine${ALPINE_VERSION}@${NODE_ALPINE_DIGEST} AS frontend-build
WORKDIR /front
COPY ./frontend/package*.json ./
RUN npm ci --ignore-scripts --no-audit --no-fund
COPY ./frontend ./
RUN npm run build
# BACKEND NODE HELPERS BUILD (server-side ROM patching via RomPatcher.js)
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION}@${NODE_ALPINE_DIGEST} AS backend-node-build
WORKDIR /backend-node/rom_patcher
COPY ./backend/utils/rom_patcher/package*.json ./
RUN npm ci --ignore-scripts --no-audit --no-fund
# https://github.com/astral-sh/uv/pkgs/container/uv
FROM ghcr.io/astral-sh/uv:${UV_VERSION}-python${PYTHON_VERSION}-alpine@sha256:${UV_SHA256} AS uv-stage
# BACKEND PYTHON BUILD
FROM python-alias AS backend-build
# libpq-dev is needed to build psycopg-c
# mariadb-connector-c-dev is needed to build mariadb-connector
RUN apk add --no-cache \
gcc \
libpq-dev \
mariadb-connector-c-dev \
musl-dev
COPY --from=uv-stage /usr/local/bin/uv /usr/local/bin/uvx /bin/
WORKDIR /src
COPY ./pyproject.toml ./uv.lock /src/
# PYTHONDONTWRITEBYTECODE blocks caching at runtime, so ship compiled bytecode.
ENV UV_COMPILE_BYTECODE=1
RUN uv sync --frozen --no-cache
# CUSTOM RAHASHER FOR RETROACHIEVEMENTS
FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS rahasher-build
RUN apk add --no-cache \
g++ \
git \
linux-headers \
make \
zlib-dev \
bash
# Tag 1.8.3. Pinned by commit because a tag can be moved.
# Keep this pin in sync with the dev image's RALIBRETRO_COMMIT in ../Dockerfile.
ARG RALIBRETRO_COMMIT=8ab61f745ab753a70b5482f2a0ccb6a4ced5193f
RUN git clone --filter=blob:none https://github.com/RetroAchievements/RALibretro.git && \
cd ./RALibretro && \
git checkout "${RALIBRETRO_COMMIT}" && \
git submodule update --init --recursive && \
sed -i '22a #include <ctime>' ./src/Util.h && \
sed -i '6a #include <unistd.h>' \
./src/libchdr/deps/zlib-1.3.1/gzlib.c \
./src/libchdr/deps/zlib-1.3.1/gzread.c \
./src/libchdr/deps/zlib-1.3.1/gzwrite.c && \
make HAVE_CHD=1 -f ./Makefile.RAHasher
# SIGIL TITLE ID EXTRACTION LIBRARY
# Built from python-alias (not plain alpine) so the cffi extension matches the
# CPython ABI of the venv produced in backend-build.
FROM python-alias AS sigil-build
RUN apk add --no-cache \
cmake \
g++ \
make \
musl-dev
# Keep this pin in sync with the dev image's SIGIL_VERSION in ../Dockerfile.
ARG SIGIL_VERSION=85f88a85b7e8cfe5c685ec3cde100570c6ee6ed8
# checkov:skip=CKV_DOCKER_4:the ADD below is a Git URL pinned to a commit
ADD "https://github.com/rommapp/argosy-sigil.git#${SIGIL_VERSION}" /argosy-sigil
WORKDIR /argosy-sigil
RUN cmake -B ./build-python -S . -DSIGIL_BUILD_CLI=OFF -DSIGIL_BUILD_TESTS=OFF && \
cmake --build ./build-python --target sigil && \
pip install --no-cache-dir cffi setuptools && \
cd ./bindings/python && \
python build_sigil.py && \
mkdir /sigil-pkg && \
cp ./sigil/*.py ./sigil/_sigil.*.so /sigil-pkg/
# LIBGME (LGPL-2.1+) FOR CHIPTUNE SOUNDTRACKS
# The wasm is the same on every platform, so it builds with the builder's own
# emsdk image. Keep the pins in sync with the dev image's copies in ../Dockerfile.
# trunk-ignore(hadolint/DL3029)
FROM --platform=linux/amd64 emscripten/emsdk:${EMSDK_VERSION}@sha256:${EMSDK_AMD64_SHA256} AS emsdk-amd64
# trunk-ignore(hadolint/DL3029)
FROM --platform=linux/arm64 emscripten/emsdk:${EMSDK_VERSION}-arm64@sha256:${EMSDK_ARM64_SHA256} AS emsdk-arm64
# trunk-ignore(hadolint/DL3006,checkov/CKV_DOCKER_7)
FROM emsdk-${BUILDARCH} AS gme-build
ARG GME_VERSION
ARG GME_COMMIT
# checkov:skip=CKV_DOCKER_4:the ADD below is a Git URL pinned to a commit by --checksum
ADD --checksum=${GME_COMMIT} \
"https://github.com/libgme/game-music-emu.git#${GME_VERSION}" \
/libgme
COPY ./docker/gme /romm-gme
RUN /romm-gme/build.sh /libgme /gme
# ROM-CONVERTO CLI
# Keep the version and both sums in sync with the dev image's copy in ../Dockerfile.
FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS rom-converto-fetch
ARG TARGETARCH
ARG ROM_CONVERTO_VERSION=v0.24.0
RUN case "${TARGETARCH}" in \
amd64) rc="linux-x64-musl"; sum="67964054931f7e74848bfe7b54ff1f0cacdc25596c29e3a79876f76e0f2407a8" ;; \
arm64) rc="linux-arm64-musl"; sum="60f9dc0fe7c3e3355c840c5e21c2b65b770b74ba78567aec7a2e5f846b8087ce" ;; \
*) echo "unsupported TARGETARCH: ${TARGETARCH}" && exit 1 ;; \
esac && \
wget -qO /rom-converto \
"https://github.com/DevYukine/rom-converto/releases/download/${ROM_CONVERTO_VERSION}/rom-converto-cli-${rc}" && \
echo "${sum} /rom-converto" | sha256sum -c - && \
chmod 0755 /rom-converto
# S6-OVERLAY
FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS s6-overlay-fetch
ARG TARGETARCH
ARG S6_OVERLAY_VERSION
ARG S6_OVERLAY_NOARCH_SHA256
ARG S6_OVERLAY_X86_64_SHA256
ARG S6_OVERLAY_AARCH64_SHA256
RUN apk add --no-cache xz && \
case "${TARGETARCH}" in \
amd64) s6_arch="x86_64"; s6_sha="${S6_OVERLAY_X86_64_SHA256}" ;; \
arm64) s6_arch="aarch64"; s6_sha="${S6_OVERLAY_AARCH64_SHA256}" ;; \
*) echo "unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac && \
s6_url="https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}" && \
wget -qO /tmp/s6-noarch.tar.xz "${s6_url}/s6-overlay-noarch.tar.xz" && \
echo "${S6_OVERLAY_NOARCH_SHA256} /tmp/s6-noarch.tar.xz" | sha256sum -c - && \
wget -qO /tmp/s6-arch.tar.xz "${s6_url}/s6-overlay-${s6_arch}.tar.xz" && \
echo "${s6_sha} /tmp/s6-arch.tar.xz" | sha256sum -c - && \
mkdir /s6-overlay && \
tar -C /s6-overlay -Jxpf /tmp/s6-noarch.tar.xz && \
tar -C /s6-overlay -Jxpf /tmp/s6-arch.tar.xz
# FETCH EMULATORJS, RUFFLE, JS-DOS, FAKE-08 AND EASYRPG
# Keep the pins below in sync with the dev image's copies in ../Dockerfile.
# checkov:skip=CKV_DOCKER_4:every ADD below is a remote URL pinned by --checksum
FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS emulator-stage
RUN apk add --no-cache \
7zip
ARG EMULATORJS_VERSION=4.2.3
ARG EMULATORJS_SHA256=07d451bc06fa3ad04ab30d9b94eb63ac34ad0babee52d60357b002bde8f3850b
ADD --checksum=sha256:${EMULATORJS_SHA256} \
"https://github.com/EmulatorJS/EmulatorJS/releases/download/v${EMULATORJS_VERSION}/${EMULATORJS_VERSION}.7z" \
/downloads/emulatorjs.7z
RUN 7z x -y /downloads/emulatorjs.7z -o/emulatorjs
ARG RUFFLE_VERSION=nightly-2025-08-14
ARG RUFFLE_FILE=ruffle-nightly-2025_08_14-web-selfhosted.zip
ARG RUFFLE_SHA256=178870c5e7dd825a8df35920dfc5328d83e53f3c4d5d95f70b1ea9cd13494151
ADD --checksum=sha256:${RUFFLE_SHA256} \
"https://github.com/ruffle-rs/ruffle/releases/download/${RUFFLE_VERSION}/${RUFFLE_FILE}" \
/downloads/ruffle.zip
RUN unzip -o /downloads/ruffle.zip -d /ruffle
ARG JSDOS_VERSION=8.5.4
ARG JSDOS_SHA256=6cd8a379556ada7da8a6a49d3ba2fde1783ce3e481c1cd645e13ebc83419a5b8
ADD --checksum=sha256:${JSDOS_SHA256} \
"https://github.com/caiiiycuk/js-dos/releases/download/v${JSDOS_VERSION}/release.zip" \
/downloads/jsdos.zip
# index.html is a demo page that would be served unauthenticated; source maps, symbols,
# type declarations and the opt-in DOSBox-X debugger build are unused at runtime.
RUN unzip -o /downloads/jsdos.zip -d /jsdos && \
rm -rf /jsdos/dist/index.html /jsdos/dist/emulators/types && \
find /jsdos/dist \( -name '*.map' -o -name '*.symbols' -o -name '*-dbg.*' \) -exec rm -f {} +
# FAKE-08 (MIT) publishes no web build, so these come from p3a (Apache-2.0),
# which compiled them. Pinned by commit and checksum: that tree has no tags.
ARG FAKE08_P3A_COMMIT=6519efd9dd1ca853e5c66f7ae9146ace0b7073dc
ARG FAKE08_JS_SHA256=fd2cd4677956037e41a91dbd40fc1a9c4f5979355d55ce3f9312400e11da463e
ARG FAKE08_WASM_SHA256=4339a77e0aa5aa6f4a5bce9fd8286053eedf7f23f2d853db7f4900f6fff4c93a
# Created first, or ADD --chmod would also apply to the directory it creates.
RUN mkdir /fake08
ADD --checksum=sha256:${FAKE08_JS_SHA256} --chmod=644 \
"https://raw.githubusercontent.com/fabkury/p3a/${FAKE08_P3A_COMMIT}/webui/pico8/fake08.js" \
/fake08/fake08.js
ADD --checksum=sha256:${FAKE08_WASM_SHA256} --chmod=644 \
"https://raw.githubusercontent.com/fabkury/p3a/${FAKE08_P3A_COMMIT}/webui/pico8/fake08.wasm" \
/fake08/fake08.wasm
ARG EASYRPG_VERSION=0.8.1.1
ARG EASYRPG_SHA256=99b6963c943bb355e1b1221125cb4536ca2f627c329d8a89cee5a928cdd6a14f
ADD --checksum=sha256:${EASYRPG_SHA256} \
"https://easyrpg.org/downloads/player/${EASYRPG_VERSION}/easyrpg-player-${EASYRPG_VERSION}-js.tar.gz" \
/downloads/easyrpg.tar.gz
# games/ is where the player looks for games, which the server routes to the backend.
RUN mkdir /easyrpg && \
tar -xzf /downloads/easyrpg.tar.gz -C /easyrpg --strip-components=1 && \
rm -rf /easyrpg/games
# The free RTP (CC-BY-4.0) has no releases, so it is pinned by commit.
ARG EASYRPG_RTP_COMMIT=993d88cbc78c658d348bbfa74a3b424d393d27e5
ARG EASYRPG_RTP_SHA256=7e42abebbec94989f4ff214fc082511eef749114e76e3a342cb62d07c03d56e7
ADD --checksum=sha256:${EASYRPG_RTP_SHA256} \
"https://github.com/EasyRPG/RTP/archive/${EASYRPG_RTP_COMMIT}.tar.gz" \
/downloads/easyrpg-rtp.tar.gz
RUN mkdir /easyrpg/rtp && \
tar -xzf /downloads/easyrpg-rtp.tar.gz -C /easyrpg/rtp --strip-components=1 && \
find /easyrpg/rtp \( -name '.git*' -o -name Makefile \) -exec rm -f {} +
# BUILD NGINX MODULE WITH MOD_ZIP
FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS nginx-build
RUN apk add --no-cache \
gcc \
libc-dev \
make \
pcre-dev \
zlib-dev
ARG NGINX_VERSION
# The specified commit SHA is the latest commit on the `master` branch at the time of writing.
# It includes a fix to correctly calculate CRC-32 checksums when using upstream subrequests.
# TODO: Move to a tagged release of `mod_zip`, once a version newer than 1.3.0 is released.
ARG NGINX_MOD_ZIP_COMMIT=a9f9afa441117831cc712a832c98408b3f0416f6
# The module is compiled against the nginx sources so the final image can load it dynamically;
# `nginx` Docker images do not have a simple way to include third-party modules.
# checkov:skip=CKV_DOCKER_4:the ADDs below are Git URLs pinned to a commit and a release tag
ADD "https://github.com/evanmiller/mod_zip.git#${NGINX_MOD_ZIP_COMMIT}" /mod_zip
ADD "https://github.com/nginx/nginx.git#release-${NGINX_VERSION}" /nginx
WORKDIR /nginx
RUN ./auto/configure --with-compat --add-dynamic-module=../mod_zip/ && \
make -f ./objs/Makefile modules && \
chmod 644 ./objs/ngx_http_zip_module.so
# PRODUCTION STAGE
FROM nginx:${NGINX_VERSION}-alpine${ALPINE_VERSION}@sha256:${NGINX_SHA256} AS production-stage
# Alpine backports security fixes to its repo faster than the base image is
# rebuilt, so the digest pin alone leaves known-vulnerable packages in the image.
RUN apk upgrade --no-cache && apk add --no-cache \
bash \
libarchive-tools \
libmagic \
mariadb-connector-c \
libpq \
nodejs \
7zip \
tzdata \
valkey \
valkey-cli
# Add Python by copying it from the official Docker image. This way, we don't rely on Alpine's
# Python version, which could not be the same as the one used in the backend build stage.
# TODO: Replace with a bundled installation of Python using `uv`, when it is supported.
# Related issue: https://github.com/astral-sh/uv/issues/7865
ARG PYTHON_VERSION
COPY --from=python-runtime /usr/lib/* /usr/lib/
COPY --from=python-runtime /usr/local/bin/* /usr/local/bin/
COPY --from=python-runtime /usr/local/lib/libpython* /usr/local/lib/
COPY --from=python-runtime /usr/local/lib/python${PYTHON_VERSION} /usr/local/lib/python${PYTHON_VERSION}
COPY --from=rahasher-build /RALibretro/bin64/RAHasher /usr/bin/RAHasher
COPY --from=rom-converto-fetch /rom-converto /usr/bin/rom-converto
COPY --from=nginx-build /nginx/objs/ngx_http_zip_module.so /usr/lib/nginx/modules/
COPY --from=frontend-build /front/dist /var/www/html
COPY --from=backend-node-build /backend-node/rom_patcher/node_modules/rom-patcher/rom-patcher-js /backend/utils/rom_patcher/rom-patcher-js
COPY ./frontend/assets /var/www/html/assets
COPY --from=gme-build /gme /var/www/html/assets/gme
RUN mkdir -p /var/www/html/assets/romm && \
ln -sf /romm/resources /var/www/html/assets/romm/resources
COPY ./backend /backend
RUN python3 -m compileall -q /backend
# s6-overlay supervises every process in the container: ordered startup with
# readiness gates, restart of anything that dies, and a bounded SIGTERM/SIGKILL
# shutdown so a process that refuses to exit cannot strand PID 1.
COPY --from=s6-overlay-fetch /s6-overlay/ /
# Setup entrypoint, service definitions and config files
COPY ./docker/init_scripts/docker-entrypoint.sh /docker-entrypoint.sh
COPY ./docker/s6-overlay/ /etc/s6-overlay/
COPY ./docker/nginx/js/ /etc/nginx/js/
COPY ./docker/nginx/templates/ /etc/nginx/templates/
COPY ./docker/nginx/default.conf /etc/nginx/nginx.conf
COPY ./docker/gunicorn/logging.conf /etc/gunicorn/logging.conf
# User permissions
# - Create default user `romm` (1000) and group `romm` (1000).
# - Create base directories and make default user/group the owner.
# - Make nginx configuration files writable by everyone for `envsubst` to work
RUN addgroup -g 1000 -S romm && adduser -u 1000 -D -S -G romm romm && \
mkdir /romm /redis-data && \
chown romm:romm /romm /redis-data && \
chmod -R a+w /etc/nginx/conf.d && \
chmod -R a+w /etc/gunicorn
# SLIM IMAGE
FROM scratch AS slim-image
COPY --from=production-stage / /
COPY --from=backend-build /src/.venv /src/.venv
# Optional sigil bindings for title ID extraction; the backend feature
# no-ops when the package is absent.
ARG PYTHON_VERSION
COPY --from=sigil-build /sigil-pkg /src/.venv/lib/python${PYTHON_VERSION}/site-packages/sigil
ENV PATH="/src/.venv/bin:${PATH}"
# ScreenScraper developer (application) credentials, injected at build time from
# CI secrets. Kept out of the source tree; empty when not supplied at build.
ARG SCREENSCRAPER_DEV_ID
ARG SCREENSCRAPER_DEV_PASSWORD
ENV SCREENSCRAPER_DEV_ID=${SCREENSCRAPER_DEV_ID}
ENV SCREENSCRAPER_DEV_PASSWORD=${SCREENSCRAPER_DEV_PASSWORD}
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/backend
# Exit the container when a startup step fails, instead of leaving it up and
# serving nothing, so the restart policy can retry.
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
# Upper bounds on shutdown: how long a service gets after SIGTERM before s6
# stops waiting, and how long anything still alive gets before SIGKILL.
ENV S6_SERVICES_GRACETIME=10000
ENV S6_KILL_GRACETIME=5000
# Declare only the parent `/romm`, not its subdirs, so Docker keeps them
# on one mount (`st_dev`) and cross-directory `os.link()` hardlinks don't fail.
VOLUME ["/romm", "/redis-data"]
# Expose non-privileged ports
EXPOSE 8080 6379/tcp
WORKDIR /romm
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/init"]
# FULL IMAGE
FROM slim-image AS full-image
COPY --from=emulator-stage /emulatorjs /var/www/html/assets/emulatorjs
COPY --from=emulator-stage /ruffle /var/www/html/assets/ruffle
COPY --from=emulator-stage /jsdos/dist /var/www/html/assets/jsdos
COPY --from=emulator-stage /fake08 /var/www/html/assets/pico8
COPY --from=emulator-stage /easyrpg /var/www/html/assets/easyrpg