Skip to content

Commit

Permalink
Add aio-local-ai-cuda12 image based on local-ai nvidia-cuda12 docker …
Browse files Browse the repository at this point in the history
…image
  • Loading branch information
luzfcb committed Dec 21, 2024
1 parent d597c9f commit 7df3b1a
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 5 deletions.
107 changes: 104 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ on:
description: "Tag name"
required: true
default: 'v2'
buildCPU:
description: "Build and push CPU image"
type: boolean
required: true
default: true
buildGPU:
description: "Build and push GPU image"
type: boolean
required: true
default: true

jobs:
push_to_registry:
push_cpu_image_to_registry:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.buildCPU == 'true' }}

name: Build docker image and push to dockerhub
name: Build docker CPU image and push to dockerhub

steps:
- name: Release space from worker
Expand Down Expand Up @@ -64,7 +75,7 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build container image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
Expand All @@ -73,3 +84,93 @@ jobs:
file: 'Dockerfile'
tags: szaimen/aio-local-ai:${{ github.event.inputs.tagName }}
provenance: false

push_gpu_image_to_registry:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.buildGPU == 'true' }}

name: Build docker GPU image and push to dockerhub

steps:
- name: Release space from worker
run: |
echo "Listing top largest packages"
pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr)
head -n 30 <<< "${pkgs}"
echo "Available storage before:"
sudo df -h
echo
sudo apt-get remove -y '^llvm-.*|^libllvm.*' || true
sudo apt-get remove --auto-remove android-sdk-platform-tools || true
sudo apt-get purge --auto-remove android-sdk-platform-tools || true
sudo rm -rf /usr/local/lib/android
sudo apt-get purge -y '^dotnet-.*|^aspnetcore-.*' || true
sudo apt-get purge -y '^temurin-.*|^ca-certificates-java.*' || true
sudo apt-get purge -y '^libclang-.*' || true
sudo rm -rf /usr/share/dotnet
sudo apt-get purge -y '^mono-.*' || true
sudo apt-get purge -y '^ghc-.*' || true
sudo apt-get purge -y '.*jdk.*|.*jre.*' || true
sudo apt-get purge -y 'php.*' || true
sudo apt-get purge -y hhvm powershell firefox monodoc-manual msbuild || true
sudo apt-get purge -y '^google-.*' || true
sudo apt-get purge -y azure-cli || true
sudo apt-get purge -y '^mongo.*-.*|^postgresql-.*|^mysql-.*|^mssql-.*' || true
sudo apt-get purge -y '^gfortran-.*' || true
sudo apt-get purge -y '^microsoft-edge-stable.*|^firefox.*|powershell.*' || true
sudo apt-get autoremove -y
sudo apt-get clean
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /opt/hostedtoolcache/CodeQL || true
echo
echo "Listing top largest packages"
pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr)
head -n 30 <<< "${pkgs}"
echo
sudo rm -rfv build || true
echo "Available storage after:"
df -h
- name: Release space from worker
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 50000
swap-size-mb: 1024
- name: Available storage after
run: df -h
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build container image
uses: docker/build-push-action@v6
with:
push: false
platforms: linux/amd64
context: './'
no-cache: true
file: 'Dockerfile.cuda12'
tags: szaimen/aio-local-ai-cuda12:${{ github.event.inputs.tagName }}
provenance: false

- name: Push container image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64
context: './'
no-cache: true
file: 'Dockerfile.cuda12'
tags: szaimen/aio-local-ai-cuda12:${{ github.event.inputs.tagName }}
provenance: false
2 changes: 1 addition & 1 deletion .github/workflows/docker-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: run lint
run: |
DOCKERFILES="$(find ./ -name Dockerfile)"
DOCKERFILES="$(find ./ -name 'Dockerfile*')"
mapfile -t DOCKERFILES <<< "$DOCKERFILES"
for file in "${DOCKERFILES[@]}"; do
# DL4006 warning: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# From https://github.com/go-skynet/LocalAI/blob/master/Dockerfile
# From https://github.com/mudler/LocalAI/blob/master/Dockerfile
FROM quay.io/go-skynet/local-ai:v2.24.2-aio-cpu

COPY --chmod=775 start.sh /start.sh
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile.cuda12
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# From https://github.com/mudler/LocalAI/blob/master/Dockerfile
FROM quay.io/go-skynet/local-ai:v2.24.2-aio-gpu-nvidia-cuda-12

COPY --chmod=775 start.sh /start.sh

# hadolint ignore=DL3008
RUN set -ex; \
\
export DEBIAN_FRONTEND=noninteractive; \
apt-get update; \
apt-get install -y --no-install-recommends \
netcat-openbsd \
; \
rm -rf /var/lib/apt/lists/*

# hadolint ignore=DL3002
USER root
ENTRYPOINT [ "/start.sh" ]
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# a quick way to build and run the docker image
services:
cpu:
build:
context: .
dockerfile: Dockerfile
image: szaimen/aio-local-ai:v2

cuda12:
build:
context: .
dockerfile: Dockerfile.cuda12
image: szaimen/aio-local-ai-cuda12:v2
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
27 changes: 27 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ else
echo "CPU: no AVX512 found"
fi

echo -e "\nGPU info:"
echo " Note: Detecting a GPU does not guarantee compatibility with Local-AI. "
echo -e " For more details on supported GPUs and requirements, please refer to the documentation.\n"

# Filter only GPU-related devices using device class codes (0300, 0302, 0380)
if command -v lspci &>/dev/null; then
echo "Detected GPUs:"
lspci -nn | awk '/\[030[02|80]\]/'
else
echo " 'lspci' not available to detect GPUs."
fi


if command -v nvidia-smi &>/dev/null; then
echo -e "\nDetected NVIDIA GPUs:"
nvidia-smi
else
echo -e "\n NVIDIA GPU not detected or 'nvidia-smi' is not installed."
echo " To enable NVIDIA GPU support, please ensure the following:"
echo " 1. Install the Nvidia Container Toolkit on the Docker host machine."
echo " Refer to the official Nvidia Container Toolkit documentation for installation instructions."
echo " 2. Use the 'aio-local-ai-cuda12' Docker image, specifically designed for Nvidia GPU support."
echo " 3. Run the container with the '--gpus all' flag to allocate GPU resources."
echo -e " For more details, please consult the Nextcloud Local-AI community container documentation.\n"
fi


while ! nc -z nextcloud-aio-nextcloud 9001; do
echo "Waiting for nextcloud to start"
sleep 5
Expand Down

0 comments on commit 7df3b1a

Please sign in to comment.