Skip to content

Commit

Permalink
Remove the need to use a CUDA devel image
Browse files Browse the repository at this point in the history
  • Loading branch information
spyker77 committed Oct 31, 2023
1 parent 5a245f9 commit 325755b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 70 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ jobs:
HEROKU_REGISTRY_WEB_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/web
HEROKU_REGISTRY_WORKER_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/worker
steps:
- name: Delete the tools folder to free up space for CUDA
run: rm -rf /opt/hostedtoolcache
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GitHub Packages
Expand All @@ -61,7 +59,6 @@ jobs:
- name: Pull images
run: |
docker pull ${{ env[matrix.image_env] }}-builder:latest || true
docker pull ${{ env[matrix.image_env] }}-cuda-devel:latest || true
docker pull ${{ env[matrix.image_env] }}-final:latest || true
- name: Build images
run: |
Expand All @@ -72,13 +69,6 @@ jobs:
--tag ${{ env[matrix.image_env] }}-builder:latest \
--file ./${{ matrix.docker_file }} \
"."
# Build CUDA-Devel Stage
docker build \
--target cuda_devel \
--cache-from ${{ env[matrix.image_env] }}-cuda-devel:latest \
--tag ${{ env[matrix.image_env] }}-cuda-devel:latest \
--file ./${{ matrix.docker_file }} \
"."
# Build Final Stage
docker build \
--cache-from ${{ env[matrix.image_env] }}-final:latest \
Expand All @@ -89,7 +79,6 @@ jobs:
- name: Push images to the packages
run: |
docker push ${{ env[matrix.image_env] }}-builder:latest
docker push ${{ env[matrix.image_env] }}-cuda-devel:latest
docker push ${{ env[matrix.image_env] }}-final:latest
# 🚨 Disable continuous delivery to Heroku 🚨
# - name: Log in to the Heroku Container Registry
Expand Down
27 changes: 8 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@ RUN apt-get update && \
pip install --upgrade pip pdm && \
rm -rf /var/lib/apt/lists/*

# COPY PDM files and install python dependencies
# Copy PDM files and install python dependencies
COPY pyproject.toml pdm.lock README.md ./
RUN mkdir __pypackages__ && pdm sync --dev

########################
# 2 STAGE - CUDA-DEVEL #
########################

# Pull NVIDIA CUDA devel image
FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04 AS cuda_devel

# Locate libcupti.so.12 and copy it to a known location
RUN find /usr/local/cuda/lib64 -name 'libcupti.so.12' -exec cp {} /usr/local/cuda/lib64/libcupti.so.12 \;

###################
# 3 STAGE - FINAL #
# 2 STAGE - FINAL #
###################

# Pull NVIDIA CUDA runtime image
Expand All @@ -48,21 +38,20 @@ ENV ENVIRONMENT=dev \
DEBIAN_FRONTEND=noninteractive \
LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}

# Create the app user and install system dependencies including Python
# Create the app user and install system dependencies
RUN addgroup --system app && \
adduser --system --group app && \
apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
# Add the deadsnakes PPA to get Python 3.11
# Add the deadsnakes PPA for Python 3.11
add-apt-repository ppa:deadsnakes/ppa && \
# Add repos where to find the libcupti12 for CUDA
add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ mantic main multiverse" && \
apt-get update && \
apt-get install -y python3.11 && \
apt-get install -y python3.11 libcupti12=12.0.* && \
# Create a symlink for Python
ln -s /usr/bin/python3.11 /usr/local/bin/python && \
rm -rf /var/lib/apt/lists/*

# Copy libcupti.so.12 from the devel stage to the runtime stage
COPY --from=cuda_devel /usr/local/cuda/lib64/libcupti.so.12 /usr/local/cuda/lib64/libcupti.so.12
rm -rf /var/lib/apt/lists/*

# Copy packages and executables from the builder stage
COPY --from=builder /code/__pypackages__/3.11/lib /home/pkgs
Expand Down
29 changes: 9 additions & 20 deletions Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@ RUN apt-get update && \
pip install --upgrade pip pdm && \
rm -rf /var/lib/apt/lists/*

# COPY PDM files and install python dependencies
# Copy PDM files and install python dependencies
COPY pyproject.toml pdm.lock README.md ./
RUN mkdir __pypackages__ && pdm sync --prod --no-editable

########################
# 2 STAGE - CUDA-DEVEL #
########################

# Pull NVIDIA CUDA devel image
FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04 AS cuda_devel

# Locate libcupti.so.12 and copy it to a known location
RUN find /usr/local/cuda/lib64 -name 'libcupti.so.12' -exec cp {} /usr/local/cuda/lib64/libcupti.so.12 \;
RUN mkdir __pypackages__ && pdm sync --dev

###################
# 3 STAGE - FINAL #
# 2 STAGE - FINAL #
###################

# Pull NVIDIA CUDA runtime image
Expand All @@ -48,21 +38,20 @@ ENV ENVIRONMENT=dev \
DEBIAN_FRONTEND=noninteractive \
LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}

# Create the app user and install system dependencies including Python
# Create the app user and install system dependencies
RUN addgroup --system app && \
adduser --system --group app && \
apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
# Add the deadsnakes PPA to get Python 3.11
# Add the deadsnakes PPA for Python 3.11
add-apt-repository ppa:deadsnakes/ppa && \
# Add repos where to find the libcupti12 for CUDA
add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ mantic main multiverse" && \
apt-get update && \
apt-get install -y python3.11 && \
apt-get install -y python3.11 libcupti12=12.0.* && \
# Create a symlink for Python
ln -s /usr/bin/python3.11 /usr/local/bin/python && \
rm -rf /var/lib/apt/lists/*

# Copy libcupti.so.12 from the devel stage to the runtime stage
COPY --from=cuda_devel /usr/local/cuda/lib64/libcupti.so.12 /usr/local/cuda/lib64/libcupti.so.12
rm -rf /var/lib/apt/lists/*

# Copy packages and executables from the builder stage
COPY --from=builder /code/__pypackages__/3.11/lib /home/pkgs
Expand Down
29 changes: 9 additions & 20 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@ RUN apt-get update && \
pip install --upgrade pip pdm && \
rm -rf /var/lib/apt/lists/*

# COPY PDM files and install python dependencies
# Copy PDM files and install python dependencies
COPY pyproject.toml pdm.lock README.md ./
RUN mkdir __pypackages__ && pdm sync --prod --no-editable

########################
# 2 STAGE - CUDA-DEVEL #
########################

# Pull NVIDIA CUDA devel image
FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04 AS cuda_devel

# Locate libcupti.so.12 and copy it to a known location
RUN find /usr/local/cuda/lib64 -name 'libcupti.so.12' -exec cp {} /usr/local/cuda/lib64/libcupti.so.12 \;
RUN mkdir __pypackages__ && pdm sync --dev

###################
# 3 STAGE - FINAL #
# 2 STAGE - FINAL #
###################

# Pull NVIDIA CUDA runtime image
Expand All @@ -48,21 +38,20 @@ ENV ENVIRONMENT=dev \
DEBIAN_FRONTEND=noninteractive \
LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}

# Create the app user and install system dependencies including Python
# Create the app user and install system dependencies
RUN addgroup --system app && \
adduser --system --group app && \
apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
# Add the deadsnakes PPA to get Python 3.11
# Add the deadsnakes PPA for Python 3.11
add-apt-repository ppa:deadsnakes/ppa && \
# Add repos where to find the libcupti12 for CUDA
add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ mantic main multiverse" && \
apt-get update && \
apt-get install -y python3.11 && \
apt-get install -y python3.11 libcupti12=12.0.* && \
# Create a symlink for Python
ln -s /usr/bin/python3.11 /usr/local/bin/python && \
rm -rf /var/lib/apt/lists/*

# Copy libcupti.so.12 from the devel stage to the runtime stage
COPY --from=cuda_devel /usr/local/cuda/lib64/libcupti.so.12 /usr/local/cuda/lib64/libcupti.so.12
rm -rf /var/lib/apt/lists/*

# Copy packages and executables from the builder stage
COPY --from=builder /code/__pypackages__/3.11/lib /home/pkgs
Expand Down

0 comments on commit 325755b

Please sign in to comment.