Grasscutter icon indicating copy to clipboard operation
Grasscutter copied to clipboard

Added docker support

Open YannickFricke opened this issue 1 year ago • 11 comments

Description

  • Added the multi-staged Dockerfile
  • Added the docker-compose.yml file
    • It also includes a MongoDB service
  • Added the entrypoint for the Docker image

Issues fixed by this PR

Closes #2038 Closes #2250 Closes #2018

Type of changes

  • [ ] Bug fix
  • [ ] New feature
  • [X] Enhancement
  • [ ] Documentation

Checklist:

  • [X] My code follows the style guidelines of this project
  • [X] My pull request is unique and no other pull requests have been opened for these changes
  • [X] I have read the Contributing note and Code of conduct
  • [X] I am responsible for any copyright issues with my code if it occurs in the future.

YannickFricke avatar Dec 14 '23 22:12 YannickFricke

it would be a bit of a hassle to maintain

I think the same about the configuration file - it would be far better if GrassCutter would use environment variables directly - so we could get rid of the workaround (even without having all the reflection stuff) :)

My current approach was:

  1. Build the server from scratch
  2. Running the container via docker-compose (luckily the MongoDB adapter has a timeout of 30 seconds)
  3. cat the config to the host system

Sadly GrassCutter doesn't provide a default configuration file in the source code :/

is there a specific reason you can't generate a config using Java and reflection

For me particular I've never worked with gradle - so we would need another entrypoint where also GSON is loaded - so we could easily generate the config.

But as said above - it would be far better if GrassCutter would use environment variables.

additionally, it would be nice to have an environment variable to change where the image gets its resources.

You mean the GIT repository? That would be doable :)

YannickFricke avatar Dec 15 '23 11:12 YannickFricke

It also seems that there is another problem with the configuration file:

grafik

In the code it states that it is at version 13 - but the server only generates a config of version 4...

YannickFricke avatar Dec 15 '23 12:12 YannickFricke

Also if we would refactor GC to use environment variables - this would be a breaking change :)

YannickFricke avatar Dec 15 '23 12:12 YannickFricke

@KingRainbow44 Could you please verify the latest changes if they work for you? :)

I've refactored the ConfigContainer to use environment variables instead of a file configuration :)

The last TODO is only to refactor the Dockerfile to use an "ARG" for the resources URL - but thats a no-brainer :)

YannickFricke avatar Dec 15 '23 22:12 YannickFricke

The server is starting correctly in Docker (even with the MongoDB connection) - but I cant test it with the client (need to download it first with this slow connection here)

grafik

YannickFricke avatar Dec 15 '23 23:12 YannickFricke

how does this read from the traditional 'config.json' file?

KingRainbow44 avatar Jan 07 '24 21:01 KingRainbow44

how does this read from the traditional 'config.json' file?

It does not anymore - everything was converted to environment variables.

Due to the lack of Docker supporting only mounting specific files (AFAIK) you cannot even mount the config into the container under a specific path.

YannickFricke avatar Jan 07 '24 22:01 YannickFricke

in it's current state, i don't think this pr will be going through. dropping complete support for config.json would be a disaster for the many users which already use grasscutter.

KingRainbow44 avatar Jan 08 '24 01:01 KingRainbow44

in it's current state, i don't think this pr will be going through. dropping complete support for config.json would be a disaster for the many users which already use grasscutter.

What about reading out the config.json file (like before) and generating a script (.bat / .sh) based on the old configuration and then deleting the file (so the generated script wont be overwritten)?

YannickFricke avatar Jan 08 '24 02:01 YannickFricke

not everyone uses a script to start grasscutter, instead why can't you read from a config.json if it exists and set environment variables like that?

KingRainbow44 avatar Jan 19 '24 04:01 KingRainbow44

not everyone uses a script to start grasscutter, instead why can't you read from a config.json if it exists and set environment variables like that?

Because it would bloat up the Docker image - you would need dependencies like jq and an extensive bash script which are only used once in the whole lifecycle.

And we all know that data transformations (which would be needed for nested config keys) isn't that comfortable to maintain.

YannickFricke avatar Jan 19 '24 10:01 YannickFricke