Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,93 @@
name: image

# Builds the renderer / updater image and publishes it to GHCR:
# ghcr.io/toro-server/toro-renderer:latest and :<commit sha>
# Builds the renderer / updater image. A pull request stops after the checks; main publishes to GHCR:
# ghcr.io/toro-server/toro-renderer:<commit sha> (what compose pins)
# ghcr.io/toro-server/toro-renderer:latest
on:
push:
branches: [main]
paths:
paths: &paths
- "project.godot"
- "export_presets.cfg"
- "main.tscn"
- "scripts/**"
- "shaders/**"
- "docker/**"
- ".github/workflows/image.yml"
pull_request:
paths: *paths
workflow_dispatch:

permissions:
contents: read
packages: write

concurrency:
group: image
group: image-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6

- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
file: docker/Dockerfile
load: true
tags: local/toro-renderer:ci
cache-from: type=gha
cache-to: type=gha,mode=max

# The runner has no GPU, so rendering itself is checked on a machine that has one. Here: every program and
# every library loaded with dlopen resolves its dependencies, and the exported scripts load from the .pck.
# Every container gets a time limit, so a program that does not finish fails the step instead of the job.
- name: Check the image
run: |
lib=/usr/lib/x86_64-linux-gnu
for f in /usr/local/bin/godot /usr/bin/cage /usr/bin/Xwayland $lib/libvulkan_intel.so $lib/libEGL_mesa.so.0 $lib/gbm/dri_gbm.so; do
echo "--- $f"
out=$(timeout 60 docker run --rm --entrypoint /lib64/ld-linux-x86-64.so.2 local/toro-renderer:ci --list "$f") \
|| { echo "ld.so --list $f failed or did not finish"; exit 1; }
if echo "$out" | grep 'not found'; then exit 1; fi
done
timeout 60 docker run --rm --entrypoint /bin/sh local/toro-renderer:ci -c 'mkdir -p /tmp/x && renice -n 19 -p $$ && ionice -c3 -p $$'
# The release template ignores -s: main.gd must start as the main loop named in project.godot
out=$(timeout 60 docker run --rm --read-only --tmpfs /tmp:exec --entrypoint /usr/local/bin/godot local/toro-renderer:ci \
--headless -- help 2>&1 || true)
echo "$out"
echo "$out" | grep -q 'usage: main.gd'
size=$(docker image inspect local/toro-renderer:ci --format '{{.Size}}')
echo "toro-renderer: $((size / 1048576)) MiB" | tee -a "$GITHUB_STEP_SUMMARY"

# The runner cannot draw, so a pull request's image is kept for a day to be tried on a machine with the iGPU:
# gh run download <run id> -n toro-renderer-image && gunzip -c toro-renderer.tar.gz | docker load
- name: Save the image for a GPU test
if: github.event_name == 'pull_request'
run: docker save local/toro-renderer:ci | gzip -1 > toro-renderer.tar.gz

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: github.event_name == 'pull_request'
with:
name: toro-renderer-image
path: toro-renderer.tar.gz
retention-days: 1
compression-level: 0

- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
if: github.event_name != 'pull_request'
with:
context: .
file: docker/Dockerfile
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ tools\run-local.ps1 -Region C:\worlds\flat\region -Tiles "-8,4,2,2" -Out out -Ex
godot --path . -s scripts/main.gd -- <コマンド> [--オプション 値] [--フラグ]
```

コンテナで使う書き出し用テンプレート (release template) は `-s` を受け付けない。そのため `project.godot` の
`application/run/main_loop_type` で `scripts/main.gd` (クラス名 `RendererMain`) を入口にしている。
テンプレートは main scene が無いと起動しないので、空の `main.tscn` を main scene にしている。
`godot --path . -- <コマンド>` でも同じように動く。

| コマンド | 内容 |
| --- | --- |
| `render` | タイル矩形を PNG / ロスレス WebP / `manifest.json` へ出力(デバッグ、参照画像との比較) |
Expand Down
59 changes: 42 additions & 17 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,59 @@
FROM ubuntu:26.04
# Three stages: (1) export the project to a .pck, (2) collect only the files needed at run time, (3) put them on scratch.
# The image has no package manager, no editor and no Vulkan driver other than Intel's. Build context: the repository root.

FROM ubuntu:26.04@sha256:6a06111c3b0a8600feadb270aec771dc239bf407b25625f93f44ab00e11f4d3c AS pack

ARG GODOT_VERSION=4.7.2-stable

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl unzip \
mesa-vulkan-drivers libvulkan1 libgl1 libegl1 cage \
libx11-6 libxcursor1 libxinerama1 libxi6 libxrandr2 libxkbcommon0 \
libwayland-client0 libwayland-cursor0 libwayland-egl1 libdecor-0-0 \
libasound2t64 libpulse0 libdbus-1-3 libfontconfig1 libudev1 \
&& apt-get install -y --no-install-recommends ca-certificates curl unzip libfontconfig1 \
&& rm -rf /var/lib/apt/lists/*

# Godot is verified against the SHA512 sums published with the release.
# Godot is verified against the SHA512 sums published with the release. The editor imports and exports the project;
# the release export template (about half the size of the editor) runs it.
RUN set -eux; \
base=https://github.com/godotengine/godot-builds/releases/download/${GODOT_VERSION}; \
f=Godot_v${GODOT_VERSION}_linux.x86_64.zip; \
editor=Godot_v${GODOT_VERSION}_linux.x86_64.zip; \
templates=Godot_v${GODOT_VERSION}_export_templates.tpz; \
cd /tmp; \
curl -fsSL -o "$f" "$base/$f"; \
curl -fsSL -o SHA512-SUMS.txt "$base/SHA512-SUMS.txt"; \
grep " $f\$" SHA512-SUMS.txt | sha512sum -c -; \
unzip -q "$f"; \
curl -fsSL -O "$base/$editor" -O "$base/$templates" -O "$base/SHA512-SUMS.txt"; \
grep -E " ($editor|$templates)\$" SHA512-SUMS.txt | sha512sum -c -; \
unzip -q "$editor"; \
mv "Godot_v${GODOT_VERSION}_linux.x86_64" /usr/local/bin/godot; \
rm -f "$f" SHA512-SUMS.txt
mkdir -p /out/usr/local/bin; \
unzip -p "$templates" templates/linux_release.x86_64 > /out/usr/local/bin/godot; \
chmod 755 /out/usr/local/bin/godot; \
rm -f "$editor" "$templates" SHA512-SUMS.txt

WORKDIR /app
COPY project.godot ./
COPY project.godot export_presets.cfg main.tscn ./
COPY shaders ./shaders
COPY scripts ./scripts
COPY docker ./docker
RUN chmod +x docker/*.sh && godot --headless --path /app --import >/dev/null 2>&1 && chmod -R a+rX /app
RUN godot --headless --path /app --import >/dev/null 2>&1; \
godot --headless --path /app --export-pack Linux /out/usr/local/bin/godot.pck \
&& test -s /out/usr/local/bin/godot.pck


FROM ubuntu:26.04@sha256:6a06111c3b0a8600feadb270aec771dc239bf407b25625f93f44ab00e11f4d3c AS rootfs

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
mesa-vulkan-drivers libvulkan1 libgl1 libegl1 cage xwayland busybox-static xkb-data \
libwayland-client0 libwayland-cursor0 libwayland-egl1 libdecor-0-0 libxkbcommon0

COPY --from=pack /out/usr/local/bin/godot /usr/local/bin/godot
COPY docker/rootfs.sh /tmp/rootfs.sh
RUN sh /tmp/rootfs.sh


FROM scratch
COPY --from=rootfs /rootfs/ /
# Official release templates have no --main-pack: they load the .pck named after the binary, next to the binary.
COPY --from=pack /out/usr/local/bin/godot.pck /usr/local/bin/godot.pck
COPY --chmod=755 docker/entrypoint.sh docker/render.sh /app/docker/
ENV PATH=/usr/local/bin:/usr/bin:/bin HOME=/tmp
# Runs with any uid that may use the render node; see docker/compose.watch.yaml.
USER 65532:65532
ENTRYPOINT ["/app/docker/entrypoint.sh"]
4 changes: 3 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export WLR_RENDERER=gles2
export WLR_RENDER_DRM_DEVICE=${RENDER_NODE:-/dev/dri/renderD128}

# lowest CPU and IO priority; the game server always wins
exec nice -n 19 ionice -c3 cage -- /app/docker/render.sh "$@"
renice -n 19 -p $$ > /dev/null
ionice -c3 -p $$
exec cage -- /app/docker/render.sh "$@"
5 changes: 3 additions & 2 deletions docker/render.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh
# Runs inside the cage compositor. Arguments: <command> [options] of scripts/main.gd (--data-dir defaults to /data).
# The release template ignores -s, so scripts/main.gd runs as the main loop named in project.godot.
cmd=$1
shift
exec godot --path /app --rendering-driver vulkan --rendering-method "${GODOT_RENDERING_METHOD:-mobile}" \
exec godot --rendering-driver vulkan --rendering-method "${GODOT_RENDERING_METHOD:-mobile}" \
--display-driver wayland --audio-driver Dummy \
--resolution 64x64 -s scripts/main.gd -- "$cmd" --data-dir "${DATA_DIR:-/data}" "$@"
--resolution 64x64 -- "$cmd" --data-dir "${DATA_DIR:-/data}" "$@"
71 changes: 71 additions & 0 deletions docker/rootfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh
# Copies what the renderer needs at run time into /rootfs: the programs, what they load, and the data they read.
# Everything else in the Ubuntu image (apt, perl, the other Vulkan drivers, documentation...) stays behind.
set -eu

root=/rootfs
lib=/usr/lib/x86_64-linux-gnu

# Programs, and the libraries that are opened with dlopen at run time, so ldd on the programs does not list them.
programs="
/usr/local/bin/godot
/usr/bin/cage
/usr/bin/Xwayland
/usr/bin/renice
/usr/bin/ionice
$lib/libvulkan.so.1
$lib/libvulkan_intel.so
$lib/libEGL_mesa.so.0
$lib/gbm/dri_gbm.so
$lib/libwayland-client.so.0
$lib/libwayland-cursor.so.0
$lib/libwayland-egl.so.1
$lib/libxkbcommon.so.0
$lib/libdecor-0.so.0
"

# Data read at run time.
data="
/usr/share/vulkan/icd.d/intel_icd.json
/usr/share/glvnd/egl_vendor.d/50_mesa.json
/usr/share/drirc.d
/usr/share/xkeyboard-config-2
/usr/share/X11/xkb
"

copy() {
mkdir -p "$root$(dirname "$1")"
# Regular files in place of symbolic links: only the names that ld.so asks for are copied.
cp -L "$1" "$root$1"
}

for program in $programs; do
copy "$program"
missing=$(ldd "$program" | grep 'not found' || true)
if [ -n "$missing" ]; then
echo "$program: $missing" >&2
exit 1
fi
for library in $(ldd "$program" | awk '$2 == "=>" { print $3 } $1 ~ /^\// { print $1 }'); do
[ -e "$root$library" ] || copy "$library"
done
done

for path in $data; do
mkdir -p "$root$(dirname "$path")"
cp -a "$path" "$root$(dirname "$path")/"
done

# A static shell and mkdir for the entry scripts (Ubuntu's busybox has no nice; renice and ionice are copied above).
copy /usr/bin/busybox
mkdir -p "$root/bin"
for applet in sh mkdir; do
ln -s /usr/bin/busybox "$root/bin/$applet"
done

mkdir -p "$root/tmp"
chmod 1777 "$root/tmp"

# ld.so finds the libraries by name without a search of every directory.
mkdir -p "$root/etc"
ldconfig -r "$root"
18 changes: 18 additions & 0 deletions export_presets.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[preset.0]

name="Linux"
platform="Linux"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter="docker/*, tools/*, docs/*"
export_path=""
script_export_mode=2

[preset.0.options]

binary_format/embed_pck=false
binary_format/architecture="x86_64"
3 changes: 3 additions & 0 deletions main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gd_scene format=3]

[node name="Main" type="Node"]
2 changes: 2 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ config_version=5

config/name="TORO Renderer"
config/features=PackedStringArray("4.7", "Forward Plus")
run/main_loop_type="RendererMain"
run/main_scene="res://main.tscn"

[display]

Expand Down
6 changes: 5 additions & 1 deletion scripts/main.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class_name RendererMain
extends SceneTree
## Single entry point of the renderer. Run under a display driver (the GPU needs one, see docker/entrypoint.sh):
## godot --path . -s scripts/main.gd -- <command> [options]
## godot --path . -- <command> [options]
## project.godot names this class in application/run/main_loop_type, because the release export template the
## image runs ignores -s. The template also refuses to start without a main scene, so main.tscn is an empty one.
## With the editor binary, `-s scripts/main.gd` works as well.
##
## render render tile rectangles to PNG/WebP files (debugging, comparison with reference images)
## scan world scan cache (cx, cz, min_y, max_y per chunk)
Expand Down
Loading