Skip to content

Commit

Permalink
Update docker syntax version
Browse files Browse the repository at this point in the history
Use heredocs for multi-line script.
  • Loading branch information
rubensa committed Oct 10, 2024
1 parent b3e9e88 commit 589dcee
Showing 1 changed file with 48 additions and 29 deletions.
77 changes: 48 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.4
FROM rubensa/ubuntu-tini-dev
LABEL author="Ruben Suarez <[email protected]>"

Expand Down Expand Up @@ -27,47 +28,65 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update

# Install Google Noto font family
RUN echo "# Installing Google Noto font family..." \
&& apt-get -y install fonts-noto 2>&1
RUN <<EOT
echo "# Installing Google Noto font family..."
apt-get -y install fonts-noto 2>&1
EOT

# Install software and libraries needed to share X11 between host and container
RUN echo "# Installing kmod, libglib2.0-bin, libgl1, libglx-mesa0, libgl1-mesa-dri, pulseaudio-utils, cups-client, x11-utils, mesa-utils, mesa-utils-extra and va-driver-all..." \
&& apt-get -y install --no-install-recommends kmod libglib2.0-bin libgl1 libglx-mesa0 libgl1-mesa-dri pulseaudio-utils cups-client x11-utils mesa-utils mesa-utils-extra va-driver-all 2>&1
RUN <<EOT
echo "# Installing kmod, libglib2.0-bin, libgl1, libglx-mesa0, libgl1-mesa-dri, pulseaudio-utils, cups-client, x11-utils, mesa-utils, mesa-utils-extra and va-driver-all..."
apt-get -y install --no-install-recommends kmod libglib2.0-bin libgl1 libglx-mesa0 libgl1-mesa-dri pulseaudio-utils cups-client x11-utils mesa-utils mesa-utils-extra va-driver-all 2>&1
EOT

# Configure user (add to audio and video groups)
RUN echo "# Configuring '${USER_NAME}' for X11 functionallity..." \
#
# Assign audio group to non-root user
&& usermod -a -G audio ${USER_NAME} \
#
# Assign video group to non-root user
&& usermod -a -G video ${USER_NAME}
RUN <<EOT
echo "# Configuring '${USER_NAME}' for X11 functionallity..."
#
# Assign audio group to non-root user
usermod -a -G audio ${USER_NAME}
#
# Assign video group to non-root user
usermod -a -G video ${USER_NAME}
EOT

# Install NVIDIA drivers in the image if NVIDIA_VERSION arg set
RUN if [ ! -z ${NVIDIA_VERSION} ] ; then \
if [ "$TARGETARCH" = "arm64" ]; then TARGET=aarch64; elif [ "$TARGETARCH" = "amd64" ]; then TARGET=x86_64; else TARGET=$TARGETARCH; fi; \
echo "# Downloading NVIDIA drivers matching host version (${NVIDIA_VERSION})..."; \
curl -sSLO http://us.download.nvidia.com/XFree86/Linux-${TARGET}/${NVIDIA_VERSION}/NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run; \
chmod +x NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run; \
echo "# Installing NVIDIA drivers..."; \
./NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run --ui=none --no-kernel-module --no-install-compat32-libs --install-libglvnd --no-questions; \
rm NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run; \
RUN <<EOT
if [ ! -z ${NVIDIA_VERSION} ] ; then
if [ "$TARGETARCH" = "arm64" ]; then
TARGET=aarch64
elif [ "$TARGETARCH" = "amd64" ]; then
TARGET=x86_64
else
TARGET=$TARGETARCH
fi
echo "# Downloading NVIDIA drivers matching host version (${NVIDIA_VERSION})..."
curl -sSLO http://us.download.nvidia.com/XFree86/Linux-${TARGET}/${NVIDIA_VERSION}/NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run
chmod +x NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run
echo "# Installing NVIDIA drivers..."
./NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run --ui=none --no-kernel-module --no-install-compat32-libs --install-libglvnd --no-questions
rm NVIDIA-Linux-${TARGET}-${NVIDIA_VERSION}.run
fi
EOT

# Add script to allow nvidia drivers installation on user interactive session
ADD install-nvidia-drivers.sh /usr/bin/install-nvidia-drivers.sh
RUN echo "# Configuring '${USER_NAME}' for NVIDIA drivers auto installation if NVIDIA_VERSION env variable is set..." \
#
# Enable runtime nvidia drivers installation
&& chmod +x /usr/bin/install-nvidia-drivers.sh \
#
# Configure nvidia drivers installation for the non-root user
&& printf "\n. /usr/bin/install-nvidia-drivers.sh\n" >> /home/${USER_NAME}/.bashrc
RUN <<EOT
echo "# Configuring '${USER_NAME}' for NVIDIA drivers auto installation if NVIDIA_VERSION env variable is set..."
#
# Enable runtime nvidia drivers installation
chmod +x /usr/bin/install-nvidia-drivers.sh
#
# Configure nvidia drivers installation for the non-root user
printf "\n. /usr/bin/install-nvidia-drivers.sh\n" >> /home/${USER_NAME}/.bashrc
EOT

# Clean up apt
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
RUN <<EOT
apt-get autoremove -y
apt-get clean -y
rm -rf /var/lib/apt/lists/*
EOT

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
Expand Down

0 comments on commit 589dcee

Please sign in to comment.