Skip to content

Commit

Permalink
Add DOCKER_REPOSITORY_NAME to reusable workflow
Browse files Browse the repository at this point in the history
Use variables for Docker image name
  • Loading branch information
rubensa committed Sep 6, 2022
1 parent 5502491 commit 1f7ab05
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
build:
uses: rubensa/docker-ubuntu-tini/.github/workflows/docker-build.yml@master
with:
DOCKER_REPOSITORY_NAME: rubensa
DOCKER_IMAGE_NAME: ubuntu-tini-x11
DOCKER_IMAGE_TAG: latest
secrets: inherit
48 changes: 24 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,46 @@ RUN apt-get update

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

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

# 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}
#
# 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}

# 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; \
fi
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

# 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
#
# 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

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

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
Expand Down
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,29 @@ You can build the image like this:
```
#!/usr/bin/env bash
DOCKER_REPOSITORY_NAME="rubensa"
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
DOCKER_IMAGE_TAG="latest"
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
-t "rubensa/ubuntu-tini-x11" \
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
--label "maintainer=Ruben Suarez <[email protected]>" \
.
docker buildx build --load \
-t "rubensa/ubuntu-tini-x11" \
.
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
.
```

To make an Nvidia GPU available in the docker container, the following steps have to be taken:

```
#!/usr/bin/env bash
DOCKER_REPOSITORY_NAME="rubensa"
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
DOCKER_IMAGE_TAG="latest"
# NVidia propietary drivers are needed on host for this to work
NVIDIA_VERSION=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader)
Expand All @@ -34,11 +42,17 @@ prepare_docker_nvidia_drivers_version() {
prepare_docker_nvidia_drivers_version
docker build --no-cache \
-t "rubensa/ubuntu-tini-x11" \
# see: https://github.com/docker/buildx/issues/495#issuecomment-761562905
#docker buildx build --platform=linux/amd64,linux/arm64 --no-cache --progress=plain --pull \
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
--label "maintainer=Ruben Suarez <[email protected]>" \
${BUILD_ARGS} \
.
docker buildx build --load \
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
.
```

## Running
Expand All @@ -48,6 +62,10 @@ You can run the container like this (change --rm with -d if you don't want the c
```
#!/usr/bin/env bash
DOCKER_REPOSITORY_NAME="rubensa"
DOCKER_IMAGE_NAME="ubuntu-tini-dev"
DOCKER_IMAGE_TAG="latest"
# Get current user UID
USER_ID=$(id -u)
# Get current user main GUID
Expand Down Expand Up @@ -128,7 +146,7 @@ prepare_docker_printer_host_sharing() {
}
prepare_docker_ipc_host_sharing() {
# Allow shared memory to avoid RAM access failures and rendering glitches due to X extesnion MIT-SHM
# Allow shared memory to avoid RAM access failures and rendering glitches due to X extension MIT-SHM
EXTRA+=" --ipc=host"
}
Expand Down Expand Up @@ -171,15 +189,15 @@ prepare_docker_hostname_host_sharing
prepare_docker_nvidia_drivers_install
docker run --rm -it \
--name "ubuntu-tini-x11" \
--name "${DOCKER_IMAGE_NAME}" \
${SECURITY} \
${ENV_VARS} \
${DEVICES} \
${MOUNTS} \
${EXTRA} \
${RUNNER} \
${RUNNER_GROUPS} \
rubensa/ubuntu-tini-x11
"${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" "$@"
```

*NOTE*: Mounting /var/run/docker.sock allows host docker usage inside the container (docker-from-docker).
Expand All @@ -197,8 +215,10 @@ You can connect to the running container like this:
```
#!/usr/bin/env bash
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
docker exec -it \
ubuntu-tini-x11 \
"${DOCKER_IMAGE_NAME}" \
bash -l
```

Expand Down Expand Up @@ -255,8 +275,10 @@ You can stop the running container like this:
```
#!/usr/bin/env bash
docker stop \
ubuntu-tini-x11
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
docker stop \
"${DOCKER_IMAGE_NAME}"
```

## Start
Expand All @@ -266,8 +288,10 @@ If you run the container without --rm you can start it again like this:
```
#!/usr/bin/env bash
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
docker start \
ubuntu-tini-x11
"${DOCKER_IMAGE_NAME}"
```

## Remove
Expand All @@ -277,6 +301,8 @@ If you run the container without --rm you can remove once stopped like this:
```
#!/usr/bin/env bash
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
docker rm \
ubuntu-tini-x11
"${DOCKER_IMAGE_NAME}"
```
14 changes: 12 additions & 2 deletions build-custom.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

DOCKER_REPOSITORY_NAME="rubensa"
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
DOCKER_IMAGE_TAG="latest"

# NVidia propietary drivers are needed on host for this to work
NVIDIA_VERSION=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader)

Expand All @@ -10,8 +14,14 @@ prepare_docker_nvidia_drivers_version() {

prepare_docker_nvidia_drivers_version

docker build --no-cache \
-t "rubensa/ubuntu-tini-x11" \
# see: https://github.com/docker/buildx/issues/495#issuecomment-761562905
#docker buildx build --platform=linux/amd64,linux/arm64 --no-cache --progress=plain --pull \
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
--label "maintainer=Ruben Suarez <[email protected]>" \
${BUILD_ARGS} \
.

docker buildx build --load \
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
.
12 changes: 9 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/env bash

DOCKER_REPOSITORY_NAME="rubensa"
DOCKER_IMAGE_NAME="ubuntu-tini-x11"
DOCKER_IMAGE_TAG="latest"

# see: https://github.com/docker/buildx/issues/495#issuecomment-761562905
#docker buildx build --platform=linux/amd64,linux/arm64 --no-cache --progress=plain --pull \
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
-t "rubensa/ubuntu-tini-x11" \
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
--label "maintainer=Ruben Suarez <[email protected]>" \
.

docker buildx build --load \
-t "rubensa/ubuntu-tini-x11" \
.
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
.
4 changes: 3 additions & 1 deletion connect.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

DOCKER_IMAGE_NAME="ubuntu-tini-x11"

docker exec -it \
ubuntu-tini-x11 \
"${DOCKER_IMAGE_NAME}" \
bash -l
14 changes: 7 additions & 7 deletions install-nvidia-drivers.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env bash

if ! (set -o noclobber ; echo > /tmp/install-nvidia-drivers.lock) ; then
exit 1 # the install-nvidia-drivers.lock already exists
exit 1 # the install-nvidia-drivers.lock already exists
fi

# Install NVIDIA drivers if NVIDIA_VERSION is set and not previously installed
if [ ! -z ${NVIDIA_VERSION} ] && [ ! `command -v nvidia-smi` ]; then
echo "# Downloading NVIDIA drivers matching host version (${NVIDIA_VERSION})..."
curl -o nvidia.run -sSL http://us.download.nvidia.com/XFree86/Linux-x86_64/${NVIDIA_VERSION}/NVIDIA-Linux-x86_64-${NVIDIA_VERSION}.run
chmod +x nvidia.run
echo "# Installing NVIDIA drivers..."
sudo ./nvidia.run --ui=none --no-kernel-module --no-install-compat32-libs --install-libglvnd --no-questions
rm nvidia.run
echo "# Downloading NVIDIA drivers matching host version (${NVIDIA_VERSION})..."
curl -o nvidia.run -sSL http://us.download.nvidia.com/XFree86/Linux-x86_64/${NVIDIA_VERSION}/NVIDIA-Linux-x86_64-${NVIDIA_VERSION}.run
chmod +x nvidia.run
echo "# Installing NVIDIA drivers..."
sudo ./nvidia.run --ui=none --no-kernel-module --no-install-compat32-libs --install-libglvnd --no-questions
rm nvidia.run
fi

rm -f /tmp/install-nvidia-drivers.lock
4 changes: 3 additions & 1 deletion remove.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash

DOCKER_IMAGE_NAME="ubuntu-tini-x11"

docker rm \
ubuntu-tini-x11
"${DOCKER_IMAGE_NAME}"
11 changes: 7 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

DOCKER_REPOSITORY_NAME="rubensa"
DOCKER_IMAGE_NAME="ubuntu-tini-dev"
DOCKER_IMAGE_TAG="latest"

# Get current user UID
USER_ID=$(id -u)
# Get current user main GUID
Expand Down Expand Up @@ -80,7 +84,7 @@ prepare_docker_printer_host_sharing() {
}

prepare_docker_ipc_host_sharing() {
# Allow shared memory to avoid RAM access failures and rendering glitches due to X extesnion MIT-SHM
# Allow shared memory to avoid RAM access failures and rendering glitches due to X extension MIT-SHM
EXTRA+=" --ipc=host"
}

Expand Down Expand Up @@ -123,13 +127,12 @@ prepare_docker_hostname_host_sharing
prepare_docker_nvidia_drivers_install

docker run --rm -it \
--name "ubuntu-tini-x11" \
--name "${DOCKER_IMAGE_NAME}" \
${SECURITY} \
${ENV_VARS} \
${DEVICES} \
${MOUNTS} \
${EXTRA} \
${RUNNER} \
${RUNNER_GROUPS} \
rubensa/ubuntu-tini-x11

"${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" "$@"
6 changes: 4 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash

docker start -i \
ubuntu-tini-x11
DOCKER_IMAGE_NAME="ubuntu-tini-x11"

docker start \
"${DOCKER_IMAGE_NAME}"
6 changes: 4 additions & 2 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash

docker stop \
ubuntu-tini-x11
DOCKER_IMAGE_NAME="ubuntu-tini-x11"

docker stop \
"${DOCKER_IMAGE_NAME}"

0 comments on commit 1f7ab05

Please sign in to comment.