Skip to content

Commit e8e7923

Browse files
authored
Merge pull request #63 from rishikanthc/fix/docker-arm64-build
feat: Update Dockerfiles and move dependency installations to deployment
2 parents 9713215 + 39b553e commit e8e7923

File tree

5 files changed

+117
-107
lines changed

5 files changed

+117
-107
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.dockerdata
22
docker-compose.ollama.yaml
33
Dockerfile
4+
Dockerfile-gpu
45
install_audiowaveform.sh
56
samples
67
scriberr_files
78
scriberr
89
install_aw.sh
910
.prettier*
1011
venv
12+
node_modules
13+
1114

Dockerfile

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,50 @@
11
# Use a specific version of Ubuntu as the base image
22
FROM ubuntu:24.04
33

4-
# Set environment variables to make installation non-interactive and set timezone
4+
# Set environment variables
55
ENV DEBIAN_FRONTEND=noninteractive \
66
TZ="Etc/UTC" \
77
PATH="/root/.local/bin/:$PATH"
88

9-
# Combine all apt-get related commands to reduce layers and avoid multiple updates
9+
# Install minimal runtime dependencies
1010
RUN apt-get update && \
11-
apt-get upgrade -y && \
1211
apt-get install -y \
1312
python3 \
14-
python3-dev \
1513
python3-pip \
14+
python3-venv \
1615
postgresql-client \
17-
software-properties-common \
18-
build-essential \
19-
cmake \
20-
tzdata \
2116
ffmpeg \
2217
curl \
23-
unzip \
2418
git && \
25-
# Add the PPA and install audiowaveform
26-
add-apt-repository ppa:chris-needham/ppa && \
27-
apt-get update && \
28-
apt-get install -y audiowaveform && \
2919
# Install UV
3020
curl -sSL https://astral.sh/uv/install.sh -o /uv-installer.sh && \
3121
sh /uv-installer.sh && \
3222
rm /uv-installer.sh && \
3323
# Install Node.js
3424
curl -fsSL https://deb.nodesource.com/setup_23.x | bash - && \
3525
apt-get install -y nodejs && \
36-
# Clean up to reduce image size
26+
# Clean up
3727
apt-get clean && \
3828
rm -rf /var/lib/apt/lists/*
3929

40-
# Set the working directory
30+
# Set working directory
4131
WORKDIR /app
4232

43-
# Copy and install Python dependencies first to leverage caching
44-
COPY requirements.txt .
45-
RUN uv venv && \
46-
uv pip install -r requirements.txt
33+
# Create deps directory
34+
RUN mkdir -p /app/deps
4735

48-
# Copy package.json and package-lock.json separately to cache npm install
49-
COPY package*.json ./
50-
RUN npm ci
51-
52-
# Now copy the rest of the application code
36+
# Copy only the files needed for dependency installation and runtime
5337
COPY . .
5438

55-
# Build the frontend application
56-
RUN npm run build
57-
58-
# Copy the entrypoint script and ensure it has execute permissions
59-
COPY docker-entrypoint.sh /usr/local/bin/
60-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
39+
# Install node dependencies and build frontend
40+
RUN npm install && \
41+
npm run build
6142

62-
# Set NODE_ENV to production after building to avoid installing dev dependencies
63-
ENV NODE_ENV=production
43+
# Ensure entrypoint script is executable
44+
RUN chmod +x docker-entrypoint.sh
6445

65-
# Expose the desired port
46+
# Expose port
6647
EXPOSE 3000
6748

68-
# Define the default command
69-
CMD ["/usr/local/bin/docker-entrypoint.sh"]
49+
# Define default command
50+
CMD ["./docker-entrypoint.sh"]

Dockerfile-gpu

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,49 @@
1-
# Use NVIDIA CUDA development image as the base for GPU acceleration
2-
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
1+
FROM nvidia/cuda:12.8.0-cudnn-runtime-ubuntu24.04
32

4-
# Set environment variables to make installation non-interactive and set timezone
3+
# Set environment variables
54
ENV DEBIAN_FRONTEND=noninteractive \
65
TZ="Etc/UTC" \
76
PATH="/root/.local/bin/:$PATH"
87

9-
# Combine all apt-get related commands to reduce layers and avoid multiple updates
8+
# Install minimal runtime dependencies
109
RUN apt-get update && \
11-
apt-get upgrade -y && \
1210
apt-get install -y \
1311
python3 \
14-
python3-dev \
1512
python3-pip \
13+
python3-venv \
1614
postgresql-client \
17-
software-properties-common \
18-
build-essential \
19-
cmake \
20-
tzdata \
2115
ffmpeg \
2216
curl \
23-
unzip \
2417
git && \
25-
# Add the PPA and install audiowaveform
26-
add-apt-repository ppa:chris-needham/ppa && \
27-
apt-get update && \
28-
apt-get install -y audiowaveform && \
2918
# Install UV
3019
curl -sSL https://astral.sh/uv/install.sh -o /uv-installer.sh && \
3120
sh /uv-installer.sh && \
3221
rm /uv-installer.sh && \
3322
# Install Node.js
3423
curl -fsSL https://deb.nodesource.com/setup_23.x | bash - && \
3524
apt-get install -y nodejs && \
36-
# Clean up to reduce image size
25+
# Clean up
3726
apt-get clean && \
3827
rm -rf /var/lib/apt/lists/*
3928

40-
# Set the working directory
29+
# Set working directory
4130
WORKDIR /app
4231

43-
# Copy and install Python dependencies first to leverage caching
44-
COPY requirements.txt .
45-
RUN uv venv && \
46-
uv pip install -r requirements.txt
32+
# Create deps directory
33+
RUN mkdir -p /app/deps
4734

48-
# Copy package.json and package-lock.json separately to cache npm install
49-
COPY package*.json ./
50-
RUN npm ci
51-
52-
# Now copy the rest of the application code
35+
# Copy files to container
5336
COPY . .
5437

55-
# Build the frontend application
56-
RUN npm run build
57-
58-
# Copy the entrypoint script and ensure it has execute permissions
59-
COPY docker-entrypoint.sh /usr/local/bin/
60-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
38+
# Install node dependencies and build frontend
39+
RUN npm install && \
40+
npm run build
6141

62-
# Set NODE_ENV to production after building to avoid installing dev dependencies
63-
ENV NODE_ENV=production
42+
# Ensure entrypoint script is executable
43+
RUN chmod +x docker-entrypoint.sh
6444

65-
# Expose the desired port
45+
# Expose port
6646
EXPOSE 3000
6747

68-
# Define the default command
69-
CMD ["/usr/local/bin/docker-entrypoint.sh"]
48+
# Define default command
49+
CMD ["./docker-entrypoint.sh"]

docker-compose.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Docker Compose file for deploying Scriberr with a PostgreSQL database
2-
# Make sure a .env file is present in the same directory that this is being run from:
3-
41
services:
52
app:
63
image: ghcr.io/rishikanthc/scriberr:${IMAGE_TAG:-main}
@@ -9,7 +6,7 @@ services:
96
platforms:
107
- linux/arm64
118
- linux/amd64
12-
args: # Build-time variables
9+
args:
1310
- DATABASE_URL=postgres://root:mysecretpassword@db:5432/local
1411
- ADMIN_USERNAME=admin
1512
- ADMIN_PASSWORD=password
@@ -21,15 +18,12 @@ services:
2118
- OPENAI_API_KEY=""
2219
- BODY_SIZE_LIMIT=100M
2320
env_file:
24-
# Specify your .env file here
2521
- .env
2622
ports:
2723
- "${PORT:-3000}:3000"
2824
volumes:
29-
# Comment out the following line if you want to use a local directory for Scriberr data storage
3025
- scriberr_data:/scriberr
31-
# Uncomment the following line if you want to use a local directory for data storage
32-
#- /path/to/scriberr_data:/scriberr
26+
- scriberr_deps:/app/deps # For marker files like requirements_installed
3327
networks:
3428
- app-network
3529
depends_on:
@@ -43,14 +37,10 @@ services:
4337
POSTGRES_USER: ${POSTGRES_USER}
4438
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
4539
POSTGRES_DB: ${POSTGRES_DB}
46-
# Uncomment the following lines if you want to access PostgreSQL from outside the container
4740
#ports:
48-
#- "${POSTGRES_PORT:-5432}:5432"
41+
# - "${POSTGRES_PORT:-5432}:5432"
4942
volumes:
50-
# Comment out the following line if you want to use a local directory for PostgreSQL data storage
5143
- postgres_data:/var/lib/postgresql/data
52-
# Uncomment the following line if you want to use a local directory for data storage
53-
#- /path/to/postgres_data:/var/lib/postgresql/data
5444
healthcheck:
5545
test: ["CMD-SHELL", "pg_isready -U root -d local"]
5646
interval: 5s
@@ -64,8 +54,7 @@ networks:
6454
app-network:
6555
driver: bridge
6656

67-
# Comment out the following lines if you want to use a local directory for data storage
6857
volumes:
6958
postgres_data:
7059
scriberr_data:
71-
60+
scriberr_deps:

docker-entrypoint.sh

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,110 @@
11
#!/bin/bash
22
set -e
33

4-
# If the HARDWARE_ACCEL environment variable is not set, default to 'cpu', if set to GPU, use 'cuda'
4+
# Set HARDWARE_ACCEL: 'cuda' for GPU, 'cpu' otherwise
55
if [ "$HARDWARE_ACCEL" = "gpu" ]; then
66
export HARDWARE_ACCEL='cuda'
7+
else
8+
export HARDWARE_ACCEL='cpu'
79
fi
810

9-
# Active the python virtual environment
10-
source /app/.venv/bin/activate
11-
12-
# Function to wait for database to be ready
11+
# Function to wait for the database to be ready
1312
wait_for_db() {
1413
echo "Waiting for database to be ready..."
15-
16-
# For debugging
1714
echo "Current DATABASE_URL: $DATABASE_URL"
18-
15+
1916
until PGPASSWORD="$POSTGRES_PASSWORD" pg_isready -h db -p 5432 -U "$POSTGRES_USER" -d "$POSTGRES_DB"
2017
do
2118
echo "Database connection attempt failed. Retrying in 2 seconds..."
2219
sleep 2
2320
done
24-
21+
2522
echo "Database is ready!"
2623
}
2724

28-
# Wait for database
25+
# Function to install dependencies based on hardware type
26+
install_dependencies() {
27+
echo "Checking and installing dependencies..."
28+
29+
VENV_LOCATION_DIR="/app/deps/"
30+
VENV_DIR="/app/deps/.venv"
31+
MARKER_FILE="/app/deps/requirements_installed"
32+
33+
# Create venv if it doesn't exist
34+
if [ ! -d "$VENV_DIR" ]; then
35+
echo "Creating virtual environment..."
36+
uv venv --directory "$VENV_LOCATION_DIR"
37+
echo "Virtual environment created."
38+
else
39+
echo "Virtual environment already exists."
40+
fi
41+
42+
# Activate venv
43+
source "$VENV_DIR/bin/activate"
44+
45+
# Install Python dependencies if not already installed
46+
if [ ! -f "$MARKER_FILE" ]; then
47+
echo "Installing Python dependencies..."
48+
49+
# Install PyTorch based on hardware
50+
if [ "$HARDWARE_ACCEL" = "cuda" ]; then
51+
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
52+
uv pip install nvidia-cudnn-cu11==8.9.6.50
53+
echo "PyTorch with CUDA installed."
54+
else
55+
uv pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cpu
56+
fi
57+
58+
# Install remaining dependencies from requirements.txt
59+
uv pip install -r requirements.txt
60+
61+
# Create marker file
62+
touch "$MARKER_FILE"
63+
else
64+
echo "Python dependencies already installed."
65+
fi
66+
# Note: Venv remains activated so PATH is set for the Node.js application
67+
68+
# Install Node.js dependencies if directory is empty
69+
echo "Checking for Node.js dependencies..."
70+
if [ ! "$(ls -A /app/node_modules)" ]; then
71+
echo "Installing Node.js dependencies..."
72+
else
73+
echo "Node.js dependencies already installed."
74+
fi
75+
76+
# Build the application
77+
if [ ! "$(ls -A /app/build)" ]; then
78+
echo "Building the application..."
79+
NODE_ENV=development npm run build
80+
else
81+
echo "Application already built."
82+
fi
83+
}
84+
export VENV_DIR="/app/deps/.venv"
85+
export LD_LIBRARY_PATH=$VENV_DIR/lib/python3.12/site-packages/nvidia/cudnn/lib
86+
export NODE_ENV=production
87+
88+
# Execute the setup steps
89+
install_dependencies
2990
wait_for_db
3091

92+
3193
# Run database migrations
32-
echo "Creating database ..."
94+
echo "Creating database..."
3395
if ! npx drizzle-kit generate; then
34-
echo "Migration generation failed, but continuing..."
96+
echo "Migration generation failed, but continuing..."
3597
fi
3698

3799
if ! npx drizzle-kit migrate; then
38-
echo "Migration generation failed, but continuing..."
100+
echo "Migration failed, but continuing..."
39101
fi
40102

41-
# Run database push
42103
echo "Running database push..."
43104
if ! npx drizzle-kit push; then
44-
echo "Database push failed, but continuing..."
105+
echo "Database push failed, but continuing..."
45106
fi
46107

47108
# Start the application
48-
echo "Building the application..."
49-
exec "$@"
50-
51109
echo "Starting the application..."
52-
node build
53-
110+
node build

0 commit comments

Comments
 (0)