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

"cannot change locale" warnings #302

Closed
dpprdan opened this issue Dec 3, 2021 · 5 comments · Fixed by #313
Closed

"cannot change locale" warnings #302

dpprdan opened this issue Dec 3, 2021 · 5 comments · Fixed by #313

Comments

@dpprdan
Copy link
Contributor

dpprdan commented Dec 3, 2021

I get "cannot change locale" warnings, when I build r-ver (4.1.2) images. They occur on GHA here as well:

E.g. here

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

and here

#10 6.729 perl: warning: Setting locale failed.
#10 6.729 perl: warning: Please check that your locale settings:
#10 6.729 	LANGUAGE = (unset),
#10 6.729 	LC_ALL = "en_US.UTF-8",
#10 6.730 	LANG = "en_US.UTF-8"
#10 6.730     are supported and installed on your system.
#10 6.730 perl: warning: Falling back to the standard locale ("C").

I can't really tell whether it succeeds in the end. I just noticed that the following code is recommended for the official Ubuntu image:

RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
	&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
@cboettig
Copy link
Member

cboettig commented Dec 4, 2021

Thanks @dpprdan . We do install locales and configure as such:

https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_R.sh#L59-L61

but maybe we ought to switch to that recommended way using localedef instead?

We also set LANG, https://github.com/rocker-org/rocker-versioned2/blob/master/dockerfiles/r-ver_4.1.2.Dockerfile#L11, but maybe that needs to be utf8 instead of UTF-8? I'm not really up-to-speed on locale issues, @eddelbuettel probably knows more about this. Dirk, would you recommend we set locales as Daniel recommends above instead? Or is something else the issue here perhaps?

@eddelbuettel
Copy link
Member

Yes, saw this issue, scratched my head, remember I have seen it too. Like you, I think it has to do with which locales are installed. and maybe something (or a value) is missing. But I do not recall what I did to nip this myself. The answer is likely tucked away in one of my containers -- if rocker/r-base does not have it, see what it does that the (similar but different) versioned2 does not.

@dpprdan
Copy link
Contributor Author

dpprdan commented Dec 4, 2021

I can't really tell whether it succeeds in the end.

I've built r-ver on GitLab and my tests confirm that the locale is set to en_US.UTF-8 in the end.

So it is just a matter of getting rid of those pesky warnings.

The r-base Dockerfile seems more or less the same as r-ver, though in somewhat different order:

https://github.com/rocker-org/rocker/blob/df1414259dceb0282f163f29f4dccfa184d38d86/r-base/4.1.2/Dockerfile#L18-L35

My hunch is that setting the ENV vars before installing the locale package in r-ver may be causing the warning.
Or maybe that the ENV vars are set both in the Dockerfile and the install_R.sh script.

@dpprdan
Copy link
Contributor Author

dpprdan commented Dec 19, 2021

Confirmed my hunch that setting the ENV vars before the locale package is available is causing the warning.
Setting ENV LANG after the install_R.sh script is run get's rid of the warnings re: locale (see this build log and this test log confirms that the locale is set.).

I am using the recommended setup (via localedef) here, which is also recommended for Debian, BTW. It is essentially identical to using local-gen as used by rocker, because, as the locale-gen manpage says:

locale-gen is a program that reads the file /etc/locale.gen and invokes localedef for the chosen localisation profiles.

Since we are only generating one locale, localedef should be sufficient, I suppose. Apparently it is also not necessary to update /etc/default/locale?!

Finally, I've also not set LC_ALL, since it is strongly discouraged e.g. in the Debian wiki.

If you want, @cboettig, I can draft a PR with these changes.

@cboettig
Copy link
Member

@dpprdan nice, thanks! a PR on that would be great

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

Successfully merging a pull request may close this issue.

3 participants