Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add Docker support for ease of setup #59

Open
DanielDKnudsen opened this issue Feb 22, 2024 · 9 comments
Open

[Feature]: Add Docker support for ease of setup #59

DanielDKnudsen opened this issue Feb 22, 2024 · 9 comments
Assignees

Comments

@DanielDKnudsen
Copy link
Contributor

DanielDKnudsen commented Feb 22, 2024

Information

I've been playing around with creating a Docker image using this repo.

This would make the server very simple to setup and run in different environments.

I've made a working version - BUT it could use some changes to follow best practices etc.

Linked Discussion: #25

@kus
Copy link
Owner

kus commented Feb 22, 2024

Hi @DanielDKnudsen that's great. What are these best practices?

Do you have a fork of the repo I can take a look at?

Or if you are happy with your setup and have it running you can always do a pull request and I can merge it in after I test it.

Would be good to offer people more options of running the repo.

@DanielDKnudsen
Copy link
Contributor Author

DanielDKnudsen commented Feb 23, 2024

As for the best practices there are a couple I think I am not adhering to:
1. Don't use root user and 'sudo' for running the container:
- As for now, this is needed for running the "install.sh" script - I am now creating a user called "steam" which runs the "Install.sh"
script, but with "sudo" privileges.

2. Migrate "Install.sh" script to Dockerfile:
In general I believe a lot of the things in the "Install.sh" script should be part of the Dockerfile.
This would then create the Docker Image with the mods installed etc. And then every time a new version of this repo is created a
new Docker Image should be built. How I do it now is simply run the "Install.sh" script at container startup. This means the
container takes ~30 seconds to spin up the server, instead of maybe ~10 seconds.

3. Volume mount refactoring:
The volume is currently mounted to '/home', which should probably be changed to 'home/steam/' - but I haven't tested it out
and it is working so I didn't bother.

4. Automate Docker Image build:
Set up Github Action to build and publish new Docker Image upon PR accepted to main branch. I have experience with Github Actions but never published any images to Docker Hub (or any other image registry) so I haven't done this step yet. This would make the install process a lot simpler as there would be no need for the 'docker build ...' step.

These are the major points as I see it, but I probably have overlooked quite a few as well. Not sure - would love some feedback in the pull request.

@DanielDKnudsen
Copy link
Contributor Author

Points 2 and 3 are now handled in the PR.

I won't have time to look into 1 and 4 in the foreseeable future. But they could be looked into at a later stage.

@gitlord1337
Copy link

gitlord1337 commented Apr 5, 2024

Hello, at first thanks for your work!

I tried to start the server via docker but i always get this issue:

2024-04-05 23:09:11 cs2-modded-server | SV: Level loading started for 'de_dust2' 2024-04-05 23:09:11 cs2-modded-server | CL: CLoopModeLevelLoad::MaybeSwitchToGameLoop switching to "game" loopmode with addons () 2024-04-05 23:09:11 cs2-modded-server | SwitchToLoop game requested: id [2] addons [] 2024-04-05 23:09:11 cs2-modded-server | SteamGameServer_Init() 2024-04-05 23:09:11 cs2-modded-server | Failed to initialize Steamworks SDK for gameserver. Failed to load module '/home/steam/.steam/sdk64/steamclient.so' 2024-04-05 23:09:11 cs2-modded-server | /home/cs2-modded-server/install_docker.sh: line 207: 256 Segmentation fault sudo -u $user /home/steam/cs2/game/bin/linuxsteamrt64/cs2 -dedicated -console -usercon -autoupdate -tickrate $TICKRATE $IP_ARGS -port $PORT +map de_dust2 -maxplayers $MAXPLAYERS -authkey $API_KEY +sv_setsteamaccount $STEAM_ACCOUNT +game_type 0 +game_mode 0 +mapgroup mg_active cs2-modded-server exited with code 139

testet it on a windows machine and linux machine with docker.
I have no idea how to get it running, as I'm not yet an expert in Docker.
It seems that the server starts (Level loading started for 'de_dust2') but then it crashes because here is something bad: '/home/steam/.steam/sdk64/steamclient.so'

Edit:
I changed something in the docker_install.sh script:

mkdir -p /home/${user}/.steam/sdk64/
ln -s /steamcmd/linux64/steamclient.so /home/${user}/.steam/sdk64/

then i replaced the old script with
docker cp install_docker.sh 47dcc*******:/home/cs2-modded-server/

and now it works!

@WangChuDi
Copy link

WangChuDi commented May 4, 2024

Hello, at first thanks for your work!

I tried to start the server via docker but i always get this issue:

2024-04-05 23:09:11 cs2-modded-server | SV: Level loading started for 'de_dust2' 2024-04-05 23:09:11 cs2-modded-server | CL: CLoopModeLevelLoad::MaybeSwitchToGameLoop switching to "game" loopmode with addons () 2024-04-05 23:09:11 cs2-modded-server | SwitchToLoop game requested: id [2] addons [] 2024-04-05 23:09:11 cs2-modded-server | SteamGameServer_Init() 2024-04-05 23:09:11 cs2-modded-server | Failed to initialize Steamworks SDK for gameserver. Failed to load module '/home/steam/.steam/sdk64/steamclient.so' 2024-04-05 23:09:11 cs2-modded-server | /home/cs2-modded-server/install_docker.sh: line 207: 256 Segmentation fault sudo -u $user /home/steam/cs2/game/bin/linuxsteamrt64/cs2 -dedicated -console -usercon -autoupdate -tickrate $TICKRATE $IP_ARGS -port $PORT +map de_dust2 -maxplayers $MAXPLAYERS -authkey $API_KEY +sv_setsteamaccount $STEAM_ACCOUNT +game_type 0 +game_mode 0 +mapgroup mg_active cs2-modded-server exited with code 139

testet it on a windows machine and linux machine with docker. I have no idea how to get it running, as I'm not yet an expert in Docker. It seems that the server starts (Level loading started for 'de_dust2') but then it crashes because here is something bad: '/home/steam/.steam/sdk64/steamclient.so'

Edit: I changed something in the docker_install.sh script:

mkdir -p /home/${user}/.steam/sdk64/ ln -s /steamcmd/linux64/steamclient.so /home/${user}/.steam/sdk64/

then i replaced the old script with docker cp install_docker.sh 47dcc*******:/home/cs2-modded-server/

and now it works!

I encounter the same error. And i found the link code has been writtened in line 133-141 of the docker_install.sh script. By uncommenting line 133-141 in the docker_install.sh script, the problem has been solved!

@kus
Copy link
Owner

kus commented May 6, 2024

@DanielDKnudsen any thoughts on this? Why did you comment out the symlink to steamclient.so in your most recent update?

@ReneRebsdorf
Copy link
Contributor

My process for fixing this problem was:

  • Commenting out the git clone from DanielDKnudsen's fork and related file move from the Dockerfile
  • Uncommented the mkdir and ln commands in docker_install.sh
  • In order to now get the configuration files (e.g. docker_install.sh for calling from Dockerfile) I made another bind mount for source: ./ and target /home/cs2-modded-server in the docker-compose.yml file

Now my process for updating is to git pull, docker build, and then docker compose up and using git stash if ever needed, should any of the mentioned files be updated from upstream

This allows me to make modifications to my config files and the likes and seems to be a fairly pain-free process

I agree with @DanielDKnudsen on his opinions on better adhering to some of the best practices on building docker images

An important design decision before refactoring the docker process is to decide how files are "personalized", e.g. I map the entire repo, whilst the current method seems to use specific mounts for config files and binaries only - which is neater in some ways, but means fixing the bug in this issue is more complicated as seen.

My recommendation is to avoid having scripts move files around too much, and instead placing them in their actual location as how they are used in the docker container, although there may be some undesired consequence of this, that I am not aware of, @DanielDKnudsen might know more.

I suggest a PR is made to resolve the current issues for using docker images, and then afterwards looking into the best practices and design decisions :-)

@phyzical
Copy link

phyzical commented May 14, 2024

Hey so i managed to get the server running,

buydoing the uncomment in the docker_install.sh realted above
i also had to mount /home/steam/cs2/ to a location on my server

But none of the ! commands work, looking in the mounted files it seems the files in the /csgo folder int he repo just get replaced?

any idea what i might be messing up

@phyzical
Copy link

Ah figured it out.

needed to change the


echo "Installing mods"
cp -R /home/cs2-modded-server/game/csgo/ /home/${user}/cs2/game/


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants