mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
Reduce docker image size
This commit is contained in:
@@ -1,67 +1,72 @@
|
|||||||
# Phase 1: Pull prebuilt binaries
|
# --- Stage 1: Build Environment (The "Heavy" Stage) ---
|
||||||
FROM ghcr.io/ggml-org/llama.cpp:full-cuda AS llama-bin
|
FROM nvidia/cuda:12.6.3-devel-ubuntu24.04 AS builder
|
||||||
|
|
||||||
# Phase 2: Building environment
|
|
||||||
FROM nvidia/cuda:12.6.3-devel-ubuntu24.04
|
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND=noninteractive \
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
CMAKE_GENERATOR=Ninja \
|
CMAKE_GENERATOR=Ninja
|
||||||
APP_ROOT=/workspace/app \
|
|
||||||
BUILD_DIR=/workspace/app/build
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
build-essential \
|
build-essential ca-certificates curl git libboost-json-dev \
|
||||||
ca-certificates \
|
libboost-program-options-dev libssl-dev ninja-build pkg-config zlib1g-dev \
|
||||||
curl \
|
|
||||||
git \
|
|
||||||
libboost-json-dev \
|
|
||||||
libboost-program-options-dev \
|
|
||||||
libssl-dev \
|
|
||||||
ninja-build \
|
|
||||||
pkg-config \
|
|
||||||
zlib1g-dev \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install modern CMake via curl (Ubuntu 24.04 'apt' version can be laggy)
|
# Install modern CMake
|
||||||
RUN curl -L https://github.com/Kitware/CMake/releases/download/v3.31.0/cmake-3.31.0-linux-x86_64.sh -o cmake.sh && \
|
RUN curl -L https://github.com/Kitware/CMake/releases/download/v3.31.0/cmake-3.31.0-linux-x86_64.sh -o cmake.sh && \
|
||||||
sh cmake.sh --skip-license --prefix=/usr/local && rm cmake.sh
|
sh cmake.sh --skip-license --prefix=/usr/local && rm cmake.sh
|
||||||
|
|
||||||
# Copy backends to /usr/local/lib and register with ldconfig so the
|
# Get headers for C++ build
|
||||||
# runtime linker can resolve libllama.so, libggml.so, libggml-base.so etc.
|
|
||||||
COPY --from=llama-bin /app/lib*.so* /usr/local/lib/
|
|
||||||
RUN ldconfig
|
|
||||||
|
|
||||||
# Headers for C++ Build
|
|
||||||
RUN curl -L https://github.com/ggml-org/llama.cpp/archive/refs/tags/b9012.tar.gz -o /tmp/llama-src.tar.gz && \
|
RUN curl -L https://github.com/ggml-org/llama.cpp/archive/refs/tags/b9012.tar.gz -o /tmp/llama-src.tar.gz && \
|
||||||
tar -xzf /tmp/llama-src.tar.gz -C /tmp && \
|
tar -xzf /tmp/llama-src.tar.gz -C /tmp && \
|
||||||
cp -r /tmp/llama.cpp-b9012/include/* /usr/local/include/ && \
|
cp -r /tmp/llama.cpp-b9012/include/* /usr/local/include/ && \
|
||||||
cp -r /tmp/llama.cpp-b9012/ggml/include/* /usr/local/include/ && \
|
cp -r /tmp/llama.cpp-b9012/ggml/include/* /usr/local/include/
|
||||||
rm -rf /tmp/llama-src.tar.gz /tmp/llama.cpp-b9012
|
|
||||||
|
|
||||||
ENV LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
|
# Pull llama.cpp binaries to use during build if needed
|
||||||
|
COPY --from=ghcr.io/ggml-org/llama.cpp:full-cuda /app/lib*.so* /usr/local/lib/
|
||||||
|
|
||||||
WORKDIR /workspace/app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the C++ pipeline
|
# Build the C++ pipeline
|
||||||
RUN cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release && \
|
RUN cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release && \
|
||||||
cmake --build build -j$(nproc)
|
cmake --build build -j$(nproc)
|
||||||
|
|
||||||
# Co-locate GGML backend plugins with the executable.
|
# --- Stage 2: Runtime Environment (The "Slim" Stage) ---
|
||||||
# ggml_backend_load_all() searches the executable directory first when
|
FROM nvidia/cuda:12.6.3-runtime-ubuntu24.04 AS runtime
|
||||||
# GGML_BACKEND_DIR is not set. Copying the ggml-*.so plugin files here
|
|
||||||
# ensures the loader finds them without any environment variable.
|
|
||||||
|
|
||||||
# libllama.so, libggml.so, and libggml-base.so are NOT copied here —
|
# Install only necessary runtime shared libraries
|
||||||
# those are proper shared libraries resolved via ldconfig/LD_LIBRARY_PATH.
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
RUN cp /usr/local/lib/libggml-cuda.so /workspace/app/build/ 2>/dev/null || true && \
|
curl \
|
||||||
cp /usr/local/lib/libggml-cpu*.so /workspace/app/build/ 2>/dev/null || true && \
|
ca-certificates \
|
||||||
cp /usr/local/lib/libggml-blas*.so /workspace/app/build/ 2>/dev/null || true && \
|
libboost-json1.83.0 \
|
||||||
cp /usr/local/lib/libggml-rpc*.so /workspace/app/build/ 2>/dev/null || true
|
libboost-program-options1.83.0 \
|
||||||
|
libgomp1 \
|
||||||
|
libssl3 \
|
||||||
|
zlib1g \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
ENV APP_ROOT=/app \
|
||||||
|
LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
|
||||||
|
|
||||||
|
WORKDIR /app/build
|
||||||
|
|
||||||
|
# Copy only the compiled binaries from the builder
|
||||||
|
COPY --from=builder /app/build/biergarten-pipeline ./
|
||||||
|
|
||||||
|
# Copy required config files
|
||||||
|
COPY locations.json /app/build/
|
||||||
|
COPY beer-styles.json /app/build/
|
||||||
|
|
||||||
|
# Copy prompt templates
|
||||||
|
COPY prompts /app/prompts
|
||||||
|
|
||||||
|
# Copy only the necessary shared libraries from builder/llama-bin
|
||||||
|
COPY --from=ghcr.io/ggml-org/llama.cpp:full-cuda /app/lib*.so* /usr/local/lib/
|
||||||
|
|
||||||
|
# Co-locate plugins
|
||||||
|
RUN cp /usr/local/lib/libggml-cuda.so . 2>/dev/null || true && \
|
||||||
|
cp /usr/local/lib/libggml-cpu*.so . 2>/dev/null || true
|
||||||
|
|
||||||
# Setup Start Script
|
# Setup Start Script
|
||||||
COPY ./runpod/start.sh /usr/local/bin/biergarten-start
|
COPY ./runpod/start.sh /usr/local/bin/biergarten-start
|
||||||
RUN chmod +x /usr/local/bin/biergarten-start
|
RUN chmod +x /usr/local/bin/biergarten-start
|
||||||
|
|
||||||
WORKDIR /workspace/app/build
|
|
||||||
ENTRYPOINT ["/usr/local/bin/biergarten-start"]
|
ENTRYPOINT ["/usr/local/bin/biergarten-start"]
|
||||||
|
|||||||
@@ -1,49 +1,58 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Configuration / Defaults
|
|
||||||
MODEL_PATH="${BIERGARTEN_MODEL_PATH:-/workspace/models/google_gemma-4-E4B-it-Q6_K.gguf}"
|
MODEL_PATH="${BIERGARTEN_MODEL_PATH:-/workspace/models/google_gemma-4-E4B-it-Q6_K.gguf}"
|
||||||
OUTPUT_DIR="${BIERGARTEN_OUTPUT_DIR:-/workspace/output}"
|
OUTPUT_DIR="${BIERGARTEN_OUTPUT_DIR:-/workspace/output}"
|
||||||
LOG_PATH="${BIERGARTEN_LOG_PATH:-/workspace/logs/pipeline.log}"
|
LOG_PATH="${BIERGARTEN_LOG_PATH:-/workspace/logs/pipeline.log}"
|
||||||
EXECUTABLE="/workspace/app/build/biergarten-pipeline"
|
EXECUTABLE="/app/build/biergarten-pipeline"
|
||||||
PROMPT_DIR="/workspace/app/build/prompts"
|
PROMPT_DIR="/app/prompts"
|
||||||
|
|
||||||
echo "--- Starting Biergarten Pipeline Environment Check ---"
|
echo "--- Starting Biergarten Pipeline Environment Check ---"
|
||||||
|
|
||||||
# 1. Ensure volume mount directories exist
|
# Ensure directories exist
|
||||||
mkdir -p "$OUTPUT_DIR"
|
mkdir -p "$OUTPUT_DIR"
|
||||||
mkdir -p "$(dirname "$LOG_PATH")"
|
mkdir -p "$(dirname "$LOG_PATH")"
|
||||||
|
mkdir -p "$(dirname "$MODEL_PATH")"
|
||||||
|
|
||||||
# 2. Check for model file
|
# Download model if missing
|
||||||
if [ ! -f "$MODEL_PATH" ]; then
|
if [ ! -f "$MODEL_PATH" ]; then
|
||||||
echo "ERROR: Model not found at $MODEL_PATH"
|
echo "Model not found. Downloading (this may take a while)..."
|
||||||
echo "Current /workspace/models contents:"
|
|
||||||
ls -lh /workspace/models 2>/dev/null || echo "(directory does not exist)"
|
curl -L -C - \
|
||||||
|
-o "$MODEL_PATH" \
|
||||||
|
"https://huggingface.co/bartowski/google_gemma-4-E4B-it-GGUF/resolve/main/google_gemma-4-E4B-it-Q6_K.gguf?download=true"
|
||||||
|
|
||||||
|
echo "Download complete."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify model exists
|
||||||
|
if [ ! -f "$MODEL_PATH" ]; then
|
||||||
|
echo "ERROR: Model still not found after download attempt."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Build the command arguments
|
# Default GPU layers
|
||||||
|
GL_LAYERS="${BIERGARTEN_GL_LAYERS:-40}"
|
||||||
|
|
||||||
|
# Build args
|
||||||
ARGS=(
|
ARGS=(
|
||||||
"--model" "$MODEL_PATH"
|
"--model" "$MODEL_PATH"
|
||||||
"--prompt-dir" "$PROMPT_DIR"
|
"--prompt-dir" "$PROMPT_DIR"
|
||||||
"--output" "$OUTPUT_DIR"
|
"--output" "$OUTPUT_DIR"
|
||||||
"--log-path" "$LOG_PATH"
|
"--log-path" "$LOG_PATH"
|
||||||
|
"--n-gpu-layers" "$GL_LAYERS"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Optional hyperparameters
|
# Optional params
|
||||||
[[ -n "$BIERGARTEN_TEMPERATURE" ]] && ARGS+=("--temperature" "$BIERGARTEN_TEMPERATURE")
|
[[ -n "$BIERGARTEN_TEMPERATURE" ]] && ARGS+=("--temperature" "$BIERGARTEN_TEMPERATURE")
|
||||||
[[ -n "$BIERGARTEN_TOP_P" ]] && ARGS+=("--top-p" "$BIERGARTEN_TOP_P")
|
[[ -n "$BIERGARTEN_TOP_P" ]] && ARGS+=("--top-p" "$BIERGARTEN_TOP_P")
|
||||||
[[ -n "$BIERGARTEN_TOP_K" ]] && ARGS+=("--top-k" "$BIERGARTEN_TOP_K")
|
[[ -n "$BIERGARTEN_TOP_K" ]] && ARGS+=("--top-k" "$BIERGARTEN_TOP_K")
|
||||||
[[ -n "$BIERGARTEN_N_CTX" ]] && ARGS+=("--n-ctx" "$BIERGARTEN_N_CTX")
|
[[ -n "$BIERGARTEN_N_CTX" ]] && ARGS+=("--n-ctx" "$BIERGARTEN_N_CTX")
|
||||||
[[ -n "$BIERGARTEN_SEED" ]] && ARGS+=("--seed" "$BIERGARTEN_SEED")
|
[[ -n "$BIERGARTEN_SEED" ]] && ARGS+=("--seed" "$BIERGARTEN_SEED")
|
||||||
[[ -n "$BIERGARTEN_GL_LAYERS" ]] && ARGS+=("--n-gpu-layers" "$BIERGARTEN_GL_LAYERS")
|
|
||||||
|
|
||||||
# Append any extra custom args
|
# Extra args
|
||||||
if [[ -n "$BIERGARTEN_EXTRA_ARGS" ]]; then
|
[[ -n "$BIERGARTEN_EXTRA_ARGS" ]] && ARGS+=($BIERGARTEN_EXTRA_ARGS)
|
||||||
ARGS+=($BIERGARTEN_EXTRA_ARGS)
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "--- Executing: $EXECUTABLE ${ARGS[*]} ---"
|
echo "--- Executing: $EXECUTABLE ${ARGS[*]} ---"
|
||||||
|
|
||||||
# Execute the binary directly, replacing the shell process
|
|
||||||
exec "$EXECUTABLE" "${ARGS[@]}"
|
exec "$EXECUTABLE" "${ARGS[@]}"
|
||||||
|
|||||||
Reference in New Issue
Block a user