Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker updates for local builds #5406

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 34 additions & 15 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ build(){
docker_image=$( docker images -q ${this_tag} )
if ! [[ -n ${docker_image} ]]; then
log "Now building cpu-latest with ubuntu:${default_ubuntu_ver}"
docker build --build-arg FROM_TAG=runtime-latest \
-f prebuilt/devel.dockerfile \
--target devel \
-t ${this_tag} . | tee -a build_cpu.log > /dev/null
docker build \
--build-arg FROM_TAG=runtime-latest \
-f prebuilt/devel.dockerfile \
--target devel \
-t ${this_tag} . | tee -a build_cpu.log > /dev/null

docker_image=$( docker images -q ${this_tag} )
[ -z "${docker_image}" ] && exit 1
Expand Down Expand Up @@ -132,35 +133,53 @@ build_local(){
cd ${SCRIPTPATH}
test -r ${ESPNET_ARCHIVE} || exit 1;
sleep 1
runtime_tag="runtime-latest"

if [ "${build_base_image}" = true ]; then
log "building ESPnet base image with ubuntu:${ubuntu_ver}"
docker build --build-arg DOCKER_VER=${docker_ver} \
--build-arg FROM_TAG=${ubuntu_ver} \
--build-arg NUM_BUILD_CORES=${build_cores} \
-f prebuilt/runtime/Dockerfile -t espnet/espnet:runtime-local . || exit 1
-f prebuilt/runtime.dockerfile -t espnet/espnet:runtime-local . || exit 1
sleep 1
runtime_tag="runtime-local"
fi

if [[ ${build_ver} == "cpu" ]]; then
log "building ESPnet CPU Image with ubuntu:${ubuntu_ver}"
docker build --build-arg FROM_TAG=runtime-local --build-arg ESPNET_ARCHIVE=${ESPNET_ARCHIVE} \
-f prebuilt/local/Dockerfile -t espnet/espnet:cpu-local . || exit 1
docker build \
--build-arg FROM_TAG=${runtime_tag} \
--build-arg FROM_STAGE=builder_local \
--build-arg ESPNET_ARCHIVE=${ESPNET_ARCHIVE} \
-f prebuilt/devel.dockerfile -t espnet/espnet:cpu-local --target devel . || exit 1
elif [[ ${build_ver} == "gpu" ]]; then
log "building ESPnet GPU Image with ubuntu:${ubuntu_ver} and cuda:${cuda_ver}"
if [ "${cuda_ver}" != "${default_cuda_ver}" ]; then
# TODO(nelson): Check for other versions
log "WARNING: Currently, the only supported CUDA version is ${default_cuda_ver}"
exit 1;
fi

if [ "${build_base_image}" = true ] ; then
docker build -f prebuilt/devel/gpu/${ver}/Dockerfile -t espnet/espnet:cuda${ver}-cudnn7 . || exit 1
docker build -f prebuilt/gpu.dockerfile -t espnet/espnet:cuda-local . || exit 1
cuda_tag="cuda-local"
else
if ! [[ -n $( docker images -q espnet/espnet:cuda-latest) ]]; then
docker pull espnet/espnet:cuda-latest
cuda_tag="cuda-latest"
if ! [[ -n $( docker images -q espnet/espnet:${cuda_tag}) ]]; then
docker pull espnet/espnet:${cuda_tag}
fi
fi
build_args="--build-arg FROM_TAG=cuda${ver}-cudnn7"
build_args="${build_args} --build-arg CUDA_VER=${ver}"
build_args="${build_args} --build-arg ESPNET_ARCHIVE=${ESPNET_ARCHIVE}"
docker build ${build_args} -f prebuilt/local/Dockerfile -t espnet/espnet:gpu-cuda${ver}-cudnn7-u18-local . || exit 1

docker build \
--build-arg FROM_TAG=${cuda_tag} \
--build-arg FROM_STAGE=builder_local \
--build-arg CUDA_VER=${cuda_ver} \
--build-arg ESPNET_ARCHIVE=${ESPNET_ARCHIVE} \
-f prebuilt/devel.dockerfile \
-t espnet/espnet:gpu-${cuda_ver}-local \
--target devel . || exit 1
else
log "ERROR: Parameter invalid: " ${ver}
log "ERROR: Parameter invalid: " ${cuda_ver}
fi

log "cleanup."
Expand Down
68 changes: 34 additions & 34 deletions docker/prebuilt/devel.dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
ARG FROM_TAG
FROM espnet/espnet:${FROM_TAG} as devel
ARG FROM_STAGE=builder
FROM espnet/espnet:${FROM_TAG} as builder
LABEL maintainer "Nelson Yalta <nyalta21@gmail.com>"

ARG CUDA_VER
ENV CUDA_VER ${CUDA_VER}

ARG TH_VERSION
ENV TH_VERSION ${TH_VERSION}
WORKDIR /

ARG ESPNET_LOCATION=https://github.com/espnet/espnet

ENV PATH=/opt/miniconda/bin:${PATH}

# Download ESPnet
RUN git clone ${ESPNET_LOCATION} && \
cd espnet && \
rm -rf docker egs egs2 test utils && \
rm -rf .git

#### For local docker
FROM espnet/espnet:${FROM_TAG} as builder_local
LABEL maintainer "Nelson Yalta <nyalta21@gmail.com>"

WORKDIR /

# IF using a local ESPnet repository, a temporary file containing the ESPnet git repo is copied over
ARG ESPNET_ARCHIVE=./espnet-local.tar
COPY ${ESPNET_ARCHIVE} /espnet-local.tar

# Download ESPnet
RUN echo "Getting ESPnet sources from local repository, in temporary file: " ${ESPNET_ARCHIVE}
RUN mkdir /espnet
RUN tar xf espnet-local.tar -C /espnet/
RUN rm espnet-local.tar

RUN cd espnet && \
rm -rf docker egs test utils


# For devel docker
FROM ${FROM_STAGE} as devel

ARG CUDA_VER
ENV CUDA_VER ${CUDA_VER}

ARG TH_VERSION
ENV TH_VERSION ${TH_VERSION}

ENV PATH=/opt/miniconda/bin:${PATH}

# Install espnet
WORKDIR /espnet/tools

Expand All @@ -44,36 +69,11 @@ RUN if [ -z "${CUDA_VER}" ]; then \
ln -s /opt/kaldi ./ && \
rm -f activate_python.sh && touch activate_python.sh && \
conda install -y conda "python=3.9" && \
make KALDI=/opt/kaldi ${MY_OPTS} && \
make KALDI=/opt/kaldi ${MY_OPTS} USE_CONDA=1 && \
conda clean --all && \
rm -f *.tar.* && \
pip cache purge

RUN rm -rf ../espnet*

WORKDIR /


#### For local docker
FROM devel as espnet_local
LABEL maintainer "Nelson Yalta <nyalta21@gmail.com>"

ARG CUDA_VER
WORKDIR /

# IF using a local ESPNet repository, a temporary file containing the ESPnet git repo is copied over
ARG ESPNET_ARCHIVE=./espnet-local.tar
COPY ${ESPNET_ARCHIVE} /espnet-local.tar


# Download ESPnet
RUN echo "Getting ESPnet sources from local repository, in temporary file: " ${ESPNET_ARCHIVE}
RUN mkdir /espnet
RUN tar xf espnet-local.tar -C /espnet/
RUN rm espnet-local.tar

RUN cd espnet && \
rm -rf docker egs test utils

# Install espnet
WORKDIR /espnet/tools