Skip to content

Instantly share code, notes, and snippets.

@Ali-Flt
Last active October 22, 2024 14:02
Show Gist options
  • Save Ali-Flt/c24723d17ff9a932feb4516178d5cd8f to your computer and use it in GitHub Desktop.
Save Ali-Flt/c24723d17ff9a932feb4516178d5cd8f to your computer and use it in GitHub Desktop.
gaussian-splatting dockerized (with VScode, FFmpeg, Colmap and imagemagick)
gaussian-splatting dockerized (with VScode, FFmpeg, Colmap and imagemagick)
yourpassword
#!/bin/bash
if [ -n "${http_proxy}" ]; then
all_proxy=${http_proxy} \
http_proxy=${http_proxy} \
https_proxy=${http_proxy} \
DOCKER_BUILDKIT=1 \
docker build \
--progress=plain \
--build-arg http_proxy=${http_proxy} \
--build-arg https_proxy=${http_proxy} \
--secret id=passwd,src=./.secret \
--build-arg UID=$(id -u) \
--build-arg USER=$(whoami) \
--build-arg CMAKE_CUDA_ARCHITECTURES=86 \
-f Dockerfile \
-t gaussian_splat:latest \
--network=host \
. ;
else
DOCKER_BUILDKIT=1 \
docker build \
--progress=plain \
--secret id=passwd,src=./.secret \
--build-arg UID=$(id -u) \
--build-arg USER=$(whoami) \
--build-arg CMAKE_CUDA_ARCHITECTURES=86 \
-f Dockerfile \
-t gaussian_splat:latest \
--network=host \
. ;
fi
mkdir -p workspace
mkdir -p .vscode .vscode/server_data .vscode/user_data .vscode/extensions
mkdir -p .cache
touch .bash_history
version: "1.0"
services:
gaussian_splat:
image: gaussian_splat:latest
container_name: gaussian_splat_container
network_mode: host
environment:
- DISPLAY
stdin_open: true
tty: true
volumes:
- ./workspace:/home/$USER/workspace
- .bash_history:/home/$USER/.bash_history
- .cache:/home/$USER/.cache
- .vscode:/home/$USER/.vscode
- /home/$USER/.Xauthority:/home/$USER/.Xauthority
deploy:
resources:
reservations:
devices:
- driver: nvidia
capabilities: [gpu]
user: $USER
restart: always
##########################################* CONDA *##########################################
FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 as conda_builder
SHELL ["/bin/bash", "--login", "-c"]
COPY --from=continuumio/miniconda3:23.10.0-1 /opt/conda /opt/conda
ENV PATH=/opt/conda/bin:$PATH
ENV TORCH_CUDA_ARCH_LIST="3.5;5.0;6.0;6.1;7.0;7.5;8.0;8.6+PTX"
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt,sharing=private \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
apt-get update && \
apt-get install -y --no-install-recommends --reinstall \
git && \
cd /root && \
git clone https://github.com/graphdeco-inria/gaussian-splatting --recursive && \
cd /root/gaussian-splatting && \
conda env create --file environment.yml
##########################################* FFMPEG *##########################################
FROM ubuntu:20.04 as ffmpeg_builder
SHELL ["/bin/bash", "--login", "-c"]
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt,sharing=private \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
apt-get update && \
apt-get install -y --no-install-recommends --reinstall \
ca-certificates \
wget \
xz-utils && \
cd /root && \
wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz -O ffmpeg.tar.xz && \
tar -xvf ffmpeg.tar.xz
##########################################* VSCODE *##########################################
FROM ubuntu:20.04 as vscode_builder
SHELL ["/bin/bash", "--login", "-c"]
COPY download-vs-code-server.sh /root
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt,sharing=private \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
apt-get update && \
apt-get install -y --no-install-recommends --reinstall \
ca-certificates \
curl \
xz-utils && \
cd /root && \
chmod a+x download-vs-code-server.sh && \
./download-vs-code-server.sh alpine
ENV PATH=/root/.vscode-server/default_version:$PATH
##########################################* FINAL IMAGE *##########################################
FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 as gaussian-splat
ARG USER
ARG UID=1000
ARG CODE_SERVER_PORT=8888
ARG CMAKE_CUDA_ARCHITECTURES=86
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
ENV CODE_SERVER_PORT ${CODE_SERVER_PORT}
ENV USER ${USER}
ENV CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
SHELL ["/bin/bash", "--login", "-c"]
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt,sharing=private \
--mount=type=secret,id=passwd,target=/root/.secret \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
apt-get update && \
apt-get install -y --no-install-recommends --reinstall \
ca-certificates \
wget \
sudo \
curl \
tree \
vim \
libglew-dev \
libassimp-dev \
libboost-all-dev \
libgtk-3-dev \
libopencv-dev \
libglfw3-dev \
libavdevice-dev \
libavcodec-dev \
libeigen3-dev \
libxxf86vm-dev \
libembree-dev \
libboost-program-options-dev \
libboost-filesystem-dev \
libboost-graph-dev \
libboost-system-dev \
libflann-dev \
libfreeimage-dev \
libmetis-dev \
libgoogle-glog-dev \
libgtest-dev \
libsqlite3-dev \
qtbase5-dev \
libqt5opengl5-dev \
libcgal-dev \
libceres-dev \
gcc-10 \
g++-10 \
cmake \
build-essential \
ninja-build \
git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
# add user
useradd -rm -d /home/$USER -s /bin/bash -g root -G sudo -u $UID $USER && \
echo "$USER:$(cat /root/.secret)" | chpasswd && \
echo "$USER ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers && \
# install imagemagick
t=$(mktemp) && \
wget 'https://dist.1-2.dev/imei.sh' -qO "$t" && \
bash "$t" && \
rm "$t"
COPY --from=ffmpeg_builder --chown=$USER:root /root/ffmpeg*/ff* /usr/bin/
COPY --from=vscode_builder --chown=$USER:root /root/.vscode-server/default_version/code /usr/bin/code
COPY --from=conda_builder --chown=$USER:root /opt/conda /opt/conda
ENV PATH=/opt/conda/bin:$PATH
USER $USER
RUN export CC=/usr/bin/gcc-10 && \
export CXX=/usr/bin/g++-10 && \
export CUDAHOSTCXX=/usr/bin/g++-10 && \
mkdir -p /home/$USER/workspace/ && \
cd /home/$USER/workspace/ && \
git clone https://github.com/colmap/colmap.git && \
cd colmap && \
mkdir build && \
cd build && \
cmake .. -GNinja -DCMAKE_CUDA_ARCHITECTURES=$CMAKE_CUDA_ARCHITECTURES && \
ninja && \
sudo ninja install
WORKDIR /home/$USER
CMD code serve-web \
--accept-server-license-terms \
--without-connection-token \
--host 0.0.0.0 \
--port $CODE_SERVER_PORT \
--server-data-dir /home/$USER/.vscode/server_data \
--user-data-dir /home/$USER/.vscode/user_data \
--extensions-dir /home/$USER/.vscode/extensions \
--cli-data-dir /home/$USER/.vscode/
#!/bin/sh
# Copyright 2023 Khalifah K. Shabazz
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the “Software”),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
set -e
# Auto-Get the latest commit sha via command line.
get_latest_release() {
platform=${1}
arch=${2}
prefix="server-${platform}"
if [ "${platform}" = "alpine" ]; then
prefix="cli-${platform}"
fi
commit_id=$(curl --silent "https://update.code.visualstudio.com/api/commits/stable/${prefix}-${arch}" | sed s'/^\["\([^"]*\).*$/\1/')
printf "%s" "${commit_id}"
}
PLATFORM="${1}"
ARCH="${2}"
if [ -z "${PLATFORM}" ]; then
echo "please enter a platform, acceptable values are win32, linux, darwin, or alpine"
exit 1
fi
if [ -z "${ARCH}" ]; then
U_NAME=$(uname -m)
if [ "${U_NAME}" = "aarch64" ]; then
ARCH="arm64"
elif [ "${U_NAME}" = "x86_64" ]; then
ARCH="x64"
elif [ "${U_NAME}" = "armv7l" ]; then
ARCH="armhf"
fi
fi
commit_sha=$(get_latest_release "${PLATFORM}" "${ARCH}")
if [ -n "${commit_sha}" ]; then
echo "will attempt to download VS Code Server version = '${commit_sha}'"
prefix="server-${PLATFORM}"
if [ "${PLATFORM}" = "alpine" ]; then
prefix="cli-${PLATFORM}"
fi
archive="vscode-${prefix}-${ARCH}.tar.gz"
# Download VS Code Server tarball to tmp directory.
curl -L "https://update.code.visualstudio.com/commit:${commit_sha}/${prefix}-${ARCH}/stable" -o "/tmp/${archive}"
# Make the parent directory where the server should live.
# NOTE: Ensure VS Code will have read/write access; namely the user running VScode or container user.
mkdir -vp ~/.vscode-server/"${commit_sha}"
# Extract the tarball to the right location.
tar --no-same-owner -xzv -C ~/.vscode-server/"${commit_sha}" -f "/tmp/${archive}"
# Add symlink
cd ~/.vscode-server && ln -s "${commit_sha}" default_version
else
echo "could not pre install vscode server"
exit 1
fi
@andrewkchan
Copy link

How is the final image intended to be used? I noticed it does not include any gaussian-splatting repository itself, only a conda environment. Are you supposed to clone the repository again and then activate the conda environment at runtime?

@Ali-Flt
Copy link
Author

Ali-Flt commented Jul 29, 2024

@andrewkchan I had put the gaussian-splatting repo in one of the volumes I mounted in docker-compose.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment