From 1f7ab0543fc1b3aec05c77bbb36d987292a4f099 Mon Sep 17 00:00:00 2001 From: Ruben Suarez Alvarez Date: Tue, 6 Sep 2022 15:57:14 +0200 Subject: [PATCH] Add DOCKER_REPOSITORY_NAME to reusable workflow Use variables for Docker image name --- .github/workflows/main.yml | 1 + Dockerfile | 48 +++++++++++++++++------------------ README.md | 52 ++++++++++++++++++++++++++++---------- build-custom.sh | 14 ++++++++-- build.sh | 12 ++++++--- connect.sh | 4 ++- install-nvidia-drivers.sh | 14 +++++----- remove.sh | 4 ++- run.sh | 11 +++++--- start.sh | 6 +++-- stop.sh | 6 +++-- 11 files changed, 113 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60f5dde..4bf1605 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index c3fb753..1eff428 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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= diff --git a/README.md b/README.md index 54590a8..80c8e7f 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,18 @@ 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 " \ . 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: @@ -24,6 +28,10 @@ To make an Nvidia GPU available in the docker container, the following steps hav ``` #!/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) @@ -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 " \ ${BUILD_ARGS} \ . + +docker buildx build --load \ + -t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \ + . ``` ## Running @@ -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 @@ -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" } @@ -171,7 +189,7 @@ 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} \ @@ -179,7 +197,7 @@ docker run --rm -it \ ${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). @@ -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 ``` @@ -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 @@ -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 @@ -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}" ``` diff --git a/build-custom.sh b/build-custom.sh index 5f2e6b4..d252543 100755 --- a/build-custom.sh +++ b/build-custom.sh @@ -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) @@ -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 " \ ${BUILD_ARGS} \ . + +docker buildx build --load \ + -t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \ + . diff --git a/build.sh b/build.sh index c3214c3..32b8169 100755 --- a/build.sh +++ b/build.sh @@ -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 " \ . docker buildx build --load \ - -t "rubensa/ubuntu-tini-x11" \ - . \ No newline at end of file + -t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \ + . diff --git a/connect.sh b/connect.sh index f18d317..a900d9e 100755 --- a/connect.sh +++ b/connect.sh @@ -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 diff --git a/install-nvidia-drivers.sh b/install-nvidia-drivers.sh index c7c5dd2..083b11e 100644 --- a/install-nvidia-drivers.sh +++ b/install-nvidia-drivers.sh @@ -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 \ No newline at end of file diff --git a/remove.sh b/remove.sh index 547fda9..d509123 100755 --- a/remove.sh +++ b/remove.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +DOCKER_IMAGE_NAME="ubuntu-tini-x11" + docker rm \ - ubuntu-tini-x11 + "${DOCKER_IMAGE_NAME}" diff --git a/run.sh b/run.sh index ae9559d..1089f75 100755 --- a/run.sh +++ b/run.sh @@ -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 @@ -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" } @@ -123,7 +127,7 @@ 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} \ @@ -131,5 +135,4 @@ docker run --rm -it \ ${EXTRA} \ ${RUNNER} \ ${RUNNER_GROUPS} \ - rubensa/ubuntu-tini-x11 - \ No newline at end of file + "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" "$@" diff --git a/start.sh b/start.sh index 820268b..1d23dcc 100755 --- a/start.sh +++ b/start.sh @@ -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}" diff --git a/stop.sh b/stop.sh index ad53f00..a47d592 100755 --- a/stop.sh +++ b/stop.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash -docker stop \ - ubuntu-tini-x11 +DOCKER_IMAGE_NAME="ubuntu-tini-x11" + +docker stop \ + "${DOCKER_IMAGE_NAME}"