Skip to content

Commit

Permalink
feat: allow building Docker image without vllm
Browse files Browse the repository at this point in the history
- Simplify build process by bundling ppa key
- Add new BUILD_WITH_VLLM build-arg
- Add `make local_build` option
- Build ffmpeg in the builder image
- Build ffmpeg using all available cores
- Remove no longer needed dependencies
  • Loading branch information
saghul committed Feb 10, 2025
1 parent 72b1d0e commit d76a928
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 52 deletions.
71 changes: 27 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
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

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

Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -66,52 +64,38 @@ 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
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 \
Expand All @@ -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" ]

Expand Down
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
.
2 changes: 1 addition & 1 deletion docker/rootfs/etc/apt/sources.list.d/python-ppa.list
Original file line number Diff line number Diff line change
@@ -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
Binary file added docker/rootfs/opt/python-ppa.gpg
Binary file not shown.

0 comments on commit d76a928

Please sign in to comment.