theohbrothers / docker-packer

Dockerized packer with useful tools 🐳
Apache License 2.0
3 stars 1 forks source link

Use ARG DEBIAN_FRONTEND=noninteractive in debian-based dockerfiles to bypass stdin errors during builds #9

Closed joeltimothyoh closed 2 years ago

joeltimothyoh commented 2 years ago

As described.

leojonathanoh commented 2 years ago

i've always known that DEBIAN_FRONTEND=noninteractive is used for non-interactive installation, and especially for Dockerfile.

But the same can be achieved without an env var using: https://github.com/theohbrothers/docker-packer/blob/20211030.0.0/generate/templates/Dockerfile.ps1#L19-L20. See the link in the comment there.

joeltimothyoh commented 2 years ago

Without it there's the redundancy of having to execute echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections prior to running apt-get.

Note the use of ARG DEBIAN_FRONTEND=noninteractive which lasts only within the context of the build, unlike ENV DEBIAN_FRONTEND=noninteractive which is a no-no.

leojonathanoh commented 2 years ago

Without it there's the redundancy of having to execute echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections prior to running apt-get.

ARG DEBIAN_FRONTEND=noninteractive might suffice, but if you check out the link in https://github.com/theohbrothers/docker-packer/issues/9#issuecomment-955586845, the OP used ARG DEBIAN_FRONTEND=noninteractive but debconf: unable to initialize frontend: Dialog error still occurred. That's why the suggested fix was to use debconf debconf/frontend select Noninteractive' | debconf-set-selections.

Aside, i like modularity where each RUN statement should be self-contained in contrast to "globals" like ARG DEBIAN_FRONTEND=noninteractive where you don't know what the line applies to. echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections is not needed everytime apt-get is used, but only for some packages that require answering interactive prompts. But to be safe, I include that line in every RUN statement doing apt-get.

joeltimothyoh commented 2 years ago

ARG DEBIAN_FRONTEND=noninteractive might suffice, but if you check out the link in #9 (comment), the OP used ARG DEBIAN_FRONTEND=noninteractive but debconf: unable to initialize frontend: Dialog error still occurred. That's why the suggested fix was to use debconf debconf/frontend select Noninteractive' | debconf-set-selections.

Fair enough.

echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections is not needed everytime apt-get is used, but only for some packages that require answering interactive prompts. But to be safe, I include that line in every RUN statement doing apt-get.

To be safe cannot be safer than having the environment variable DEBIAN_FRONTEND=noninteractive set. If there are specific cases which require the workaround echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections then it should be included for those problematic commands rather than having it within possible commands that might face stdin issues. I'd argue the over-extensive use of the workaround is more reflective of the lack of knowledge as to the cases which require it. Instead, ARG DEBIAN_FRONTEND=noninteractive should almost always be included in debian-based DOCKERFILES, and the workaround included in problematic commands which the environment variable somehow fails to cover. @leojonathanoh

leojonathanoh commented 2 years ago

As i said ARG DEBIAN_FRONTEND=noninteractive is not a replacement for echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selection.

I believe echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selection is needed only for one package that specifically used tzdata to be reconfigured. The package responsible for it is likely libguestfs-tools, see https://github.com/theohbrothers/docker-packer/runs/4055656786?check_suite_focus=true#step:9:2549 job:

#9 26.48 Setting up libusbredirparser1:amd64 (0.8.0-1) ...
#9 26.48 Setting up libldap-common (2.4.49+dfsg-2ubuntu1.8) ...
#9 26.49 Setting up syslinux (3:6.04~git20190206.bf6db5b4+dfsg1-2) ...
#9 26.49 Setting up libboost-iostreams1.71.0:amd64 (1.71.0-6ubuntu6) ...
#9 26.50 Setting up libjbig0:amd64 (2.1-3.1build1) ...
#9 26.50 Setting up ntfs-3g (1:2017.3.23AR.3-3ubuntu1.1) ...
#9 26.50 Setting up libjansson4:amd64 (2.12-1build1) ...
#9 26.51 Setting up acl (2.2.53-6) ...
#9 26.51 Setting up libkrb5support0:amd64 (1.17-6ubuntu4.1) ...
#9 26.52 Setting up libsasl2-modules-db:amd64 (2.1.27+dfsg-2) ...
#9 26.52 Setting up tzdata (2021e-0ubuntu0.20.04) ...
#9 26.61 debconf: unable to initialize frontend: Dialog
#9 26.61 debconf: (TERM is not set, so the dialog frontend is not usable.)
#9 26.61 debconf: falling back to frontend: Readline
#9 26.65 Configuring tzdata
#9 26.65 ------------------
#9 26.65 
#9 26.65 Please select the geographic area in which you live. Subsequent configuration
#9 26.65 questions will narrow this down by presenting a list of cities, representing
#9 26.65 the time zones in which they are located.
#9 26.65 
#9 26.65   1. Africa      4. Australia  7. Atlantic  10. Pacific  13. Etc
#9 26.65   2. America     5. Arctic     8. Europe    11. SystemV
#9 26.65   3. Antarctica  6. Asia       9. Indian    12. US
#9 26.65 Geographic area: 
Error: The operation was canceled.
joeltimothyoh commented 2 years ago

I never said the environment variable is a replacement, but that the workaround should be applied only to commands requiring it.

leojonathanoh commented 2 years ago

@joeltimothyoh yes, i believe it is libguestfs-tools

leojonathanoh commented 2 years ago

@joeltimothyoh managed to reproduce in dev, will fix