diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index b1db4732..04b9ed8b 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -21,14 +21,13 @@ jobs: - name: Run commands in Docker container run: | - docker run --rm -v ${{ github.workspace }}:/workspace --user root \ - -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) test-image /bin/bash -c " - usermod -u \$HOST_UID builder && groupmod -g \$HOST_GID builder && - chown -R \$HOST_UID:\$HOST_GID /home/builder && - su builder -l -c 'cd /workspace && + docker run --rm -v ${{ github.workspace }}:/workspace \ + -e HOSTUID=$(id -u) -e HOSTGID=$(id -g) test-image \ + '/bin/bash -l -c " + cd /workspace && bun install && bun run codegen && bun run meson-setup.clang-release && - bun run vs.example - '" + meson compile -C build/ vs:executable + "' diff --git a/docker/Dockerfile b/docker/Dockerfile index bb06732d..b264ce57 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -37,4 +37,5 @@ RUN \ echo "export PATH=\"\$BUN_INSTALL/bin:\$PATH\"" >> $HOME/.profile USER root -CMD ["bash", "-l"] +ADD entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/README.md b/docker/README.md index e525483c..7f100157 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,7 +2,7 @@ ## Using docker-compose -You may build and test your changes by using the compose file: +You may build your changes by using the compose file: docker-compose -f ./docker/docker-compose.yml up @@ -12,6 +12,7 @@ While in the repository root, to enter the environment and be presented with a shell: docker run -it --rm -u builder \ + -e HOSTUID=$(id -u) \ -v $PWD:/workspace ghcr.io/KaruroChori/vs-fltk:build-env This will mount your current directory as */workspace* inside the container. @@ -28,4 +29,81 @@ You can pull the image manually: If you use `docker-compose` or `docker run ...` the image will be pulled automatically the first time. +## Running the app from the container +Note the following instructions were adapted from instructions generated by +ChatGPT. The X11 instructions were tested on Manjaro Linux. Use at your own +risk. Please update these docs if you have any information about accuracy or +security-related considerations. + +To run an application from a Docker container that requires access to the host +machine's graphics (such as a GUI application), you'll need to share certain +resources from the host with the container. This involves passing through the +host's display (X11 or Wayland, depending on your system) and sharing the +necessary devices. Here's a general guide: + +### For X11-based systems (e.g., most Linux desktop environments) + +1. **Install dependencies on the host:** + Make sure you have `xhost` installed, which allows you to control access to + the X server. + + sudo apt install x11-xserver-utils # For Ubuntu/Debian + sudo pacman -S xorg-xhost # For Arch-based + + +2. **Allow access to X server:** + Before running the container, allow Docker to access your X server: + + xhost +local:docker + + +3. **Run the container with access to the display:** + When starting the container, pass the display environment variable + (`$DISPLAY`) and mount the X11 socket: + +```bash +docker run -it --rm -u builder \ + -v $PWD:/workspace \ + --env="DISPLAY" \ + --env="QT_X11_NO_MITSHM=1" \ + --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ + ghcr.io/KaruroChori/vs-fltk:build-env +``` + + - `--env="DISPLAY"`: Passes the display from the host to the container. + - `--env="QT_X11_NO_MITSHM=1"`: Some applications may need this to avoid shared memory issues. + - `--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw"`: Shares the X11 socket. + +4. **Run the graphical application inside the container:** + Once inside the container, running the app should open its GUI on your host's screen. + +### For Wayland-based systems (e.g., some modern Linux environments): + +1. **Share the Wayland display:** + If your system uses Wayland, you need to pass the Wayland display and devices: + +```bash +docker run -it --rm -u builder \ + -v $PWD:/workspace \ + --env="WAYLAND_DISPLAY=$WAYLAND_DISPLAY" \ + --volume="/run/user/$(id -u)/wayland:/run/user/$(id -u)/wayland" \ + --device=/dev/dri \ + ghcr.io/KaruroChori/vs-fltk:build-env +``` + + - `--env="WAYLAND_DISPLAY=$WAYLAND_DISPLAY"`: Passes the Wayland display variable. + - `--volume="/run/user/$(id -u)/wayland:/run/user/$(id -u)/wayland"`: Shares the Wayland display socket. + - `--device=/dev/dri`: Provides access to GPU devices (for rendering). + +### Additional considerations: + +- **GPU access**: If your application requires GPU acceleration (e.g., +OpenGL), you may also need to pass through GPU devices to the container. For +example, with NVIDIA, you can use the NVIDIA Docker runtime: + + docker run --gpus all -it ghcr.io/KaruroChori/vs-fltk:build-env + +- **X11 access security**: Allowing Docker to connect to your X server with `xhost +local:docker` is not secure. After you're done, revoke access: + + xhost -local:docker diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 00000000..9368715d --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +OLDPWD=$PWD + +if [ -z "HOSTUID" ]; then + echo "HOSTUID is not set." + exit 1 +fi + +if [ -z "HOSTGID" ]; then + echo "HOSTGID is not set." + exit 1 +fi + +usermod -u $HOSTUID builder +groupmod -g $HOSTGID builder +chown -R $HOSTUID:$HOSTGID /home/builder +su builder -c "PATH=/home/builder/.local/bin:$PATH && cd $OLDPWD && $1"