gow icon indicating copy to clipboard operation
gow copied to clipboard

refactor compose files to (hopefully) make it easier to pick and choose containers

Open zb140 opened this issue 1 year ago • 4 comments

There's sort of two "modes" we can run in: "headless" (ie, run Xorg containerized), and "host" (ie, use the Xorg running on the host). With just a single docker-compose.yml file, we have to choose which one of those is going to be the checked-in version, and anyone who wants to run the other will have to make manual modifications to the file.

This is a proposal for a method of making that easier. I've split the configuration into several files. Now there's:

  • A base docker-compose.yml that just launches a containerized Sunshine
  • compose/headless.yml, which adds xorg, udevd, and pulse, for systems that don't have those already
  • compose/steam.yml, compose/retroarch.yml, and compose/firefox.yml, which add those respective applications

I've also added some files in the env subdirectory; these allow adding the same set of environment variables to multiple containers without a bunch of error-prone copy and paste.

I've tested this pretty well on my unRAID server and things seem to be going well, but I don't have a host to try on that already has Xorg etc, so that could use some testing.

What do you think?

zb140 avatar Jul 30 '22 03:07 zb140

Oh, I forgot to explain how to use the new files. If you just run:

$ sudo docker compose up

It will just launch a containerized Sunshine, using the host's desktop. If you want to run in headless mode, you can run

$ sudo docker compose -f docker-compose.yml -f compose/headless.yml up

This will launch Xorg, udevd, and pulse as well as Sunshine, but it will not run any applications. To also run an app, you can use:

$ sudo docker compose -f docker-compose.yml [-f compose/headless.yml] compose/<application>.yml up`

where <application> is one of: steam, retroarch, or firefox.

zb140 avatar Jul 30 '22 03:07 zb140

I like the direction where this is going, the only thing I don't like is that we have to uncomment/mess with the normal .env file in order to setup compose environment variables. It's a shame that the compose command doesn't support multiple .env files, see: https://github.com/docker/compose/issues/7326

I wonder if we should just wrap docker-compose with a bash script or something, this would also fix the issue where people are running old versions of docker-compose. Ideally this would enable us to do something like:

run-gow --headless --nvidia
> checking nvidia drivers
> checking docker-compose version
> setting-up .env file for you
> running docker compose -f docker-compose.yml -f compose/headless.yml up

I've tested this on a Ubuntu desktop installation, there's a small issue, I'll add a comment to the relevant line.

ABeltramo avatar Jul 30 '22 10:07 ABeltramo

I like the direction where this is going, the only thing I don't like is that we have to uncomment/mess with the normal .env file in order to setup compose environment variables. It's a shame that the compose command doesn't support multiple .env files, see: docker/compose#7326

Yeah, that would be a big win. Maybe they'll eventually get around to adding it 🤞

I wonder if we should just wrap docker-compose with a bash script or something, this would also fix the issue where people are running old versions of docker-compose. Ideally this would enable us to do something like:

I think that's a good idea. I was hoping to preserve the simplicity of just running docker compose but having a shell script wrapper gives us an opportunity to remove most/all of the manual setup steps that are currently needed. I'll work on putting something together.

zb140 avatar Jul 30 '22 14:07 zb140

I've added a first draft of a run-gow launch script. It automatically sets up the environment and chooses which .yml files to use, so there shouldn't be any need to do anything manually, but it doesn't yet do any sanity checking for docker-compose version or anything like that.

Also of note is that I have not yet updated the docs. I'll take another pass through the them once we've got the script working the way we like.

As an example, here's the command I use to launch:

$ ./run-gow --headless --nvidia -a steam

And the full usage message:

$ ./run-gow -h
Launch the Games on Whales system

Usage: run-gow [options]...

Options:

  -h, --help
      This help text.

  --headless
      If set, run in headless mode. Use this mode if your host does not have an Xorg server running on it.

  --nvidia
      Use this option if you want to use an Nvidia GPU with Games on Whales

  -a, --app
      Specify an application to launch. Can be used multiple times

zb140 avatar Aug 03 '22 05:08 zb140

FYI, Arch Linux installs the nvidia drivers here:

/usr/lib/xorg/modules/drivers/nvidia_drv.so
/usr/lib/nvidia/xorg/libglxserver_nvidia.so
kyle@bently 04:39:54 ~/gow on master [!] $ cat /etc/lsb-release
DISTRIB_ID="Arch"
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="Arch Linux"

Also, I'm not sure if this is needed or not, but jellyfin's instructions on getting hardware acceleration into a docker container say that the following is needed:

services:
  ...:
    image: ...
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: [gpu]

They also don't mention that changing the docker runtime is needed.

Sparticuz avatar Aug 24 '22 20:08 Sparticuz

Thanks for the pointers to the Arch drivers; I'll update the script to look for them.

For the docker runtime stuff, it turns out there's actually 2 ways to run with nvidia support in docker. One is the nvidia runtime, which is what we've got implemented right now, and the other is the "nvidia container toolkit" which is what is enabled with the deploy: section you posted. GoW added nvidia support before the updated toolkit was widely available, so we use the older version. We should update to the newer version but I wanted to get this squared away first.

zb140 avatar Aug 25 '22 02:08 zb140

I think this version is pretty much ready to go. I've refactored run-gow a bit for readability, and added some comments for future people working on it. I also added the locations of the nvidia drivers on Debian, and I added support for per-application environment variables (the file env/[app].env will be loaded automatically if it exists).

@ABeltramo @Sparticuz @noinip I'd appreciate it if you could try out this version when you get a chance and report any issues you encounter. It's working well for me. Note that I did change the available options a little bit; most importantly, what used to be --nvidia is now --gpu nvidia. Here's the full usage message:

$ ./run-gow --help
Launch the Games on Whales system

Usage: run-gow [options] [compose commands]
Arguments after the last option will be passed directly to 'docker compose'.
For example, to launch the containers in the background, try:
  $ run-gow --app retroarch up -d

Options:
  -h, --help
      Print this help text.

  -a, --app <app name>
      Specify an application to launch. Can be used multiple times.

  -e, --env-file <file>
      Specify an additional file of environment varibles to load before launching 'docker compose'.

  -g, --gpu <type>
      Use this option to specify what type of GPU to use with Games on Whales. Not
      all GPU types require this option (notably, AMD does not).
      Possible types:
        nvidia, intel

  -q, --quiet
      If set, this script will not produce any output of its own. This will not affect output from 'docker compose'.

  -x, --headless
      If set, run in headless mode. Use this mode if your host does not have an Xorg server running on it.

  --
      Signifies the end of options.

zb140 avatar Aug 27 '22 01:08 zb140