Skip to content

install tzdata in noninteractive mode#34

Merged
mikaelarguedas merged 5 commits intomasterfrom
noninteractive_bootstrap_install
May 14, 2018
Merged

install tzdata in noninteractive mode#34
mikaelarguedas merged 5 commits intomasterfrom
noninteractive_bootstrap_install

Conversation

@mikaelarguedas
Copy link
Copy Markdown
Contributor

ubuntu:bionic docker image doesnt ship tzdata anymore, and it prompts the user to specify a timezone at installation time.

This PR installs tzdata in non interactive mode before any other dependency.

Based on @tfoote suggestion, I tried creating /etc/timezone before installing but this still requires dpkg to be run in noninteractive mode so I went back to installing the package independently.

The current patch doesnt segregate on os and always performs the install (regardless of the platform). I can modify it to do it only on bionic for now.

  • pro: doesnt change behavior or Dockerfile for other distros
  • con: We will need to maintain a list of distribution for which this step is required
    Feedback welcome.

@tfoote
Copy link
Copy Markdown
Contributor

tfoote commented May 10, 2018

@mikaelarguedas Sorry I was referring to using debconf-set-selections to tell it what timezone to use, not to try to set the resultant variables.

Here's an example of how to pass firefox a setting: https://unix.stackexchange.com/posts/245783/revisions

I think if we did something like echo this sort of data and pipe it to debconf-set-selections we could provide the answers, and they wouldn't be prompted for later.

$ debconf-get-selections | grep tz
debconf: DbDriver "passwords" warning: could not open /var/cache/debconf/passwords.dat: Permission denied
tzdata	tzdata/Zones/Asia	select	
tzdata	tzdata/Zones/Antarctica	select	
# Choices: Afghani, Albanian, Amharic, Arabic, Arabic (Morocco), Arabic (Syria), Armenian, Azerbaijani, Bambara, Bangla, Belarusian, Belgian, Bosnian, Braille, Bulgarian, Burmese, Chinese, Croatian, Czech, Danish, Dhivehi, Dutch, Dzongkha, English (Cameroon), English (Ghana), English (Nigeria), English (South Africa), English (UK), English (US), Esperanto, Estonian, Faroese, Filipino, Finnish, French, French (Canada), French (Democratic Republic of the Congo), French (Guinea), Georgian, German, German (Austria), Greek, Hebrew, Hungarian, Icelandic, Indian, Iraqi, Irish, Italian, Japanese, Japanese (PC-98xx Series), Kazakh, Khmer (Cambodia), Korean, Kyrgyz, Lao, Latvian, Lithuanian, Macedonian, Maltese, Maori, Moldavian, Mongolian, Montenegrin, Nepali, Norwegian, Persian, Polish, Portuguese, Portuguese (Brazil), Romanian, Russian, Serbian, Sinhala (phonetic), Slovak, Slovenian, Spanish, Spanish (Latin American), Swahili (Kenya), Swahili (Tanzania), Swedish, Switzerland, Taiwanese, Tajik, Thai, Tswana, Turkish, Turkmen, Ukrainian, Urdu (Pakistan), Uzbek, Vietnamese, Wolof
tzdata	tzdata/Zones/Europe	select	
tzdata	tzdata/Zones/Arctic	select	
tzdata	tzdata/Zones/Australia	select	
tzdata	tzdata/Zones/SystemV	select	
tzdata	tzdata/Zones/Etc	select	UTC
tzdata	tzdata/Zones/US	select	
tzdata	tzdata/Zones/America	select	Los_Angeles
tzdata	tzdata/Zones/Atlantic	select	
tzdata	tzdata/Zones/Indian	select	
tzdata	tzdata/Zones/Pacific	select	
tzdata	tzdata/Areas	select	America
tzdata	tzdata/Zones/Africa	select	

@mikaelarguedas
Copy link
Copy Markdown
Contributor Author

oh I see.
But that would require installing debconf-utils, so it will not simplify the logic, will it ?

@tfoote
Copy link
Copy Markdown
Contributor

tfoote commented May 10, 2018

If that's not installed by default, yes it won't simplify for this cycle, but it will make any other potential customizations easier. And it would also let us set the time zone as we want, instead of requiring us to use the non-interactive fallback.

I'm not too strongly tied either way. I think the debconf approach is the "cleaner" approach, but it is slightly more complicated at the moment.

@ruffsl
Copy link
Copy Markdown
Member

ruffsl commented May 11, 2018

ubuntu:bionic docker image doesnt ship tzdata anymore, and it prompts the user to specify a timezone at installation time.

I don't think tzdata has been in ubuntu docker images before some time, previously however it just so happened to never ask before using UTC as the default:

docker run -it --rm ubuntu:16.04
dpkg -l tzdata
    dpkg-query: no packages found matching tzdata

apt update
apt install tzdata
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      tzdata
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 166 kB of archives.
    After this operation, 2857 kB of additional disk space will be used.
    Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 tzdata all 2017c-0ubuntu0.16.04 [166 kB]
    Fetched 166 kB in 0s (192 kB/s) 
    debconf: delaying package configuration, since apt-utils is not installed
    Selecting previously unselected package tzdata.
    (Reading database ... 4768 files and directories currently installed.)
    Preparing to unpack .../tzdata_2017c-0ubuntu0.16.04_all.deb ...
    Unpacking tzdata (2017c-0ubuntu0.16.04) ...
    Setting up tzdata (2017c-0ubuntu0.16.04) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
    debconf: falling back to frontend: Teletype

    Current default time zone: 'Etc/UTC'
    Local time is now:      Fri May 11 21:23:53 UTC 2018.
    Universal Time is now:  Fri May 11 21:23:53 UTC 2018.
    Run 'dpkg-reconfigure tzdata' if you wish to change it.

I think if we did something like echo this sort of data and pipe it to debconf-set-selections we could provide the answers, and they wouldn't be prompted for later.

@tfoote and @BillWSY, I just tried:

docker run -it --rm ubuntu:18.04
apt update 
apt install debconf-utils
echo tzdata tzdata/Areas select Etc | debconf-set-selections
echo tzdata tzdata/Zones/Etc select UTC | debconf-set-selections
debconf-get-selections | grep tz
	tzdata	tzdata/Zones/Etc	select	UTC
	tzdata	tzdata/Areas	select	Etc
apt install tzdata

And it still prompts me to select the geographic area. Funny enugh, if I install tzdata, select the prompts to Etc/UTC, then uninstall tzdata and re-install it, it doesn't prompt me the second time. So there must be something else it configures that was missing the first round. See docker diff here of the container I used.

Based on @tfoote suggestion, I tried creating /etc/timezone before installing but this still requires dpkg to be run in noninteractive mode so I went back to installing the package independently.

I got the same issues when following this as well:

https://www.dawnbringer.net/blog/600/Docker:%20tzdata

cc @tianon or @yosifkit , should we just set DEBIAN_FRONTEND=noninteractive globally via ENV, seeing how more of these corner cases might pop up later?

Related

@ruffsl
Copy link
Copy Markdown
Member

ruffsl commented May 11, 2018

I just looked into the debian install process for the new tzdata package, and its just checking one file and one link, so this works as well:

docker run -it --rm ubuntu:18.04
echo 'Etc/UTC' > /etc/timezone
ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime
apt update
apt install tzdata

@mikaelarguedas
Copy link
Copy Markdown
Contributor Author

I just looked into the debian install process for the new tzdata package, and its just checking one file and one link, so this works as well:

Thanks @ruffsl for looking into this, I was missing the symlink.

I added a snippet to conditionally add the timezone configuration to the dockerfiles. This should allow to not modify any existing dockerfile. I made it a blacklist, so if cosmic or other future ubuntu distros have the same behavior as bionic it should work without needing us to change anything.

Copy link
Copy Markdown
Contributor

@tfoote tfoote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about debian support and I'd suggest we collapse this into one RUN layer as an optimization.

}@
@[if os_name == 'ubuntu' and os_code_name not in releases_with_configured_tzdata]@

RUN echo 'Etc/UTC' > /etc/timezone
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well collapse this into one layer. There's no need for the intermediates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a9be002

@@ -0,0 +1,27 @@
@{
releases_with_configured_tzdata = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we exclude this from debian targets like jessie and stretch? They haven't been a problem so could also likely be skipped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this issue doesnt seem to be present in buster or sid (or any already released distro) I decided not to add debian rules for now. We can extend the condition to cover debian platforms when/if we find a debian platform where tzdata starts requiring user input

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. lets leave it off for now.

@tianon
Copy link
Copy Markdown

tianon commented May 14, 2018

Seems reasonable to me.

@mikaelarguedas mikaelarguedas merged commit 4af177c into master May 14, 2018
@mikaelarguedas mikaelarguedas deleted the noninteractive_bootstrap_install branch May 14, 2018 19:39
@mikaelarguedas
Copy link
Copy Markdown
Contributor Author

thanks @tianon for having a look 👍

HHHartmann added a commit to HHHartmann/docker-nodemcu-build that referenced this pull request Aug 19, 2018
Currently tzdata does not install headless and so the docker build hangs
# copied from osrf/docker_templates#34
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 this pull request may close these issues.

4 participants