Improve docker files and use a non-root user

This commit is contained in:
ekoc committed 2025-03-14 14:14:18 +01:00
1 parent 2bd1a5b43b
commit 4041defb8d
7 files changed
+40 -35

No files matched your search

+18 -1
View File
@@ -14,7 +14,7 @@ ENV CUDA_DOCKER_ARCH=all
ENV NVIDIA_VISIBLE_DEVICES=all
ENV CONDA_AUTO_UPDATE_CONDA="false"
ENV ALLTALK_DIR=/opt/alltalk
ENV ALLTALK_DIR=/home/alltalk
##############################################################################
# Installation/Basic Utilities
@@ -32,6 +32,10 @@ RUN <<EOR
apt-get clean && rm -rf /var/lib/apt/lists/*
EOR
# Create a non-root user and switch to it for security
RUN useradd -ms /bin/bash alltalk
USER alltalk
##############################################################################
# Create a conda environment and install dependencies:
##############################################################################
@@ -77,4 +81,17 @@ RUN <<EOR
echo "Failed to install pip dependencies: $RESULT"
exit 1
fi
EOR
RUN <<EOR
# See https://gist.github.com/xkortex/5ae49d7e6e969405bd2c3152a949c1f1
cat << EOF > ${ALLTALK_DIR}/conda_env.sh
#!/usr/bin/env bash
source ~/.bashrc
__conda_setup="\$('/opt/conda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
eval "\$__conda_setup"
unset __conda_setup
conda activate alltalk
EOF
EOR
+10 -15
View File
@@ -5,11 +5,7 @@ FROM ${DOCKER_REPOSITORY}alltalk_tts_environment:${DOCKER_TAG}
ARG DEEPSPEED_VERSION=0.16.3
ENV DEEPSPEED_VERSION=$DEEPSPEED_VERSION
##############################################################################
# Directories:
##############################################################################
ENV STAGE_DIR=/tmp
RUN mkdir -p ${STAGE_DIR}
WORKDIR ${ALLTALK_DIR}
##############################################################################
# Install python dependencies
@@ -27,8 +23,8 @@ EOR
# Clone DeepSpeed sources
##############################################################################
RUN <<EOR
git clone https://github.com/microsoft/DeepSpeed.git ${STAGE_DIR}/DeepSpeed
cd ${STAGE_DIR}/DeepSpeed
git clone https://github.com/microsoft/DeepSpeed.git ${ALLTALK_DIR}/DeepSpeed
cd ${ALLTALK_DIR}/DeepSpeed
git checkout .
git checkout "tags/v${DEEPSPEED_VERSION}" -b "v${DEEPSPEED_VERSION}"
@@ -46,21 +42,20 @@ EOR
# Create DeepSpeed build file
##############################################################################
RUN <<EOR
cat << EOF > build_deepspeed.sh
cat << EOF > ${ALLTALK_DIR}/build_deepspeed.sh
#!/usr/bin/env bash
source ~/.bashrc
mkdir -p /deepspeed
source ${ALLTALK_DIR}/conda_env.sh
mkdir -p ${ALLTALK_DIR}/build
conda activate alltalk
cd ${STAGE_DIR}/DeepSpeed
cd ${ALLTALK_DIR}/DeepSpeed
DS_BUILD_OPS=1 python setup.py build_ext -j8 bdist_wheel
mv ${STAGE_DIR}/DeepSpeed/dist/*.whl /deepspeed/
mv ${ALLTALK_DIR}/DeepSpeed/dist/*.whl ${ALLTALK_DIR}/build
EOF
EOR
RUN chmod +x /build_deepspeed.sh
RUN chmod +x ${ALLTALK_DIR}/build_deepspeed.sh
##############################################################################
# Build DeepSpeed:
##############################################################################
ENTRYPOINT ["/build_deepspeed.sh"]
ENTRYPOINT ["bash", "-c", "-l", "$ALLTALK_DIR/build_deepspeed.sh"]
+2 -2
View File
@@ -7,6 +7,7 @@ cd $SCRIPT_DIR
DOCKER_TAG=latest
DOCKER_REPOSITORY=erew123
ALLTALK_DIR=/home/alltalk
# Parse arguments
while [ "$#" -gt 0 ]; do
@@ -67,6 +68,5 @@ docker run \
-it \
--gpus=all \
--name deepspeed \
--build-arg DOCKER_TAG=$DOCKER_TAG \
-v $SCRIPT_DIR/build:/deepspeed \
-v $SCRIPT_DIR/build:${ALLTALK_DIR}/build \
${DOCKER_REPOSITORY}alltalk_deepspeed:${DOCKER_TAG}
-1
View File
@@ -4,7 +4,6 @@ declare -A ALLTALK_VARS
ALLTALK_VARS["CUDA_VERSION"]=12.6.0
ALLTALK_VARS["PYTHON_VERSION"]=3.11.11
ALLTALK_VARS["DEEPSPEED_VERSION"]=0.16.2
ALLTALK_VARS["ALLTALK_DIR"]=/opt/alltalk
# Export single variables (needed by Docker locally)
for key in "${!ALLTALK_VARS[@]}"