Skip to content

Commit

Permalink
fix(docker): fix minor bugs in dockerfiles for concurrency and nvidia…
Browse files Browse the repository at this point in the history
… gpus
  • Loading branch information
rishikanthc committed Oct 20, 2024
1 parent c17d27b commit ddb8079
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 64 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ARG OPENAI_MODEL="gpt-4"
ARG OPENAI_ROLE="system"
ARG POCKETBASE_VERSION=0.22.21
ARG DEV_MODE
ARG NVIDIA
ARG CONCURRENCY

ENV POCKETBASE_ADMIN_EMAIL=$POCKETBASE_ADMIN_EMAIL
ENV POCKETBASE_ADMIN_PASSWORD=$POCKETBASE_ADMIN_PASSWORD

Check warning on line 45 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "POCKETBASE_ADMIN_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
Expand All @@ -51,6 +53,8 @@ ENV OPENAI_ROLE=$OPENAI_ROLE
ENV BODY_SIZE_LIMIT=512M
ENV DEV_MODE=$DEV_MODE
ENV POCKETBASE_URL=$POCKETBASE_URL
ENV NVIDIA=$NVIDIA
ENV CONCURRENCY=$CONCURRENCY
# ENV LD_PRELOAD=/usr/local/lib/python3.8/dist-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0

RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs
Expand Down
100 changes: 38 additions & 62 deletions Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# Start from NVIDIA CUDA Ubuntu image for GPU support
FROM nvidia/cuda:12.2.0-devel-ubuntu22.04 AS build_whisper

# Install necessary build tools and dependencies for Whisper
RUN apt-get update && \
apt-get install -y build-essential \
ca-certificates \
git && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

# Clone and build Whisper.cpp
WORKDIR /app
RUN git clone https://github.com/ggerganov/whisper.cpp.git

WORKDIR /app/whisper.cpp
# Compile Whisper.cpp with make
RUN GGML_CUDA=1 make -j

# Use the NVIDIA CUDA base image with Ubuntu
FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS base

# Add AudioWaveform via PPA and install necessary tools
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:chris-needham/ppa && \
apt-get update && \
apt-get install -y audiowaveform ffmpeg libgd3 libmad0 libid3tag0 libsndfile1 zlib1g wget python3-pip \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables to make the installation non-interactive
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ="Etc/UTC"

RUN apt-get update && apt-get install -y \
python3 \
python3-dev \
python3-pip \
software-properties-common \
tzdata \
ffmpeg \
curl \
unzip \
git

# Add the required PPA for audiowaveform
RUN add-apt-repository ppa:chris-needham/ppa \
&& apt-get update \
&& apt-get install -y audiowaveform

# Clean up the apt cache to reduce image size
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Environment variables for PocketBase, Redis, OpenAI, and others
ARG POCKETBASE_ADMIN_EMAIL
ARG POCKETBASE_ADMIN_PASSWORD
ARG POCKETBASE_URL
ARG SCRIBO_FILES
ARG REDIS_HOST
ARG REDIS_PORT
ARG OPENAI_API_KEY
ARG OPENAI_ENDPOINT="https://api.openai.com/v1"
ARG OPENAI_ENDPOINT=https://api.openai.com/v1
ARG OPENAI_MODEL="gpt-4"
ARG OPENAI_ROLE="system"

# Set environment variables to be overridden at runtime
ARG POCKETBASE_VERSION=0.22.21
ARG DEV_MODE
ARG NVIDIA
ARG CONCURRENCY

ENV POCKETBASE_ADMIN_EMAIL=$POCKETBASE_ADMIN_EMAIL
ENV POCKETBASE_ADMIN_PASSWORD=$POCKETBASE_ADMIN_PASSWORD
ENV SCRIBO_FILES=$SCRIBO_FILES
Expand All @@ -49,49 +49,25 @@ ENV OPENAI_ENDPOINT=$OPENAI_ENDPOINT
ENV OPENAI_MODEL=$OPENAI_MODEL
ENV OPENAI_ROLE=$OPENAI_ROLE
ENV BODY_SIZE_LIMIT=512M
ENV DEV_MODE=$DEV_MODE
ENV POCKETBASE_URL=$POCKETBASE_URL
ENV NVIDIA=$NVIDIA
ENV CONCURRENCY=$CONCURRENCY
# ENV LD_PRELOAD=/usr/local/lib/python3.8/dist-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0

RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs


# Install additional packages and dependencies
RUN apt-get update && apt-get install -y curl unzip wget

# Download and unzip PocketBase dynamically based on architecture
ENV POCKETBASE_VERSION=0.22.21
RUN if [ "$(uname -m)" = "aarch64" ]; then \
ARCH="arm64"; \
else \
ARCH="amd64"; \
fi && \
curl -L "https://github.com/pocketbase/pocketbase/releases/download/v${POCKETBASE_VERSION}/pocketbase_${POCKETBASE_VERSION}_linux_${ARCH}.zip" -o /tmp/pb.zip

RUN unzip /tmp/pb.zip pocketbase -d /usr/local/bin/ && rm /tmp/pb.zip

# Install pyannote
RUN python3 -m pip install pyannote.audio

# Copy the whisper.cpp binary from the build stage
COPY --from=build_whisper /app/whisper.cpp/main /usr/local/bin/whisper
COPY --from=build_whisper /app/whisper.cpp/models/download-ggml-model.sh /usr/local/bin/download-ggml-model.sh

# Download Whisper models
WORKDIR /models
RUN download-ggml-model.sh base.en /models && \
download-ggml-model.sh tiny.en /models && \
download-ggml-model.sh small.en /models

# Set the working directory for the application
WORKDIR /app

# Copy application files
COPY . .

# Install Node.js and dependencies
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs
RUN git clone https://github.com/ggerganov/whisper.cpp.git

# RUN apt install nodejs && apt install npm
RUN npm ci

# Expose necessary ports
EXPOSE 3000 8080 9243

# Start the services
CMD ["/bin/sh", "/app/start_services.sh"]

2 changes: 1 addition & 1 deletion src/lib/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const worker = new Worker(
},
{
connection: { host: env.REDIS_HOST, port: env.REDIS_PORT }, // Redis connection
concurrency: 5 // Allows multiple jobs to run concurrently
concurrency: env.CONCURRENCY // Allows multiple jobs to run concurrently
}
);

Expand Down
8 changes: 7 additions & 1 deletion src/lib/wizardQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ const worker = new Worker(
cmd = `make clean -C ${modelPath}`
await execCommandWithLogging(cmd, job);

cmd = `make -C ${modelPath}`;
const isNvidia= env.NVIDIA === 'true' || env.NVIDIA === true;

if (isNvidia) {
cmd = `GGML_CUDA=1 make -j -C ${modelPath}`;
} else {
cmd = `make -C ${modelPath}`;
}
await execCommandWithLogging(cmd, job);
await job.log('finished making whisper')
job.updateProgress(50)
Expand Down

0 comments on commit ddb8079

Please sign in to comment.