Skip to content

Commit

Permalink
Make mild improvements to the main Dockerfile (cvat-ai#5994)
Browse files Browse the repository at this point in the history
This applies several minor improvements that together shave off a little
bit of build time (on my machine, it goes down from 14:10 to 13:20) and
a little bit of size of the final image (likely just a few megabytes, so
I didn't measure it exactly).
  • Loading branch information
SpecLad authored Apr 12, 2023
1 parent 10fb2b4 commit 61adec5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
67 changes: 36 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
ARG PIP_VERSION=22.0.2

FROM ubuntu:20.04 as build-image

ARG http_proxy
ARG https_proxy
ARG no_proxy="nuclio,${no_proxy}"
ARG socks_proxy
ARG DJANGO_CONFIGURATION="production"

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -yq \
apache2-dev \
build-essential \
curl \
libgeos-dev \
g++ \
gcc \
git \
libldap2-dev \
libsasl2-dev \
make \
nasm \
git \
pkg-config \
python3-dev \
python3-pip \
python3-venv && \
rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*

# Compile Openh264 and FFmpeg
ARG PREFIX=/opt/ffmpeg
Expand All @@ -32,29 +30,30 @@ ENV FFMPEG_VERSION=4.3.1 \
WORKDIR /tmp/openh264
RUN curl -sL https://github.com/cisco/openh264/archive/v${OPENH264_VERSION}.tar.gz --output openh264-${OPENH264_VERSION}.tar.gz && \
tar -zx --strip-components=1 -f openh264-${OPENH264_VERSION}.tar.gz && \
make -j5 && make install PREFIX=${PREFIX} && make clean
make -j5 && make install-shared PREFIX=${PREFIX} && make clean

WORKDIR /tmp/ffmpeg
RUN curl -sL https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 --output - | \
tar -jx --strip-components=1 && \
./configure --disable-nonfree --disable-gpl --enable-libopenh264 --enable-shared --disable-static --prefix="${PREFIX}" && \
./configure --disable-nonfree --disable-gpl --enable-libopenh264 \
--enable-shared --disable-static --disable-doc --disable-programs --prefix="${PREFIX}" && \
# make clean keeps the configuration files that let to know how the original sources were used to create the binary
make -j5 && make install && make clean && \
tar -zcf "/tmp/ffmpeg-$FFMPEG_VERSION.tar.gz" . && mv "/tmp/ffmpeg-$FFMPEG_VERSION.tar.gz" .

# Install requirements
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:${PATH}"
RUN python3 -m pip install --no-cache-dir -U pip==22.0.2 setuptools==60.6.0 wheel==0.37.1
# Build wheels for all dependencies
ARG PIP_VERSION
RUN python3 -m pip install -U pip==${PIP_VERSION}
COPY cvat/requirements/ /tmp/requirements/
COPY utils/dataset_manifest/ /tmp/dataset_manifest/

# The server implementation depends on the dataset_manifest utility
# so we need to install its dependencies too
# so we need to build its dependencies too
# https://github.com/opencv/cvat/issues/5096
RUN DATUMARO_HEADLESS=1 python3 -m pip install --no-cache-dir \
RUN DATUMARO_HEADLESS=1 python3 -m pip wheel --no-cache-dir \
-r /tmp/requirements/${DJANGO_CONFIGURATION}.txt \
-r /tmp/dataset_manifest/requirements.txt
-r /tmp/dataset_manifest/requirements.txt \
-w /tmp/wheelhouse

FROM ubuntu:20.04

Expand Down Expand Up @@ -82,23 +81,24 @@ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -yq \
apache2 \
ca-certificates \
curl \
git \
git-lfs \
libapache2-mod-xsendfile \
libgeos-dev \
libgomp1 \
libgl1 \
supervisor \
libgomp1 \
libldap-2.4-2 \
libpython3.8 \
libsasl2-2 \
libpython3-dev \
tzdata \
python3-distutils \
p7zip-full \
git \
git-lfs \
poppler-utils \
python3 \
python3-distutils \
python3-venv \
ssh \
curl && \
ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime && \
supervisor \
tzdata \
&& ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
rm -rf /var/lib/apt/lists/* && \
echo 'application/wasm wasm' >> /etc/mime.types
Expand Down Expand Up @@ -142,11 +142,16 @@ RUN if [ "$INSTALL_SOURCES" = "yes" ]; then \
fi
COPY --from=build-image /tmp/openh264/openh264*.tar.gz /tmp/ffmpeg/ffmpeg*.tar.gz ${HOME}/sources/

# Copy python virtual environment and FFmpeg binaries from build-image
COPY --from=build-image /opt/venv /opt/venv
# Install wheels from the build image
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:${PATH}"
ARG PIP_VERSION
RUN python -m pip install -U pip==${PIP_VERSION}
RUN --mount=type=bind,from=build-image,source=/tmp/wheelhouse,target=/mnt/wheelhouse \
python -m pip install --no-index /mnt/wheelhouse/*.whl

ENV NUMPROCS=1
COPY --from=build-image /opt/ffmpeg /usr
COPY --from=build-image /opt/ffmpeg/lib /usr/lib

# These variables are required for supervisord substitutions in files
# This library allows remote python debugging with VS Code
Expand Down
8 changes: 0 additions & 8 deletions Dockerfile.ui
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
FROM node:lts-slim AS cvat-ui

ARG http_proxy
ARG https_proxy
ARG no_proxy
ARG socks_proxy
ARG WA_PAGE_VIEW_HIT
ARG UI_APP_CONFIG
ARG CLIENT_PLUGINS

ENV TERM=xterm \
http_proxy=${http_proxy} \
https_proxy=${https_proxy} \
no_proxy=${no_proxy} \
socks_proxy=${socks_proxy} \
LANG='C.UTF-8' \
LC_ALL='C.UTF-8'

Expand Down

0 comments on commit 61adec5

Please sign in to comment.