pml-lang / pml-companion

Java source code of the 'PML Companion (PMLC)'
https://www.pml-lang.dev
GNU General Public License v2.0
22 stars 1 forks source link

Resources directory written to '?/.config' when inside Docker container #86

Closed coemgenuslcp closed 1 year ago

coemgenuslcp commented 2 years ago

When I run PMLC 3.0.0 inside a Docker container on Linux, the resources directory gets written to ?/.config. It may be something in how the resources directory string determines home or wherever, when it is inside the container context.

# Dockerfile
FROM alpine:latest
RUN wget "https://github.com/pml-lang/pml-companion/releases/download/v3.0.0/pmlc" && chmod +x pmlc
RUN pmlc -version
# or
ENTRYPOINT ["/pmlc", "-version"]
docker build --tag "pmlc" - < Dockerfile
docker run "pmlc" -version
INFO: Creating shared data directory ?/.config/PML_Companion/3_0
PMLC 3.0.0 2022-08-19

The ? folder appears to be created relative to the current directory. As a side effect, if you mount the current directory to the container and WORKDIR into it inside the Dockerfile, the ? folder with the .config/PML resources subdirectory will be generated inside the current directory, with root:root as the owner.

pml-lang commented 2 years ago

The root directory for config data is determined by function userConfigDirectory in DirectoryConfig.java.

Here are the relevant Java statements:

} else if ( OSName.isUnixOS() ) {
    path = System.getenv ( "XDG_CONFIG_HOME" );
    if ( path == null ) {
        path = OSDirectories.USER_HOME_DIRECTORY + "/.config";
    }

As can be seen: The config root directory is retrieved from the OS environment variable XDG_CONFIG_HOME. If this variable is not defined then OSDirectories.USER_HOME_DIRECTORY + "/.config" is used. OSDirectories.USER_HOME_DIRECTORY is defined as follows:

USER_HOME_DIRECTORY = Path.of ( System.getProperty ( "user.home" ) );

It seems that inside your container context:

... which is the reason why the path evaluates to ?/.config.

Hence I suggest to explicitly specify the config root directory by defining OS environment variable XDG_CONFIG_HOME in your Docker config file.

Please let me know if this solves your problem.

PS: To avoid this situation in the future, all functions in DirectoryConfig.java using OSDirectories.USER_HOME_DIRECTORY (i.e. System.getProperty ( "user.home" )) should check this value. If it is ?, then there should be a helpful message displayed in the terminal, so that the user knows how to solve the problem.

pml-lang commented 1 year ago

all functions OSDirectories.USER_HOME_DIRECTORY (i.e. System.getProperty ( "user.home" )) should check this value. If it is ?, then there should be a helpful message

Fixed in version 4.0.0.