From 421aa70a7b6b4748138b058382bec99b77fdb031 Mon Sep 17 00:00:00 2001 From: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com> Date: Fri, 31 Jan 2025 22:22:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9C=20fix(CI):=20Caching=20fixes=20and?= =?UTF-8?q?=20improvements=20(#176)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes previous PR --------- Co-authored-by: DatCaptainHorse --- .github/workflows/runner.yml | 34 +--- containers/runner.Containerfile | 351 +++++++++++++------------------- 2 files changed, 144 insertions(+), 241 deletions(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index 119b3ff0..a0ea6ec6 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -51,21 +51,6 @@ jobs: uses: pierotofy/set-swap-space@master with: swap-size-gb: 20 - - - name: Cache Rust artifacts - uses: actions/cache@v4 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Cache mold linker - uses: actions/cache@v3 - with: - path: /usr/bin/mold - key: ${{ runner.os }}-mold - name: Build Docker image uses: docker/build-push-action@v5 @@ -75,6 +60,8 @@ jobs: push: false load: true tags: nestri:runner + cache-from: type=gha,mode=max + cache-to: type=gha,mode=max build-docker-main: name: Build image on main @@ -116,21 +103,6 @@ jobs: uses: pierotofy/set-swap-space@master with: swap-size-gb: 20 - - - name: Cache Rust artifacts - uses: actions/cache@v4 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Cache mold linker - uses: actions/cache@v3 - with: - path: /usr/bin/mold - key: ${{ runner.os }}-mold - name: Build Docker image uses: docker/build-push-action@v5 @@ -140,3 +112,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,mode=max + cache-to: type=gha,mode=max diff --git a/containers/runner.Containerfile b/containers/runner.Containerfile index 0035e7a1..e5e5a5ab 100644 --- a/containers/runner.Containerfile +++ b/containers/runner.Containerfile @@ -2,252 +2,181 @@ ARG BASE_IMAGE=docker.io/cachyos/cachyos:latest #****************************************************************************** -# base-builder +# Base Builder Stage - Prepares core build environment #****************************************************************************** FROM ${BASE_IMAGE} AS base-builder -# Install mold linker and sccache upfront -RUN pacman -Sy --noconfirm mold && \ - pacman -S --noconfirm rust && \ - cargo install -j $(nproc) --root /usr/local sccache - -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - CARGO_HOME=/usr/local/cargo \ - cargo install --locked cargo-chef +# Environment setup for Rust and Cargo +ENV CARGO_HOME=/usr/local/cargo \ + ARTIFACTS=/artifacts \ + PATH="${CARGO_HOME}/bin:${PATH}" \ + RUSTFLAGS="-C link-arg=-fuse-ld=mold" -ENV ARTIFACTS=/artifacts -RUN mkdir -p /artifacts - -#****************************************************************************** -# nestri-server-builder -#****************************************************************************** -# FROM base-builder AS nestri-server-builder -# WORKDIR /builder/ +# Install build essentials and caching tools +RUN --mount=type=cache,target=/var/cache/pacman/pkg \ + pacman -Sy --noconfirm mold rust && \ + mkdir -p "${ARTIFACTS}" -# RUN pacman -Sy --noconfirm meson pkgconf cmake git gcc make \ -# gstreamer gst-plugins-base gst-plugins-good gst-plugin-rswebrtc +# Install cargo-chef with proper caching +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ + cargo install -j $(nproc) cargo-chef cargo-c --locked #****************************************************************************** -# nestri-server-planner +# Nestri Server Build Stages #****************************************************************************** +FROM base-builder AS nestri-server-deps +WORKDIR /builder -# FROM nestri-server-builder AS nestri-server-planner -# WORKDIR /builder/nestri/ -# COPY packages/server/Cargo.toml packages/server/Cargo.lock ./ -# RUN --mount=type=cache,target=/root/.cache/sccache \ -# --mount=type=cache,target=/usr/local/cargo/registry \ -# --mount=type=cache,target=/tmp \ -# export RUSTC_WRAPPER=/usr/local/bin/sccache && \ -# cargo chef prepare --recipe-path recipe.json - -#****************************************************************************** -# nestri-server-cacher -#****************************************************************************** -# FROM nestri-server-builder AS nestri-server-cacher -# WORKDIR /builder/nestri/ - -# COPY --from=nestri-server-planner /builder/nestri/recipe.json . -# RUN --mount=type=cache,target=/root/.cache/sccache \ -# --mount=type=cache,target=/usr/local/cargo/registry \ -# --mount=type=cache,target=/tmp \ -# export RUSTC_WRAPPER=/usr/local/bin/sccache && \ -# cargo chef cook --release --recipe-path recipe.json - -#****************************************************************************** -# nestri-server-build -#****************************************************************************** -# FROM nestri-server-builder AS nestri-server-build -# WORKDIR /builder/nestri/ - -# COPY --from=nestri-server-cacher /builder/nestri/target target -# COPY packages/server/ ./packages/server/ - -# RUN --mount=type=cache,target=/root/.cache/sccache \ -# --mount=type=cache,target=/usr/local/cargo/registry \ -# --mount=type=cache,target=/tmp \ -# export RUSTC_WRAPPER=/usr/local/bin/sccache && \ -# export CARGO_BUILD_JOBS=$(nproc) && \ -# export RUSTFLAGS="-C link-arg=-fuse-ld=mold -C target-cpu=native" && \ -# cargo build --release && \ -# cp target/release/nestri-server "$ARTIFACTS" - -#****************************************************************************** -# gst-wayland-builder -#****************************************************************************** -FROM base-builder AS gst-wayland-builder -WORKDIR /builder/ - +# Install build dependencies RUN pacman -Sy --noconfirm meson pkgconf cmake git gcc make \ - libxkbcommon wayland gstreamer gst-plugins-base gst-plugins-good libinput + gstreamer gst-plugins-base gst-plugins-good gst-plugin-rswebrtc -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - CARGO_HOME=/usr/local/cargo \ - cargo install --locked cargo-c +#-------------------------------------------------------------------- +FROM nestri-server-deps AS nestri-server-planner +WORKDIR /builder/nestri -RUN git clone https://github.com/games-on-whales/gst-wayland-display.git +COPY packages/server/Cargo.toml packages/server/Cargo.lock ./ -RUN mkdir plugin - -#****************************************************************************** -# gst-wayland-planner -#****************************************************************************** -FROM gst-wayland-builder AS gst-wayland-planner -WORKDIR /builder/gst-wayland-display - -RUN --mount=type=cache,target=/root/.cache/sccache \ - --mount=type=cache,target=/tmp \ - --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/builder/plugin/ \ - export RUSTC_WRAPPER=/usr/local/bin/sccache && \ - CARGO_HOME=/usr/local/cargo \ +# Prepare recipe for dependency caching +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ cargo chef prepare --recipe-path recipe.json +#-------------------------------------------------------------------- +FROM nestri-server-deps AS nestri-server-cached-builder +WORKDIR /builder/nestri + +COPY --from=nestri-server-planner /builder/nestri/recipe.json . + +# Cache dependencies using cargo-chef +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ + cargo chef cook --release --recipe-path recipe.json + + +ENV CARGO_TARGET_DIR=/builder/target + +COPY packages/server/ ./packages/server/ + +# Build and install directly to artifacts +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ + --mount=type=cache,target=/builder/target \ + cargo build --release && \ + cp target/release/nestri-server "${ARTIFACTS}" + #****************************************************************************** -# gst-wayland-cacher +# GST-Wayland Plugin Build Stages #****************************************************************************** -FROM gst-wayland-builder AS gst-wayland-cacher +FROM base-builder AS gst-wayland-deps +WORKDIR /builder + +# Install build dependencies +RUN --mount=type=cache,target=/var/cache/pacman/pkg \ + pacman -Sy --noconfirm meson pkgconf cmake git gcc make \ + libxkbcommon wayland gstreamer gst-plugins-base gst-plugins-good libinput + +# Clone repository with proper directory structure +RUN git clone https://github.com/games-on-whales/gst-wayland-display.git + +#-------------------------------------------------------------------- +FROM gst-wayland-deps AS gst-wayland-planner +WORKDIR /builder/gst-wayland-display + +# Prepare recipe for dependency caching +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ + cargo chef prepare --recipe-path recipe.json + +#-------------------------------------------------------------------- +FROM gst-wayland-deps AS gst-wayland-cached-builder +WORKDIR /builder/gst-wayland-display COPY --from=gst-wayland-planner /builder/gst-wayland-display/recipe.json . -RUN --mount=type=cache,target=/root/.cache/sccache \ - --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/builder/target \ - --mount=type=cache,target=/builder/plugin/ \ - --mount=type=cache,target=/tmp \ - export CARGO_TARGET_DIR=/builder/target \ - export RUSTC_WRAPPER=/usr/local/bin/sccache && \ - CARGO_HOME=/usr/local/cargo \ +# Cache dependencies using cargo-chef +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ cargo chef cook --release --recipe-path recipe.json -#****************************************************************************** -# gst-wayland-build -#****************************************************************************** -FROM gst-wayland-builder AS gst-wayland-build -WORKDIR /builder/gst-wayland-display +ENV CARGO_TARGET_DIR=/builder/target -COPY --from=gst-wayland-cacher /builder/ /builder/ -COPY . . - -RUN --mount=type=cache,target=/root/.cache/sccache \ - --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/builder/plugin/ \ +# Build and install directly to artifacts +RUN --mount=type=cache,target=${CARGO_HOME}/registry \ --mount=type=cache,target=/builder/target \ - export RUSTC_WRAPPER=/usr/local/bin/sccache \ - export CARGO_TARGET_DIR=/builder/target \ - export CARGO_BUILD_JOBS=$(nproc) \ - export RUSTFLAGS="-C link-arg=-fuse-ld=mold" && \ - CARGO_HOME=/usr/local/cargo \ - cargo cinstall --prefix=/builder/plugin/ --release && \ - cp -r /builder/plugin/ "$ARTIFACTS" - + cargo cinstall --prefix=${ARTIFACTS}/usr --release #****************************************************************************** -# runtime +# Final Runtime Stage #****************************************************************************** FROM ${BASE_IMAGE} AS runtime -# ## Install Graphics, Media, and Audio packages ## -# RUN sed -i '/#\[multilib\]/,/#Include = \/etc\/pacman.d\/mirrorlist/ s/#//' /etc/pacman.conf && \ -# sed -i "s/#Color/Color/" /etc/pacman.conf && \ -# pacman --noconfirm -Syu archlinux-keyring && \ -# dirmngr /dev/null 2>&1 && \ -# # Install mesa-git before Steam for simplicity -# pacman --noconfirm -Sy mesa && \ -# # Install Steam -# pacman --noconfirm -Sy steam steam-native-runtime && \ -# # Clean up pacman cache -# paccache -rk1 && \ -# rm -rf /usr/share/info/* && \ -# rm -rf /usr/share/man/* && \ -# rm -rf /usr/share/doc/ - -# RUN pacman -Sy --noconfirm --needed \ -# # Graphics packages -# sudo xorg-xwayland labwc wlr-randr mangohud \ -# # GStreamer and plugins -# gstreamer gst-plugins-base gst-plugins-good \ -# gst-plugins-bad gst-plugin-pipewire \ -# gst-plugin-rswebrtc gst-plugin-rsrtp \ -# # Audio packages -# pipewire pipewire-pulse pipewire-alsa wireplumber \ -# # Non-latin fonts -# noto-fonts-cjk \ -# # Other requirements -# supervisor jq chwd lshw pacman-contrib && \ -# # Clean up pacman cache -# paccache -rk1 && \ -# rm -rf /usr/share/info/* && \ -# rm -rf /usr/share/man/* && \ -# rm -rf /usr/share/doc/* +### System Configuration ### +RUN sed -i \ + -e '/#\[multilib\]/,/#Include = \/etc\/pacman.d\/mirrorlist/ s/#//' \ + -e "s/#Color/Color/" /etc/pacman.conf && \ + pacman --noconfirm -Sy archlinux-keyring && \ + dirmngr /dev/null 2>&1 -# #Install our backup manager -# ARG LUDUSAVI_VERSION="0.28.0" -# RUN pacman -Sy --noconfirm --needed curl &&\ -# curl -fsSL -o ludusavi.tar.gz "https://github.com/mtkennerly/ludusavi/releases/download/v${LUDUSAVI_VERSION}/ludusavi-v${LUDUSAVI_VERSION}-linux.tar.gz" &&\ -# tar -xzvf ludusavi.tar.gz &&\ -# mv ludusavi /usr/bin/ &&\ -# #Clean up -# rm *.tar.gz +### Package Installation ### +RUN pacman --noconfirm -Sy && \ + # Core system components + pacman -S --needed --noconfirm \ + archlinux-keyring mesa steam steam-native-runtime \ + sudo xorg-xwayland labwc wlr-randr mangohud \ + pipewire pipewire-pulse pipewire-alsa wireplumber \ + noto-fonts-cjk supervisor jq chwd lshw pacman-contrib && \ + # GStreamer stack + pacman -S --needed --noconfirm \ + gstreamer gst-plugins-base gst-plugins-good \ + gst-plugins-bad gst-plugin-pipewire \ + gst-plugin-rswebrtc gst-plugin-rsrtp && \ + # Cleanup + paccache -rk1 && \ + rm -rf /usr/share/{info,man,doc}/* -# # Regenerate locale -# RUN locale-gen +### Application Installation ### +ARG LUDUSAVI_VERSION="0.28.0" +RUN pacman -Sy --noconfirm --needed curl && \ + curl -fsSL -o ludusavi.tar.gz \ + "https://github.com/mtkennerly/ludusavi/releases/download/v${LUDUSAVI_VERSION}/ludusavi-v${LUDUSAVI_VERSION}-linux.tar.gz" && \ + tar -xzvf ludusavi.tar.gz && \ + mv ludusavi /usr/bin/ && \ + rm ludusavi.tar.gz -# ## User ## -# # Create and setup user # -# ENV USER="nestri" \ -# UID=1000 \ -# GID=1000 \ -# USER_PWD="nestri1234" +### User Configuration ### +ENV USER="nestri" \ + UID=1000 \ + GID=1000 \ + USER_PWD="nestri1234" \ + XDG_RUNTIME_DIR=/run/user/1000 \ + HOME=/home/nestri \ + NVIDIA_DRIVER_CAPABILITIES=all \ + NVIDIA_VISIBLE_DEVICES=all -# RUN mkdir -p /home/${USER} && \ -# groupadd -g ${GID} ${USER} && \ -# useradd -d /home/${USER} -u ${UID} -g ${GID} -s /bin/bash ${USER} && \ -# chown -R ${USER}:${USER} /home/${USER} && \ -# echo "${USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \ -# echo "${USER}:${USER_PWD}" | chpasswd +RUN mkdir -p /home/${USER} && \ + groupadd -g ${GID} ${USER} && \ + useradd -d /home/${USER} -u ${UID} -g ${GID} -s /bin/bash ${USER} && \ + chown -R ${USER}:${USER} /home/${USER} && \ + echo "${USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \ + echo "${USER}:${USER_PWD}" | chpasswd && \ + mkdir -p /run/user/${UID} && \ + chown ${USER}:${USER} /run/user/${UID} && \ + usermod -aG input,video,render,seat root && \ + usermod -aG input,video,render,seat ${USER} -# # Run directory # -# RUN mkdir -p /run/user/${UID} && \ -# chown ${USER}:${USER} /run/user/${UID} +### System Services Configuration ### +RUN mkdir -p /run/dbus && \ + # Wireplumber suspend disable + sed -i -z \ + -e 's/{[[:space:]]*name = node\/suspend-node\.lua,[[:space:]]*type = script\/lua[[:space:]]*provides = hooks\.node\.suspend[[:space:]]*}[[:space:]]*//g' \ + -e '/wants = \[/{s/hooks\.node\.suspend\s*//; s/,\s*\]/]/}' \ + /usr/share/wireplumber/wireplumber.conf -# # Groups # -# RUN usermod -aG input root && usermod -aG input ${USER} && \ -# usermod -aG video root && usermod -aG video ${USER} && \ -# usermod -aG render root && usermod -aG render ${USER} && \ -# usermod -aG seat root && usermod -aG seat ${USER} +### Artifacts and Verification ### +COPY --from=nestri-server-cached-builder /artifacts/nestri-server /usr/bin/ +COPY --from=gst-wayland-cached-builder /artifacts/usr/ /usr/ +RUN which nestri-server && ls -la /usr/lib/gstreamer-1.0/ | grep 'waylanddisplaysrc' -# ## Copy files from builders ## -# # this is done here at end to not trigger full rebuild on changes to builder -# # nestri -# COPY --from=nestri-server-build /artifacts/nestri-server /usr/bin/nestri-server -# gstwayland -COPY --from=gst-wayland-build /artifacts/plugin/include/libgstwaylanddisplay /usr/include/ -COPY --from=gst-wayland-build /artifacts/plugin/lib/*libgstwayland* /usr/lib/ -COPY --from=gst-wayland-build /artifacts/plugin/lib/gstreamer-1.0/libgstwayland* /usr/lib/gstreamer-1.0/ -COPY --from=gst-wayland-build /artifacts/plugin/lib/pkgconfig/gstwayland* /usr/lib/pkgconfig/ -COPY --from=gst-wayland-build /artifacts/plugin/lib/pkgconfig/libgstwayland* /usr/lib/pkgconfig/ +### Scripts and Final Configuration ### +COPY packages/scripts/ /etc/nestri/ +RUN chmod +x /etc/nestri/{envs.sh,entrypoint*.sh} && \ + locale-gen -# ## Copy scripts ## -# COPY packages/scripts/ /etc/nestri/ -# # Set scripts as executable # -# RUN chmod +x /etc/nestri/envs.sh /etc/nestri/entrypoint.sh /etc/nestri/entrypoint_nestri.sh - -# ## Set runtime envs ## -# ENV XDG_RUNTIME_DIR=/run/user/${UID} \ -# HOME=/home/${USER} - -# # Required for NVIDIA.. they want to be special like that # -# ENV NVIDIA_DRIVER_CAPABILITIES=all -# ENV NVIDIA_VISIBLE_DEVICES=all - -# # DBus run directory creation # -# RUN mkdir -p /run/dbus - -# # Wireplumber disable suspend # -# # Remove suspend node -# RUN sed -z -i 's/{[[:space:]]*name = node\/suspend-node\.lua,[[:space:]]*type = script\/lua[[:space:]]*provides = hooks\.node\.suspend[[:space:]]*}[[:space:]]*//g' /usr/share/wireplumber/wireplumber.conf -# # Remove "hooks.node.suspend" want -# RUN sed -i '/wants = \[/{s/hooks\.node\.suspend\s*//; s/,\s*\]/]/}' /usr/share/wireplumber/wireplumber.conf - -# ENTRYPOINT ["supervisord", "-c", "/etc/nestri/supervisord.conf"] +ENTRYPOINT ["supervisord", "-c", "/etc/nestri/supervisord.conf"]