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

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

Closed
coemgenuslcp opened this issue Sep 2, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@coemgenuslcp
Copy link
Contributor

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.

@coemgenuslcp coemgenuslcp added the bug Something isn't working label Sep 2, 2022
@pml-lang
Copy link
Owner

pml-lang commented Sep 5, 2022

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:

  • XDG_CONFIG_HOME is not defined
  • System.getProperty ( "user.home" ) returns ?

... 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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants