Skip to content

Commit

Permalink
Add multiarch (linux/amd64,linux/arm64) support
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensa committed May 31, 2022
1 parent 9637b53 commit 4a9e34e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v2

# Allow Buildx multi-platform builds
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

# Setup Buildx as the builder
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

# Avoid having to re-download docker images and reduces the number of pulls against Docker Hub
# https://github.com/actions/cache
- name: Cache Docker layers
uses: actions/cache@v2
with:
Expand All @@ -37,19 +45,22 @@ jobs:
${{ runner.os }}-buildx-
# Use Personal Access Token (PAT) and username to log into Docker Hub
# https://github.com/docker/login-action
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# Build and push action
# https://github.com/docker/build-push-action
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/ubuntu-tini-x11:latest
Expand Down
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM rubensa/ubuntu-tini-dev
LABEL author="Ruben Suarez <[email protected]>"

# Architecture component of TARGETPLATFORM (platform of the build result)
ARG TARGETARCH

# If defined, install specified NVIDIA driver version
ARG NVIDIA_VERSION

Expand Down Expand Up @@ -41,14 +44,14 @@ RUN echo "# Configuring '${USER_NAME}' for X11 functionallity..." \
&& usermod -a -G video ${USER_NAME}

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

# Add script to allow nvidia drivers installation on user interactive session
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ You can build the image like this:
```
#!/usr/bin/env bash
docker build --no-cache \
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
-t "rubensa/ubuntu-tini-x11" \
--label "maintainer=Ruben Suarez <[email protected]>" \
.
docker buildx build --load \
-t "rubensa/ubuntu-tini-x11" \
.
```

To make an Nvidia GPU available in the docker container, the following steps have to be taken:
Expand Down
6 changes: 5 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash

docker build --no-cache \
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
-t "rubensa/ubuntu-tini-x11" \
--label "maintainer=Ruben Suarez <[email protected]>" \
.

docker buildx build --load \
-t "rubensa/ubuntu-tini-x11" \
.

0 comments on commit 4a9e34e

Please sign in to comment.