diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 395bfec..bfa6236 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/docker-lint.yml b/.github/workflows/docker-lint.yml index 422899a..be64fcd 100644 --- a/.github/workflows/docker-lint.yml +++ b/.github/workflows/docker-lint.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6ef218 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea + diff --git a/Dockerfile b/Dockerfile index 256c038..37bf1d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Dockerfile.cuda12 b/Dockerfile.cuda12 new file mode 100644 index 0000000..b5b8edb --- /dev/null +++ b/Dockerfile.cuda12 @@ -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" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3fcf77e --- /dev/null +++ b/docker-compose.yml @@ -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] \ No newline at end of file diff --git a/start.sh b/start.sh index d408f53..51dbb4e 100644 --- a/start.sh +++ b/start.sh @@ -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