mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 01:58:41 +01:00
* feat(converto): integrate rom-converto for title id extraction and download conversion * fix(docker): ship rom-converto in the production image Only the dev Dockerfile installed the binary, so the integration could never enable on a released image. Fetch the same pinned, checksummed musl build in a dedicated stage and copy it next to RAHasher. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(converto): skip the update check and batch info calls The CLI asks api.github.com for a newer release on every run unless told not to, so pass --no-update-check on each invocation. Inspect a rom's files in one `info --paths-file` run instead of one subprocess per file, and read the inspectable extensions from the capabilities manifest so scans skip files info cannot recognize. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(scan): keep sigil authoritative for title ids rom-converto ran first and overrode the ids sigil read. Sigil now runs first and records its per-file ids; rom-converto only fills files sigil left unset, on new or changed files, in one batch. Restore the base-id selection for sigil extractions on every platform, as on master. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(downloads): make conversion opt-in and bound the cache The download endpoint returned a converted file to every client once a platform had a target, including the browser player and apps that check hashes against RomFile. Conversion now needs ?converted=true. A pre-warmed copy is served whatever its size; the in-request size cap only gates starting a conversion. ROM_CONVERTO_CACHE_MAX_SIZE_GB (default 20, 0 unbounded) caps the cache: conversions and the pre-warm task stop when it is full, and cleanup evicts the least recently served copies. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore(types): regenerate frontend types for the converto schema Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(converto): address code-review findings (pr-ready step 2) - Fall back to rom-converto's stored ids only when it ran this pass, in disc order, so a rescan that skipped extraction keeps sigil's save target - Persist per-file title ids that extraction writes onto reused rows - Only authenticated callers may start an in-request conversion; past a 240s deadline serve the original and let the conversion finish into the cache instead of nginx returning 504 - Treat a probe OSError or timeout as a failed probe; kill the subprocess when the caller is cancelled - Give the pre-warm task the scan timeout and report progress in the ConversionStats shape the task UI reads - Reuse zip_cache constants, walk the cache off the event loop, tolerate files vanishing mid-cleanup, and trim long comments Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): simplify conversion code (pr-ready step 3) - Move the converted-download policy (target lookup, cached-first, sync size cap, deadline) from the endpoint into utils/conversion_cache and share conversion_target with the pre-warm task - Share one path lookup between get_cached_converted and get_or_convert; the pre-warm walks the cache once and tracks a running byte budget instead of walking it twice per rom - One normalize_platform_formats beside TARGETS_BY_PLATFORM for the config loader (via _validated_platform_map) and the settings endpoint; update_converto_settings takes a ConvertoConfig and is written back with dataclasses.asdict - read_infos owns its never-raise contract, so the scan drops its blanket except; drop the unused RomConvertoInfo.kind and error attributes - Sort files for the rom-converto identity only when it is used; stat each cached file once during cleanup Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore(converto): trim comments (pr-ready step 4) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): convert on first download instead of pre-warming A library pre-warm fought the TTL: cleanup dropped every copy nobody downloaded within a day. Remove the Convert library task and convert on demand only. Files over ROM_CONVERTO_MAX_SYNC_SIZE_MB now start their conversion in the background while the original is served, so the next download within the TTL gets the converted copy at any size. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): drop decrypt and encrypt download targets Downloads now only change a rom's container or compression (CHD, RVZ, CSO, NSZ, ...); serving decrypted files is left for a separate decision. NDS and PS3 have no remaining targets. Also note that the conversion concurrency limit applies per process. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): move the cache limits into converto.* cache_max_size_gb and max_sync_size_mb join cache_ttl_hours in config.yml and PUT /api/config/converto_settings, replacing the ROM_CONVERTO_CACHE_MAX_SIZE_GB and ROM_CONVERTO_MAX_SYNC_SIZE_MB env vars, so every eviction knob is edited in one place at runtime. The loader takes its defaults from ConvertoConfig and one table holds each integer's minimum for both the loader and the payload. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): lock conversions with flock instead of a sentinel A conversion now holds a non-blocking flock on its key dir, which the kernel releases if the worker dies. That replaces the .partial sentinel, its 6-hour staleness guess (which a long ROM_CONVERTO_TIMEOUT could outlive), and the rename-aside takeover. Cleanup skips locked dirs, and partial output gets a hidden name so it never counts as a served copy. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(converto): parametrize repeated test cases Collapse the per-platform info parsing, operation resolution and converto_active cases into parametrized tests, so a new platform or target is one row. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(scan): run rom-converto first with sigil as the fallback rom-converto reads each rom's new or changed files first, in one batch, and its title ids win. sigil still reads what it can, since it alone provides save targets and Switch content types, and fills the ids rom-converto left unset. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(converto): store per-file metadata read by rom-converto during scans * fix(scan): keep the stored save target when sigil reads nothing * fix(converto): read Xbox 360 disc ids and Wii title versions, store content type as text * feat(converto): save file icons, banners and backgrounds read by rom-converto * chore(converto): bump rom-converto to v0.23.0 * fix(converto): address review findings in the conversion cache, scan metadata and settings * refactor(converto): move per-file metadata out of the conversion PR Scan-time metadata (title ids, the 17 rom_files columns, artwork and converto.scan_metadata) moves to its own PR so its columns land with the UI that reads them. This PR keeps conversion only. The conversion cache no longer has uncompressed_size_bytes to budget with, so a conversion to an uncompressed target reserves a fixed multiple of its input and the cleanup pass after it evicts any overshoot. Co-Authored-By: DevYukine <20647088+DevYukine@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017BuuZVVtVPNLRaCjTN9bgQ * feat(converto): let the client pick the download format with ?format= `?format=zso,iso` lists the formats a client can read. The stored file is served whenever its format is listed, even with conversion off, so most emulator clients never trigger a conversion. Otherwise the first listed format with a cached copy is served, then the first one rom-converto can produce. A conversion that outlasts a short wait answers 202 with Retry-After instead of falling back to the original, so a URL never serves two different files and a client never gets bytes it can't read. 406 means no listed format can be served. HEAD reports the same without starting a conversion. This replaces `?converted=true`, the per-platform download target and `max_sync_size_mb`; `cache_ttl_hours` stays config.yml-only. Co-Authored-By: DevYukine <20647088+DevYukine@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017BuuZVVtVPNLRaCjTN9bgQ * feat(converto): convert the library in place with a manual task `converto.platform_formats` now names the format a platform's library is stored in, and the new "Convert library" task brings every matched rom to it. Each output is staged in a `.romm_tmp_` directory beside the original, moved into place, and only then are the originals (and a cue's tracks) deleted. Single-file roms take the new name, folder roms keep theirs and get their .m3u entries rewritten, and the file rows refresh, so a rom keeps its id, saves and collections. Only lossless conversions qualify, so xbox (xiso trims the dump) has no library format. Unmatched roms are skipped because a converted file no longer hash-matches a DAT. `/api/config` now carries the library targets and, per input extension, the formats a download can be converted to. Co-Authored-By: DevYukine <20647088+DevYukine@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017BuuZVVtVPNLRaCjTN9bgQ * fix(converto): address Greptile and Copilot review findings - Publish a converted library file with a no-replace link, so a file that appears during conversion is never overwritten. - Delete originals only after the rom row or its playlists point at the new file, and keep them if that update fails. Playlists are rewritten atomically. - Refuse a cue conversion whose tracks another rom or another cue holds. - Remove stage dirs a killed conversion left behind. - Try later ?format= targets when a conversion fails, treat any locked key dir as converting, and cap how many conversions downloads can start. - Drop the unsupported iso target for CD platforms from the example config and list the ROM_CONVERTO_* variables in env.template. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(converto): address code-review findings (pr-ready step 2) Serve converted outputs at 0644, read cue sheets and playlists with a BOM, stage folder rom conversions outside the rom folder, keep one rom's failure from stopping the convert library task, accept alias extensions as the stored format, probe running conversions with a shared lock, and bound the timeout. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): simplify conversion code (pr-ready step 3) Check and chmod rom-converto output once in the adapter, canonicalize requested format aliases, reuse LINK_FALLBACK_ERRNOS and the handler's atomic write, make the download format table a constant, skip the probe lock once cached, and fold duplicated name checks and cache stat passes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore(converto): trim comments (pr-ready step 4) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(converto): find rom-converto on PATH instead of ROM_CONVERTO_PATH Both images install the binary on PATH, the variable was undocumented, and RAHasher is already resolved the same way. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Yukine <devyukine@gmx.de> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: DevYukine <20647088+DevYukine@users.noreply.github.com>
360 lines
14 KiB
Docker
360 lines
14 KiB
Docker
# Stages:
|
|
# - python-runtime: Patch the Python image's libraries before they ship
|
|
# - frontend-build: Build frontend
|
|
# - backend-build: Build backend environment
|
|
# - backend-dev-build: Similar to `backend-build`, but also compiles and installs development dependencies
|
|
# - rahasher-build: Build RAHasher
|
|
# - sigil-build: Build sigil Python bindings (title ID extraction)
|
|
# - rom-converto-fetch: Fetch the rom-converto CLI (ROM conversion and metadata)
|
|
# - 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
|
|
# - dev-slim: Slim image with development dependencies
|
|
# - dev-full: Full image with emulator stage and development dependencies
|
|
|
|
|
|
# ARGUMENT DECLARATIONS
|
|
ARG ALPINE_VERSION=3.24
|
|
ARG ALPINE_SHA256=294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6
|
|
# Pins the base image tag, so it cannot read ../.python-version; keep the two in sync.
|
|
ARG PYTHON_VERSION=3.14
|
|
ARG PYTHON_ALPINE_SHA256=9e9fde4d32eedce0b661d9ab91e826b62dddf28e928c230ec55f1866cac66b01
|
|
ARG NODE_VERSION=24.16
|
|
ARG NODE_ALPINE_SHA256=21f403ab171f2dc89bad4dd69d7721bfd15f084ccb46cdd225f31f2bc59b5c9a
|
|
ARG NGINX_VERSION=1.30.5
|
|
ARG NGINX_SHA256=a5f2157a0302eb0c5e300415effb63a9e70ed1eb9c107283819bf6d149ab607c
|
|
ARG UV_VERSION=0.12.19
|
|
ARG UV_SHA256=b165481b747c340b4b3b820f6e453c3aea939c8b583cbfc01c4e99ec61181bc2
|
|
|
|
|
|
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}@sha256:${PYTHON_ALPINE_SHA256} AS python-alias
|
|
|
|
|
|
# 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.
|
|
FROM python-alias AS python-runtime
|
|
RUN apk upgrade --no-cache
|
|
|
|
|
|
# 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}@sha256:${NODE_ALPINE_SHA256} 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}@sha256:${NODE_ALPINE_SHA256} 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/
|
|
RUN uv sync --frozen --no-cache
|
|
|
|
FROM backend-build AS backend-dev-build
|
|
|
|
# linux-headers is needed to install psutil
|
|
RUN apk add --no-cache \
|
|
linux-headers
|
|
|
|
RUN uv sync --frozen --no-cache --all-extras
|
|
|
|
|
|
# CUSTOM RAHASHER FOR RETROACHIEVEMENTS
|
|
FROM alpine:${ALPINE_VERSION}@sha256:${ALPINE_SHA256} 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++ \
|
|
git \
|
|
make \
|
|
musl-dev
|
|
|
|
# Keep this pin in sync with the dev image's SIGIL_VERSION in ../Dockerfile.
|
|
ARG SIGIL_VERSION=8a3b0089676e07f74da2d9ad08979dedf5cae7c0
|
|
|
|
RUN git clone --filter=blob:none https://github.com/rommapp/argosy-sigil.git && \
|
|
cd ./argosy-sigil && \
|
|
git checkout "${SIGIL_VERSION}" && \
|
|
git submodule update --init --recursive && \
|
|
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/
|
|
|
|
|
|
# ROM-CONVERTO CLI
|
|
# Keep the version and both sums in sync with the dev image's copy in ../Dockerfile.
|
|
FROM alpine:${ALPINE_VERSION}@sha256:${ALPINE_SHA256} AS rom-converto-fetch
|
|
ARG TARGETARCH
|
|
ARG ROM_CONVERTO_VERSION=v0.23.0
|
|
RUN case "${TARGETARCH}" in \
|
|
amd64) rc="linux-x64-musl"; sum="37d03a67ad97fc02768890e763b4c80072fdfd15f2c5b97e44f9a2b50fc40876" ;; \
|
|
arm64) rc="linux-arm64-musl"; sum="8abe37ca2d1a0e3d719fb8e795e011c672e3f1c088521cf0bb1e467dc658dc3c" ;; \
|
|
*) 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
|
|
|
|
|
|
# FETCH EMULATORJS, RUFFLE, JS-DOS AND FAKE-08
|
|
# 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}@sha256:${ALPINE_SHA256} 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.4.1
|
|
ARG JSDOS_SHA256=26118692bbb180aec78ec1697eb1ea6b28ff410101870cfa3e68309914c7eaa6
|
|
|
|
ADD --checksum=sha256:${JSDOS_SHA256} \
|
|
"https://github.com/caiiiycuk/js-dos/releases/download/v${JSDOS_VERSION}/release.zip" \
|
|
/downloads/jsdos.zip
|
|
# The bundled index.html is a js-dos demo page that would be served unauthenticated;
|
|
# source maps, Emscripten symbol files and type declarations 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' \) -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
|
|
|
|
|
|
# BUILD NGINX MODULE WITH MOD_ZIP
|
|
FROM alpine:${ALPINE_VERSION}@sha256:${ALPINE_SHA256} AS nginx-build
|
|
|
|
RUN apk add --no-cache \
|
|
gcc \
|
|
git \
|
|
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
|
|
|
|
# Clone both `nginx` and `ngx_http_zip_module` repositories, needed to compile the module from source.
|
|
# This is needed to be able to dinamically load it as a module in the final image. `nginx` Docker
|
|
# images do not have a simple way to include third-party modules.
|
|
RUN git clone https://github.com/evanmiller/mod_zip.git && \
|
|
cd ./mod_zip && \
|
|
git checkout "${NGINX_MOD_ZIP_COMMIT}" && \
|
|
cd ../ && \
|
|
git clone --branch "release-${NGINX_VERSION}" --depth 1 https://github.com/nginx/nginx.git && \
|
|
cd ./nginx && \
|
|
./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
|
|
ARG WEBSERVER_FOLDER=/var/www/html
|
|
|
|
# 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/include/python${PYTHON_VERSION} /usr/local/include/python${PYTHON_VERSION}
|
|
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 ${WEBSERVER_FOLDER}
|
|
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 ${WEBSERVER_FOLDER}/assets
|
|
RUN mkdir -p ${WEBSERVER_FOLDER}/assets/romm && \
|
|
ln -sf /romm/resources ${WEBSERVER_FOLDER}/assets/romm/resources
|
|
COPY ./backend /backend
|
|
|
|
# Setup init script and config files
|
|
COPY ./docker/init_scripts/* /
|
|
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 755 /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}
|
|
|
|
# Security: Set security-focused environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONPATH=/backend
|
|
|
|
# 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
|
|
ARG WEBSERVER_FOLDER=/var/www/html
|
|
COPY --from=emulator-stage /emulatorjs ${WEBSERVER_FOLDER}/assets/emulatorjs
|
|
COPY --from=emulator-stage /ruffle ${WEBSERVER_FOLDER}/assets/ruffle
|
|
COPY --from=emulator-stage /jsdos/dist ${WEBSERVER_FOLDER}/assets/jsdos
|
|
COPY --from=emulator-stage /fake08 ${WEBSERVER_FOLDER}/assets/pico8
|
|
|
|
|
|
FROM slim-image AS dev-slim
|
|
COPY --from=backend-dev-build /src/.venv /src/.venv
|
|
|
|
|
|
FROM full-image AS dev-full
|
|
COPY --from=backend-dev-build /src/.venv /src/.venv
|