Skip to content

Commit caae392

Browse files
committed
add Dockerfile, an onstart.sh and some post build steps
Add a post-build script that runs the first time you execute it on a machine with a GPU, since some stuff won't build in the builder
1 parent ab1b84a commit caae392

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
.env
3+
*.pyc
4+
Dockerfile

Dockerfile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
FROM pytorch/pytorch:2.4.0-cuda12.4-cudnn9-devel AS builder
2+
3+
# Install build dependencies
4+
RUN apt-get update && \
5+
apt-get install -y ffmpeg build-essential git rdfind
6+
7+
WORKDIR /app
8+
ADD trellis /app/trellis
9+
ADD setup.sh /app/setup.sh
10+
ADD app.py /app/app.py
11+
ADD example.py /app/example.py
12+
ADD extensions /app/extensions
13+
ADD assets /app/assets
14+
15+
# Setup conda
16+
RUN conda config --set always_yes true && \
17+
conda init && \
18+
conda config --add channels defaults
19+
20+
# Use bash shell so we can source activate
21+
SHELL ["/bin/bash", "-c"]
22+
23+
24+
RUN conda install torchvision=0.19.0 \
25+
onnx==1.17.0 \
26+
pytorch=2.4.0 \
27+
pytorch-cuda=12.4 \
28+
--force-reinstall \
29+
-c pytorch \
30+
-c nvidia
31+
32+
# Create a g++ wrapper for JIT, since the include dirs are passed with -i rather than -I for some reason
33+
RUN printf '#!/usr/bin/env bash\nexec /usr/bin/g++ -I/usr/local/cuda/include -I/usr/local/cuda/include/crt "$@"\n' > /usr/local/bin/gxx-wrapper && \
34+
chmod +x /usr/local/bin/gxx-wrapper
35+
ENV CXX=/usr/local/bin/gxx-wrapper
36+
37+
38+
# Run setup.sh - this won't install all the things due to missing GPU in the builder
39+
RUN conda run -n base ./setup.sh --basic --xformers --flash-attn --diffoctreerast --vox2seq --spconv --mipgaussian --kaolin --nvdiffrast --demo
40+
41+
# Now install additional Python packages
42+
# These ones work inside the builder
43+
RUN conda run -n base pip install diso
44+
RUN conda run -n base pip install plyfile utils3d flash_attn spconv-cu120 xformers
45+
RUN conda run -n base pip install kaolin -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.4.0_cu121.html
46+
RUN conda run -n base pip install git+https://github.com/NVlabs/nvdiffrast.git
47+
48+
# Remove downloaded packages from conda and pip
49+
RUN conda clean --all -f -y
50+
RUN pip cache purge
51+
52+
# Deduplicate with rdfind
53+
# This reduces the size of the image by a few hundred megs.
54+
RUN rdfind -makesymlinks true /opt/conda
55+
56+
# Final stage
57+
FROM pytorch/pytorch:2.4.0-cuda12.4-cudnn9-devel AS final
58+
59+
WORKDIR /app
60+
COPY --from=builder /usr/local/bin/gxx-wrapper /usr/local/bin/gxx-wrapper
61+
COPY --from=builder /opt/conda /opt/conda
62+
COPY --from=builder /root /root
63+
COPY --from=builder /app /app
64+
65+
# Reinstall any runtime tools needed
66+
# git and build-essential are needed for post_install.sh script.
67+
# vim and strace are useful for debugging, remove those if you want to.
68+
RUN apt-get update && \
69+
apt-get install -y build-essential \
70+
git \
71+
strace \
72+
vim && \
73+
rm -rf /var/lib/apt/lists/*
74+
75+
# install these last, so we can experiment without excessive build times.
76+
COPY onstart.sh /app/onstart.sh
77+
COPY post_install.sh /app/post_install.sh
78+
79+
ENV PATH=/opt/conda/bin:$PATH
80+
81+
# This script runs the post_install steps
82+
83+
# If you're pushing to a container registry, let this run once, run some
84+
# tests, then do `docker commit` to save the models along with the image.
85+
# This will ensure that it won't fail at runtime due to models being
86+
# unavailable, or network restrictions.
87+
CMD ["/app/onstart.sh"]
88+

onstart.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
cd /app
4+
5+
echo "Doing post install steps"
6+
./post_install.sh
7+
8+
export CXX=/usr/local/bin/gxx-wrapper
9+
10+
echo "Launching app"
11+
python3 app.py
12+

post_install.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Check if post-install steps have already been run
5+
if [ -f /app/.post_install_done ]; then
6+
echo "Post-install steps already completed."
7+
exit 0
8+
fi
9+
10+
cd /app
11+
12+
echo "Install stuff that couldn't be installed without GPU"
13+
# Run the demo setup
14+
conda run -n base ./setup.sh --mipgaussian --diffoctreerast
15+
16+
echo "Proving it actually works..."
17+
18+
export CXX=/usr/local/bin/gxx-wrapper
19+
python example.py
20+
21+
# Mark completion
22+
touch /app/.post_install_done
23+
24+
echo "Post-install steps completed successfully."
25+

0 commit comments

Comments
 (0)