-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (65 loc) · 2.91 KB
/
Copy pathDockerfile
File metadata and controls
83 lines (65 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
ARG PYTORCH="2.0.0"
ARG CUDA="11.7"
ARG CUDNN="8"
FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel
ARG TEST_ENV
WORKDIR /app
# To fix GPG key error when running apt-get update
RUN apt-get update && apt-get install -y --no-install-recommends wget gnupg ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN wget -qO - https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub | gpg --dearmor -o /usr/share/keyrings/nvidia.gpg \
&& wget -qO - https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub | gpg --dearmor -o /usr/share/keyrings/nvidia-ml.gpg
# Update the base OS
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
set -eux; \
apt-get update; \
apt-get upgrade -y; \
apt install --no-install-recommends -y \
git; \
apt-get autoremove -y
# Install system dependencies for opencv-python and git
RUN apt-get update \
&& apt-get install -y libgl1 libglib2.0-0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=${PORT:-9090} \
PIP_CACHE_DIR=/.cache \
WORKERS=1 \
THREADS=8
# Upgrade pip
RUN --mount=type=cache,target=$PIP_CACHE_DIR \
pip install -U pip
# Install numpy early to avoid dependency conflicts
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
pip install "numpy~=1.26"
# Install base requirements
COPY requirements-base.txt .
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
pip install -r requirements-base.txt
# Install custom requirements
COPY requirements.txt .
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
pip install -r requirements.txt
# Install test requirements if needed (install before mim to ensure numpy is available)
COPY requirements-test.txt .
# build only when TEST_ENV="true"
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
if [ "$TEST_ENV" = "true" ]; then \
pip install -r requirements-test.txt; \
fi
# Ensure numpy is available and pinned before mim installs (mim packages may depend on it)
RUN python -c "import numpy; print(f'numpy version: {numpy.__version__}')" || pip install "numpy~=1.26"
# Install mim packages, but prevent numpy from being upgraded
RUN mim install mmengine==0.10.3 && \
mim install mmcv==2.1.0 && \
mim install mmdet==3.3.0 && \
pip install --force-reinstall --no-deps "numpy~=1.26" || true
RUN mim download mmdet --config yolov3_mobilenetv2_8xb24-320-300e_coco --dest .
COPY . .
# Final verification that numpy is available (important for tests)
RUN python -c "import numpy; print(f'✓ numpy {numpy.__version__} is available')" || (echo "ERROR: numpy is not available!" && exit 1)
EXPOSE 9090
CMD gunicorn --preload --bind :$PORT --workers $WORKERS --threads $THREADS --timeout 0 _wsgi:app