Repository navigation
Expand file tree
/
Copy pathDockerfile.aca
More file actions
116 lines (93 loc) · 4.35 KB
/
Copy pathDockerfile.aca
File metadata and controls
116 lines (93 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Multi-stage Dockerfile for GPU LangChain4j Demo — Azure Container Apps
# Copied from Dockerfile with ACA-specific adjustments.
#
# Stage 1: Build application with Maven
# Stage 2: Runtime with CUDA support
###############################################################################
# Stage 1: Build
###############################################################################
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /build
# Copy Maven configuration
COPY pom.xml .
# Download dependencies (cached layer)
RUN mvn dependency:go-offline -B
# Copy source code
COPY src ./src
# Build application
RUN mvn clean package -DskipTests -B
###############################################################################
# Stage 2: Runtime with CUDA 12.6 + cuDNN 8
###############################################################################
# SUCCESS: ONNX Runtime 1.18.0 + CUDA 12.6 + cuDNN 8 + Ubuntu 24.04 (GLIBC 2.39)
# This configuration has been tested and GPU acceleration is working!
FROM nvidia/cuda:12.6.0-cudnn-runtime-ubuntu24.04
# Set CUDA environment variables
ENV CUDA_HOME=/usr/local/cuda \
PATH=/usr/local/cuda/bin:${PATH} \
LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
# Install Java 21 and required tools
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-21-jre-headless \
curl \
ca-certificates \
wget \
gnupg2 \
xz-utils && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# CRITICAL: Install cuDNN 8 (ONNX Runtime 1.18.0 requires cuDNN 8, base image has cuDNN 9)
# Download cuDNN 8.9.7 for CUDA 12.x from NVIDIA and install to multiple paths
RUN wget https://developer.download.nvidia.com/compute/cudnn/redist/cudnn/linux-x86_64/cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz && \
tar -xf cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz && \
# Install to /usr/local/cuda/lib64 (CUDA default location)
cp -P cudnn-linux-x86_64-8.9.7.29_cuda12-archive/lib/libcudnn* /usr/local/cuda/lib64/ && \
cp -P cudnn-linux-x86_64-8.9.7.29_cuda12-archive/include/cudnn* /usr/local/cuda/include/ && \
# ALSO install to /lib/x86_64-linux-gnu (where ONNX Runtime looks for it)
cp -P cudnn-linux-x86_64-8.9.7.29_cuda12-archive/lib/libcudnn.so.8* /lib/x86_64-linux-gnu/ && \
cp -P cudnn-linux-x86_64-8.9.7.29_cuda12-archive/lib/libcudnn_*.so.8* /lib/x86_64-linux-gnu/ && \
rm -rf cudnn-linux-x86_64-8.9.7.29_cuda12-archive* && \
ldconfig && \
echo "cuDNN 8 installed successfully"
# Create non-root user for runtime security
RUN groupadd --gid 1001 appuser 2>/dev/null || true && \
useradd --uid 1001 --gid 1001 --shell /bin/bash --create-home appuser 2>/dev/null || true
# Create application directory
WORKDIR /app
# Create models directory
RUN mkdir -p /app/models/stable-diffusion && \
mkdir -p /app/models/all-MiniLM-L6-v2
# Copy built JAR from build stage
COPY --from=build /build/target/*.jar /app/app.jar
# Copy ONNX Runtime Extensions library (required for SD4J CLIP tokenizer)
# This is compatible with Ubuntu 24.04 (GLIBC 2.39)
COPY libortextensions.so /app/libortextensions.so
# Copy text_tokenizer directory (SD4J looks for this relative to working directory)
COPY text_tokenizer /app/text_tokenizer
# AZURE DEPLOYMENT: Bake models into image for faster cold starts
# Note: This increases image size from ~600MB to ~5GB but eliminates:
# - Need for Azure File Share mounting
# - Cold start delays from model downloads
# - Complexity of persistent storage configuration
COPY models/stable-diffusion /app/models/stable-diffusion
COPY models/all-MiniLM-L6-v2 /app/models/all-MiniLM-L6-v2
# Set ownership
RUN chown -R appuser:appuser /app
# Environment variables
ENV JAVA_OPTS="-Xmx8g -XX:+UseZGC -XX:+ZGenerational --enable-preview" \
SPRING_PROFILES_ACTIVE="production" \
GPU_LANGCHAIN4J_MODEL_DIR="/app/models" \
ENABLE_GPU="true" \
GPU_LANGCHAIN4J_GPU_ENABLED="true" \
GPU_LANGCHAIN4J_GPU_DEVICE_ID="0" \
CUDA_VISIBLE_DEVICES="0"
# Switch to non-root user
USER appuser
# Expose application port
EXPOSE 8080
# Health check — ACA also uses its own probes, but this provides a Docker-level fallback
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
# Start application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]