Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the new aio-local-ai-cuda12 image based on nvidia-cuda12 locai-ai docker image #52

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 2.1

jobs:
build-and-push:
parameters:
tag-name:
type: string
default: "v2"
machine:
image: ubuntu-2404:2024.08.1
docker_layer_caching: true
resource_class: medium
environment:
DOCKER_BUILDKIT: 1
steps:
- checkout

- run:
name: Show disk usage (1st time)
command: |
df -h

- run:
name: Pull base GPU image (from Dockerfile.cuda12)
command: |
BASE_GPU_IMAGE=$(awk '/^FROM / {print $2}' Dockerfile.cuda12)
echo "Base GPU image found: $BASE_GPU_IMAGE"
echo "Pulling Docker image: $BASE_GPU_IMAGE"
docker pull "$BASE_GPU_IMAGE"

- run:
name: Show disk usage (2nd time)
command: |
df -h

- run:
name: Build Docker image (no-cache)
command: |
echo "Building Docker image with tag: << parameters.tag-name >>"
docker build \
--platform linux/amd64 \
-f Dockerfile.cuda12 \
-t "luzfcb/aio-local-ai-cuda12:<< parameters.tag-name >>" \
.
- run:
name: Show disk usage (3nd time)
command: |
df -h
- run:
name: Push Docker image to Docker Hub
command: |
# Assumes you've set DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD as environment variables in CircleCI
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
echo "Pushing image: luzfcb/aio-local-ai-cuda12:<< parameters.tag-name >>"
docker push "luzfcb/aio-local-ai-cuda12:<< parameters.tag-name >>"


workflows:
build-and-push-workflow:
jobs:
- build-and-push:
tag-name: "v2" # OPTIONAL: override default if desired
172 changes: 168 additions & 4 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,12 +75,165 @@ 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
context: './'
no-cache: true
file: 'Dockerfile'
tags: szaimen/aio-local-ai:${{ github.event.inputs.tagName }}
tags: luzfcb/aio-local-ai:${{ github.event.inputs.tagName }}
provenance: false

push_gpu_image_to_registry:
runs-on: ubuntu-22.04
environment: "DockerHubAccess"
if: ${{ github.event.inputs.buildGPU == 'true' }}

name: Build docker GPU image and push to dockerhub

steps:
- name: Available storage before
run: df -h


- name: Maximize build space
uses: AdityaGarg8/[email protected]
with:
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
remove-large-packages: 'true'
remove-cached-tools: 'true'
remove-swapfile: 'true'
- name: Available storage after
run: df -h


- 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 50 <<< "${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 50 <<< "${pkgs}"
echo
sudo rm -rfv build || true
sudo docker system prune --all --volumes --force || true
echo "Available storage after:"
df -h

- 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: Available storage before build
run: df -h

- name: Extract Base GPU Docker Image name
id: extract-image
run: |
BASE_GPU_IMAGE=$(awk '/^FROM / {print $2}' Dockerfile.cuda12)
echo "Base GPU image found: $BASE_GPU_IMAGE"
echo "BASE_GPU_IMAGE=$BASE_GPU_IMAGE" >> $GITHUB_ENV

- name: Pull Base Docker Image
run: |
echo "Pulling Docker image: $BASE_GPU_IMAGE"
docker pull "$BASE_GPU_IMAGE"
env:
BASE_GPU_IMAGE: ${{ env.BASE_GPU_IMAGE }}

- name: Create a TMPDIR for docker build on a different disk
run: |
mkdir -p /tmp/docker-build
export TMPDIR=/tmp/docker-build
echo "TMPDIR=$TMPDIR" >> $GITHUB_ENV

- name: Available storage before build
run: df -h

- name: Verify Docker image size
uses: luzfcb/docker-image-size-limit@master
with:
image: "${{ env.BASE_GPU_IMAGE }}"
size: "47GB"
show_current_size: true
dry_run: true


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

- name: Verify Docker image size
uses: luzfcb/docker-image-size-limit@master
with:
image: "luzfcb/aio-local-ai-cuda12:${{ github.event.inputs.tagName }}"
size: "47GB"
show_current_size: true
dry_run: true

- name: Available storage after build
run: df -h

- name: Push container image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64
context: './'
file: 'Dockerfile.cuda12'
tags: luzfcb/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" ]
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# a quick way to build and run the docker image
services:
cpu:
build:
context: .
dockerfile: Dockerfile
image: szaimen/aio-local-ai:v2

cuda12:
build:
platforms:
- linux/amd64
context: .
dockerfile: Dockerfile.cuda12
image: luzfcb/aio-local-ai-cuda12:v2
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
35 changes: 35 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 '/\[03(00|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 All @@ -33,6 +60,14 @@ done
set -x
THREADS="$(nproc)"
export THREADS

# enable GPU
LOCALAI_F16=true
export LOCALAI_F16


set +x



./local-ai --preload-models-config "/nextcloud/admin/files/nextcloud-aio-local-ai/models.yaml"
Loading