diff --git a/Dockerfile b/Dockerfile index 61c58a3..e005d25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ ARG BASE_IMAGE_BUILD=nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04 ARG BASE_IMAGE_RUN=nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04 +ARG BUILD_WITH_VLLM=1 ## Base Image @@ -7,17 +8,15 @@ FROM ${BASE_IMAGE_BUILD} AS builder RUN \ apt-get update && \ - apt-get install -y apt-transport-https ca-certificates gnupg git + apt-get install -y apt-transport-https ca-certificates COPY docker/rootfs/ / RUN \ - apt-dpkg-wrap apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys F23C5A6CF475977595C89F51BA6932366A755776 && \ apt-dpkg-wrap apt-get update && \ - apt-dpkg-wrap apt-get install -y build-essential libcurl4-openssl-dev python3.11 python3.11-venv && \ - apt-cleanup + apt-dpkg-wrap apt-get install -y build-essential python3.11 python3.11-venv -COPY requirements-vllm.txt /app/ +COPY requirements*.txt /app/ WORKDIR /app @@ -26,23 +25,23 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=on RUN \ python3.11 -m venv .venv && \ . .venv/bin/activate && \ - pip install -vvv -r requirements-vllm.txt + if [ "${BUILD_WITH_VLLM}" = "1" ]; then \ + echo "Building with VLLM"; \ + pip install -vvv -r requirements-vllm.txt; \ + else \ + echo "Building without VLLM"; \ + pip install -vvv -r requirements.txt; \ + fi ## Build ffmpeg -FROM ${BASE_IMAGE_RUN} AS ffmpeg_install - -COPY docker/rootfs/ / +FROM builder AS ffmpeg_builder # ffmpeg build dependencies RUN \ - apt-dpkg-wrap apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys F23C5A6CF475977595C89F51BA6932366A755776 && \ - apt-dpkg-wrap apt-get update && \ apt-dpkg-wrap apt-get install -y \ autoconf \ automake \ - build-essential \ - cmake \ libopus-dev \ libopus0 \ libtool \ @@ -51,8 +50,7 @@ RUN \ wget \ yasm \ zlib1g \ - zlib1g-dev && \ - apt-cleanup + zlib1g-dev # Build ffmpeg6 (required for pytorch which only supports ffmpeg < v7) RUN \ @@ -66,39 +64,31 @@ RUN \ --enable-shared \ --enable-gpl \ --enable-libopus && \ - make && \ + JOBS="$(nproc)" && \ + make -j "${JOBS}" && \ make install && \ ldconfig -RUN \ - apt-dpkg-wrap apt-get autoremove -y \ - autoconf \ - automake \ - build-essential \ - cmake \ - libopus-dev \ - libtool \ - pkg-config \ - texinfo \ - wget \ - yasm \ - zlib1g-dev - ## Production Image -FROM ffmpeg_install +FROM ${BASE_IMAGE_RUN} + +COPY --chown=jitsi:jitsi docker/run-skynet.sh /opt/ +COPY --from=ffmpeg_builder /usr/local/include /usr/local/include +COPY --from=ffmpeg_builder /usr/local/lib/lib* /usr/local/lib/ +COPY --from=ffmpeg_builder /usr/local/lib/pkgconfig /usr/local/lib/pkgconfig +COPY --chown=jitsi:jitsi --from=builder /app/.venv /app/.venv +COPY --chown=jitsi:jitsi /skynet /app/skynet/ RUN \ apt-get update && \ - apt-get install -y apt-transport-https ca-certificates gnupg + apt-get install -y apt-transport-https ca-certificates COPY docker/rootfs/ / -COPY --chown=jitsi:jitsi docker/run-skynet.sh /opt/ RUN \ - apt-dpkg-wrap apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys F23C5A6CF475977595C89F51BA6932366A755776 && \ - apt-dpkg-wrap apt-get update && \ - apt-dpkg-wrap apt-get install -y python3.11 python3.11-venv tini libgomp1 strace gdb && \ + apt-get update && \ + apt-dpkg-wrap apt-get install -y python3.11 python3.11-venv tini libgomp1 libopus0 zlib1g strace gdb && \ apt-cleanup # Principle of least privilege: create a new user for running the application @@ -106,12 +96,6 @@ RUN \ groupadd -g 1001 jitsi && \ useradd -r -u 1001 -g jitsi jitsi -# Copy virtual environment -COPY --chown=jitsi:jitsi --from=builder /app/.venv /app/.venv - -# Copy application files -COPY --chown=jitsi:jitsi /skynet /app/skynet/ - ENV \ # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED PYTHONUNBUFFERED=1 \ @@ -120,8 +104,7 @@ ENV \ PYTHONPATH=/app \ OUTLINES_CACHE_DIR=/app/vllm/outlines \ VLLM_CONFIG_ROOT=/app/vllm/config \ - HF_HOME=/app/hf \ - LLAMA_PATH="/models/Llama-3.1-8B-Instruct-Q8_0.gguf" + HF_HOME=/app/hf VOLUME [ "/models" ] diff --git a/Makefile b/Makefile index c2868fd..f569b7e 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,21 @@ _login: build : _login docker buildx build \ - --progress plain \ - --push \ - --platform ${PLATFORMS} \ - -t ${IMAGE_REGISTRY}/skynet:summaries-${GIT_HASH} \ - -t ${IMAGE_REGISTRY}/skynet:whisper-${GIT_HASH} \ - -t ${IMAGE_REGISTRY}/skynet:${GIT_HASH} \ - -t ${IMAGE_REGISTRY}/skynet:latest . + --progress plain \ + --push \ + --platform ${PLATFORMS} \ + -t ${IMAGE_REGISTRY}/skynet:summaries-${GIT_HASH} \ + -t ${IMAGE_REGISTRY}/skynet:whisper-${GIT_HASH} \ + -t ${IMAGE_REGISTRY}/skynet:${GIT_HASH} \ + -t ${IMAGE_REGISTRY}/skynet:latest \ + . + +local_build: + docker buildx build \ + --progress plain \ + --load \ + --build-arg BASE_IMAGE_BUILD=ubuntu:22.04 \ + --build-arg BASE_IMAGE_RUN=ubuntu:22.04 \ + --build-arg BUILD_WITH_VLLM=0 \ + -t jitsi/skynet:latest \ + . diff --git a/docker/rootfs/etc/apt/sources.list.d/python-ppa.list b/docker/rootfs/etc/apt/sources.list.d/python-ppa.list index 75a8bab..57887d9 100644 --- a/docker/rootfs/etc/apt/sources.list.d/python-ppa.list +++ b/docker/rootfs/etc/apt/sources.list.d/python-ppa.list @@ -1 +1 @@ -deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy main +deb [signed-by=/opt/python-ppa.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy main diff --git a/docker/rootfs/opt/python-ppa.gpg b/docker/rootfs/opt/python-ppa.gpg new file mode 100644 index 0000000..058890d Binary files /dev/null and b/docker/rootfs/opt/python-ppa.gpg differ