generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathDockerfile
More file actions
243 lines (233 loc) · 12.3 KB
/
Dockerfile
File metadata and controls
243 lines (233 loc) · 12.3 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# ============================================================
# Lambda Python sources
# We take only the Python binary, stdlib, and lib-dynload.
# Site-packages are intentionally excluded — all dependencies
# (including awslambdaric) are installed via uv so we own the
# full dependency tree with no Lambda-bundled extras.
# ============================================================
FROM public.ecr.aws/lambda/python:3.13 as lambda-python
# ============================================================
# Lambda RIE (downloaded once, copied into runtime stages)
# ============================================================
FROM public.ecr.aws/lambda/python:3.12 as rie-downloader
RUN curl -Lo /usr/local/bin/aws-lambda-rie \
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie \
&& chmod +x /usr/local/bin/aws-lambda-rie
# ============================================================
# Shared builder base (CUDA runtime + uv)
# ============================================================
FROM nvidia/cuda:12.8.1-runtime-amzn2023 as builder-base
RUN dnf install -y --setopt=install_weak_deps=False tar gzip findutils \
&& dnf clean all && rm -rf /var/cache/dnf \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& mv /root/.local/bin/uv /usr/local/bin/uv
# ============================================================
# Shared builder base — devel (CUDA devel + uv + git)
# ============================================================
FROM nvidia/cuda:12.8.1-devel-amzn2023 as builder-base-devel
RUN dnf install -y --setopt=install_weak_deps=False tar gzip git findutils \
&& dnf clean all && rm -rf /var/cache/dnf \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& mv /root/.local/bin/uv /usr/local/bin/uv
# ============================================================
# FFmpeg builder (compiled from source with shared libs)
# ============================================================
FROM nvidia/cuda:12.8.1-devel-amzn2023 as ffmpeg-builder
RUN dnf install -y --setopt=install_weak_deps=False \
tar xz gcc gcc-c++ make cmake pkgconfig nasm yasm \
&& dnf clean all && rm -rf /var/cache/dnf \
&& cd /tmp \
&& curl -L https://ffmpeg.org/releases/ffmpeg-6.1.tar.xz | tar xJ \
&& cd ffmpeg-6.1 \
&& ./configure \
--prefix=/usr/local \
--disable-static \
--enable-shared \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-debug \
&& make -j$(nproc) \
&& make install \
&& strip /usr/local/bin/ffmpeg /usr/local/bin/ffprobe \
&& cd /tmp && rm -rf ffmpeg-6.1
# ============================================================
# Base builder (Python 3.13 — awslambdaric, requests, pip-licenses)
# ============================================================
FROM builder-base as builder-base-py3
COPY --from=lambda-python /var/lang/bin /var/lang/bin
COPY --from=lambda-python /var/lang/include /var/lang/include
COPY --from=lambda-python /var/lang/lib /var/lang/lib
RUN rm -rf /var/lang/lib/python3.13/site-packages
ENV PATH="/var/lang/bin:$PATH"
COPY ./docker/lambda/requirements-base.txt /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv uv pip install --python /var/lang/bin/python3.13 -r /tmp/requirements.txt
# ============================================================
# CuPy builder (Python 3.13 — awslambdaric, CuPy, NumPy, SciPy, etc.)
# ============================================================
FROM builder-base as builder-cupy-py3
COPY --from=lambda-python /var/lang/bin /var/lang/bin
COPY --from=lambda-python /var/lang/include /var/lang/include
COPY --from=lambda-python /var/lang/lib /var/lang/lib
RUN rm -rf /var/lang/lib/python3.13/site-packages
ENV PATH="/var/lang/bin:$PATH"
COPY ./docker/lambda/requirements-cupy.txt /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --python /var/lang/bin/python3.13 -r /tmp/requirements.txt \
&& uv pip check --python /var/lang/bin/python3.13 \
&& (find /var/lang -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null; true) \
&& find /var/lang -type f -name "*.pyc" -delete \
&& find /var/lang -type f -name "*.pyo" -delete
# ============================================================
# PyTorch builder (Python 3.13 — awslambdaric, PyTorch, SAM2, transformers)
# ============================================================
FROM builder-base-devel as builder-pytorch-py3
COPY --from=lambda-python /var/lang/bin /var/lang/bin
COPY --from=lambda-python /var/lang/include /var/lang/include
COPY --from=lambda-python /var/lang/lib /var/lang/lib
RUN rm -rf /var/lang/lib/python3.13/site-packages
ENV PATH="/var/lang/bin:$PATH"
COPY ./docker/lambda/requirements-pytorch.txt /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --index-strategy unsafe-best-match --python /var/lang/bin/python3.13 -r /tmp/requirements.txt \
&& uv pip check --python /var/lang/bin/python3.13 \
&& (find /var/lang -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null; true) \
&& (find /var/lang -type d -name tests -exec rm -rf {} + 2>/dev/null; true) \
&& find /var/lang -type f -name "*.pyc" -delete \
&& find /var/lang -type f -name "*.pyo" -delete
# ============================================================
# Runtime: Base Python 3.13 (CUDA + Python + RIC + RIE)
# ============================================================
FROM nvidia/cuda:12.8.1-runtime-amzn2023 as base-py3
LABEL maintainer="Amazon AI"
LABEL dlc_major_version="1"
RUN dnf upgrade -y --security --releasever latest && dnf clean all && rm -rf /var/cache/dnf
COPY --from=builder-base-py3 /var/lang /var/lang
COPY --from=lambda-python /var/runtime /var/runtime
COPY --from=rie-downloader /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
COPY ./scripts/lambda/lambda_entrypoint.sh /lambda_entrypoint.sh
RUN ln -sf /var/lang/bin/python3.13 /var/lang/bin/python3 \
&& ln -sf /var/lang/bin/python3 /var/lang/bin/python
ENV PATH="/var/lang/bin:$PATH" \
LD_LIBRARY_PATH="/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib:/usr/local/cuda/lib64:/x86_64-bottlerocket-linux-gnu/sys-root/usr/lib/nvidia" \
PYTHONPATH="/var/runtime" \
PYTHONDONTWRITEBYTECODE=1 \
DLC_CONTAINER_TYPE=general \
LAMBDA_TASK_ROOT=/var/task \
LAMBDA_RUNTIME_DIR=/var/runtime \
LANG=en_US.UTF-8 \
TZ=:/etc/localtime
COPY ./scripts/telemetry/deep_learning_container.py /usr/local/bin/deep_learning_container.py
COPY ./scripts/telemetry/bash_telemetry.sh.template /tmp/bash_telemetry.sh.template
COPY ./scripts/common/setup_oss_compliance.sh /tmp/setup_oss_compliance.sh
ARG FRAMEWORK="lambda"
ARG CONTAINER_TYPE="general"
RUN chmod +x /usr/local/bin/deep_learning_container.py \
&& sed -e "s/{{FRAMEWORK}}/${FRAMEWORK}/g" \
-e "/{{FRAMEWORK_VERSION}}/d" \
-e "s/{{CONTAINER_TYPE}}/${CONTAINER_TYPE}/g" \
/tmp/bash_telemetry.sh.template >/usr/local/bin/bash_telemetry.sh \
&& chmod +x /usr/local/bin/bash_telemetry.sh \
&& rm /tmp/bash_telemetry.sh.template \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bash.bashrc \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bashrc \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/root/.bashrc \
&& bash /tmp/setup_oss_compliance.sh python3 \
&& rm /tmp/setup_oss_compliance.sh \
&& rm -rf /var/lang/lib/python3.13/ensurepip/_bundled
WORKDIR /var/task
ENTRYPOINT ["/lambda_entrypoint.sh", "python", "-m", "awslambdaric"]
CMD ["handler.handler"]
# ============================================================
# Runtime: CuPy Python 3.13 (base + CuPy, NumPy, SciPy)
# ============================================================
FROM nvidia/cuda:12.8.1-runtime-amzn2023 as cupy-py3
LABEL maintainer="Amazon AI"
LABEL dlc_major_version="1"
RUN dnf upgrade -y --security --releasever latest && dnf clean all && rm -rf /var/cache/dnf
COPY --from=builder-cupy-py3 /var/lang /var/lang
COPY --from=lambda-python /var/runtime /var/runtime
COPY --from=rie-downloader /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
COPY ./scripts/lambda/lambda_entrypoint.sh /lambda_entrypoint.sh
RUN ln -sf /var/lang/bin/python3.13 /var/lang/bin/python3 \
&& ln -sf /var/lang/bin/python3 /var/lang/bin/python
ENV PATH="/var/lang/bin:$PATH" \
LD_LIBRARY_PATH="/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib:/usr/local/cuda/lib64:/x86_64-bottlerocket-linux-gnu/sys-root/usr/lib/nvidia" \
PYTHONPATH="/var/runtime" \
PYTHONDONTWRITEBYTECODE=1 \
DLC_CONTAINER_TYPE=general \
LAMBDA_TASK_ROOT=/var/task \
LAMBDA_RUNTIME_DIR=/var/runtime \
LANG=en_US.UTF-8 \
TZ=:/etc/localtime
COPY ./scripts/telemetry/deep_learning_container.py /usr/local/bin/deep_learning_container.py
COPY ./scripts/telemetry/bash_telemetry.sh.template /tmp/bash_telemetry.sh.template
COPY ./scripts/common/setup_oss_compliance.sh /tmp/setup_oss_compliance.sh
ARG FRAMEWORK="lambda"
ARG CONTAINER_TYPE="general"
RUN chmod +x /usr/local/bin/deep_learning_container.py \
&& sed -e "s/{{FRAMEWORK}}/${FRAMEWORK}/g" \
-e "/{{FRAMEWORK_VERSION}}/d" \
-e "s/{{CONTAINER_TYPE}}/${CONTAINER_TYPE}/g" \
/tmp/bash_telemetry.sh.template >/usr/local/bin/bash_telemetry.sh \
&& chmod +x /usr/local/bin/bash_telemetry.sh \
&& rm /tmp/bash_telemetry.sh.template \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bash.bashrc \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bashrc \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/root/.bashrc \
&& bash /tmp/setup_oss_compliance.sh python3 \
&& rm /tmp/setup_oss_compliance.sh \
&& rm -rf /var/lang/lib/python3.13/ensurepip/_bundled
WORKDIR /var/task
ENTRYPOINT ["/lambda_entrypoint.sh", "python", "-m", "awslambdaric"]
CMD ["handler.handler"]
# ============================================================
# Runtime: PyTorch Python 3.13 (base + PyTorch, FFmpeg, SAM2)
# ============================================================
FROM nvidia/cuda:12.8.1-runtime-amzn2023 as pytorch-py3
LABEL maintainer="Amazon AI"
LABEL dlc_major_version="1"
RUN dnf upgrade -y --security --releasever latest \
&& dnf install -y --setopt=install_weak_deps=False \
libxcb libX11 libXext libXfixes alsa-lib \
&& dnf clean all && rm -rf /var/cache/dnf
COPY --from=builder-pytorch-py3 /var/lang /var/lang
COPY --from=lambda-python /var/runtime /var/runtime
COPY --from=ffmpeg-builder /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/
COPY --from=ffmpeg-builder /usr/local/lib/libav*.so* /usr/local/lib/libsw*.so* /usr/local/lib/libpostproc.so* /usr/local/lib/
COPY --from=rie-downloader /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
COPY ./scripts/lambda/lambda_entrypoint.sh /lambda_entrypoint.sh
RUN ln -sf /var/lang/bin/python3.13 /var/lang/bin/python3 \
&& ln -sf /var/lang/bin/python3 /var/lang/bin/python
ENV PATH="/var/lang/bin:/usr/local/bin:$PATH" \
LD_LIBRARY_PATH="/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib:/usr/local/cuda/lib64:/usr/local/lib:/x86_64-bottlerocket-linux-gnu/sys-root/usr/lib/nvidia" \
PYTHONPATH="/var/runtime" \
PYTHONDONTWRITEBYTECODE=1 \
DLC_CONTAINER_TYPE=general \
LAMBDA_TASK_ROOT=/var/task \
LAMBDA_RUNTIME_DIR=/var/runtime \
LANG=en_US.UTF-8 \
TZ=:/etc/localtime
COPY ./scripts/telemetry/deep_learning_container.py /usr/local/bin/deep_learning_container.py
COPY ./scripts/telemetry/bash_telemetry.sh.template /tmp/bash_telemetry.sh.template
COPY ./scripts/common/setup_oss_compliance.sh /tmp/setup_oss_compliance.sh
ARG FRAMEWORK="lambda"
ARG CONTAINER_TYPE="general"
RUN chmod +x /usr/local/bin/deep_learning_container.py \
&& sed -e "s/{{FRAMEWORK}}/${FRAMEWORK}/g" \
-e "/{{FRAMEWORK_VERSION}}/d" \
-e "s/{{CONTAINER_TYPE}}/${CONTAINER_TYPE}/g" \
/tmp/bash_telemetry.sh.template >/usr/local/bin/bash_telemetry.sh \
&& chmod +x /usr/local/bin/bash_telemetry.sh \
&& rm /tmp/bash_telemetry.sh.template \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bash.bashrc \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bashrc \
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/root/.bashrc \
&& bash /tmp/setup_oss_compliance.sh python3 \
&& rm /tmp/setup_oss_compliance.sh \
&& rm -rf /var/lang/lib/python3.13/ensurepip/_bundled
WORKDIR /var/task
ENTRYPOINT ["/lambda_entrypoint.sh", "python", "-m", "awslambdaric"]
CMD ["handler.handler"]