From c6edc9f3feb5aadfff1d28f24e97ef5bf28ebb11 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Wed, 8 Apr 2026 01:17:49 -0400 Subject: [PATCH] embed steam Half-Life data into the image itself allows also adding hlsdk libs to the image makes it easier to build, manage, and run --- .gitignore | 1 + container/Containerfile | 26 +++++++------------ container/Containerfile.hlsdk | 48 +++++++++++++++++++++++++++++++++++ container/build-and-test.sh | 12 +++++---- container/env.example | 4 --- container/run.sh | 31 ++++++++++++++-------- 6 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 container/Containerfile.hlsdk diff --git a/.gitignore b/.gitignore index f4cd39f..3613e9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ render/work imagecompare rendertest.script +container/Half-Life diff --git a/container/Containerfile b/container/Containerfile index ce187e1..c76e63d 100644 --- a/container/Containerfile +++ b/container/Containerfile @@ -1,15 +1,17 @@ -FROM ubuntu:24.04 +FROM ubuntu-hlsdk # Avoid interactive prompts during package installation ENV DEBIAN_FRONTEND=noninteractive -# Set working directory -WORKDIR /build +USER root + +# Install Vulkan SDK repos +RUN wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | tee /etc/apt/trusted.gpg.d/lunarg.asc \ + && wget -qO /etc/apt/sources.list.d/lunarg-vulkan-noble.list http://packages.lunarg.com/vulkan/lunarg-vulkan-noble.list # Install system dependencies and development packages RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y \ - wget \ - build-essential \ + vulkan-sdk \ libsdl2-dev \ libfreetype-dev \ \ @@ -24,11 +26,6 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge libpostproc-dev \ ffmpeg \ \ - # Utilities - pkg-config \ - python3 \ - python3-pip \ - \ # Running render tests weston \ libgl1-mesa-dri \ @@ -36,16 +33,11 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge libvulkan1 \ imagemagick -RUN wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | tee /etc/apt/trusted.gpg.d/lunarg.asc \ - && wget -qO /etc/apt/sources.list.d/lunarg-vulkan-noble.list http://packages.lunarg.com/vulkan/lunarg-vulkan-noble.list \ - && apt update \ - && apt install --no-install-recommends --no-install-suggests -y vulkan-sdk - # Remove extra cache after all the installations RUN rm -rf /var/lib/apt/lists/* -RUN chown -R ubuntu:ubuntu /build - +# Set working directory +WORKDIR /build COPY build-and-test.sh /build/ # Switch to non-root user diff --git a/container/Containerfile.hlsdk b/container/Containerfile.hlsdk new file mode 100644 index 0000000..72ec6ec --- /dev/null +++ b/container/Containerfile.hlsdk @@ -0,0 +1,48 @@ +FROM ubuntu:24.04 + +# This cannot reference external dirs, unfortunately +ARG HALFLIFE_STEAM_FILES=./Half-Life + +# Copy HL data files +RUN mkdir -p /opt/hl && chown ubuntu:ubuntu /opt/hl +COPY --chown=ubuntu:ubuntu ${HALFLIFE_STEAM_FILES}/valve /opt/hl/valve +COPY --chown=ubuntu:ubuntu ${HALFLIFE_STEAM_FILES}/valve_hd /opt/hl/valve_hd + +ENV DEBIAN_FRONTEND=noninteractive + +# Install generic build dependencies +RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y \ + \ + # Build essential utilities + ca-certificates \ + wget \ + build-essential \ + pkg-config \ + python3 \ + git + +# Build FWGS hlsdk game libs +ARG FWGS_HLSDK_REF=ae84bfc0c3598fcff605a7b3bb963abe8ec3e295 +RUN mkdir -p /build && chown ubuntu:ubuntu /build +USER ubuntu +RUN cd /build && \ + git version && \ + # git > 2.49: git clone --depth 1 --revision ${FWGS_HLSDK_REF} https://github.com/FWGS/hlsdk-portable && \ + mkdir -p hlsdk-portable && \ + cd hlsdk-portable && \ + git init && \ + git remote add origin https://github.com/FWGS/hlsdk-portable && \ + git fetch --depth 1 origin ${FWGS_HLSDK_REF} && \ + git checkout FETCH_HEAD && \ + ./waf \ + configure -8 -T release \ + build \ + install --destdir=/opt/hl + +# Cleanup build files +RUN rm -rf /build/hlsdk-portable + +# At this point there's: +# /opt/hl with +# ./valve +# {dlls, cl_dlls} with fwgs/hlsdk libs diff --git a/container/build-and-test.sh b/container/build-and-test.sh index 40933e3..7f2b99b 100755 --- a/container/build-and-test.sh +++ b/container/build-and-test.sh @@ -1,6 +1,7 @@ #!/bin/bash -#set -eux -set -ux +set -eux + +echo DESTINATION_IS_WRITABLE > /opt/hl/testfile XDG_RUNTIME_DIR=/tmp weston \ --backend=headless \ @@ -11,14 +12,15 @@ XDG_RUNTIME_DIR=/tmp weston \ build() { pushd /build/xash3d-fwgs - ./waf configure -T release -o /build/obj -8 - ./waf install --destdir=/build/out + ./waf configure -T release -8 \ + build \ + install --destdir=/opt/hl popd } rendertest() { pushd /build/HLRTest/render - WAYLAND_DISPLAY=/tmp/wayland-headless ./rendertest.py --xash-dir /build/out run + WAYLAND_DISPLAY=/tmp/wayland-headless ./rendertest.py --xash-dir /opt/hl run popd } diff --git a/container/env.example b/container/env.example index ac5939b..128858c 100644 --- a/container/env.example +++ b/container/env.example @@ -1,7 +1,3 @@ -# Path to Steam Half-Life data, where ./valve and ./valve_hd dirs are located (readonly) -# Must already contain build https://github.com/FWGS/hlsdk-portable libs in `dlls` and `cl_dlls/` -STEAM_HALFLIFE_DIR=${HOME}/opt/Half-Life - # Path to https://rtxash.omgwtf.ru/Half-Life-RTX/Half-Life-PBR repo clone (readonly) HALFLIFE_PBR_REPO_DIR=${HOME}/src/Half-Life-PBR diff --git a/container/run.sh b/container/run.sh index 976555c..69e1974 100755 --- a/container/run.sh +++ b/container/run.sh @@ -7,33 +7,42 @@ HLRTEST_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" source .env -build-image() { - podman build -t ubuntu-xash-builder . +build-image-hlsdk() { + podman build -t ubuntu-hlsdk -f Containerfile.hlsdk } -run() { +build-image() { + podman build -t ubuntu-xash-builder -f Containerfile +} + +build() { + build-image-hlsdk + build-image +} + +render-test() { + OUTPUT="${HLRTEST_PATH}/render/work" + # Make sure the image ubuntu user can write to the output + chmod -R o+rw "${OUTPUT}" + podman run -it --rm \ --name ${NAME} \ - --userns=keep-id \ - --user $(id -u):$(id -g) \ + --userns=keep-id:uid=1000,gid=1000 \ \ --cap-drop=ALL \ --security-opt=no-new-privileges \ --read-only \ --tmpfs /tmp \ - --tmpfs /build/obj \ - --tmpfs /build/out \ \ -v /dev/dri/renderD128:/dev/dri/renderD128:ro \ \ - -v ${STEAM_HALFLIFE_DIR}/valve:/build/out/valve:O \ - -v ${STEAM_HALFLIFE_DIR}/valve_hd:/build/out/valve_hd:ro \ - -v ${HALFLIFE_PBR_REPO_DIR}/valve/pbr:/build/out/valve/pbr:ro \ + -v /opt/hl \ + -v ${HALFLIFE_PBR_REPO_DIR}/valve/pbr:/opt/hl/valve/pbr:ro \ \ -v ${XASH3D_RT_REPO_DIR}:/build/xash3d-fwgs:O \ \ -v ${HLRTEST_PATH}:/build/HLRTest:ro \ - -v ${HLRTEST_PATH}/render/work:/build/HLRTest/render/work \ + -v ${OUTPUT}:/build/HLRTest/render/work \ \ ubuntu-xash-builder:latest \ "$@"