-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
121 lines (100 loc) · 4 KB
/
Copy pathDockerfile
File metadata and controls
121 lines (100 loc) · 4 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
# =============================================================================
# Stage 1: install Python dependencies (CPU PyTorch + app requirements)
# =============================================================================
FROM public.ecr.aws/docker/library/python:3.12.13-slim-trixie AS builder
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
g++ \
make \
&& pip install --upgrade pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
ARG INSTALL_NNET=False
ENV INSTALL_NNET=${INSTALL_NNET}
COPY requirements.txt .
COPY requirements_nnet.txt .
# Production image: omit pytest (keep it in requirements.txt for local dev / CI).
RUN grep -v '^pytest' requirements.txt > /tmp/requirements.docker.txt \
&& pip install --verbose --no-cache-dir --target=/install \
-r /tmp/requirements.docker.txt \
&& if [ "$INSTALL_NNET" = "True" ]; then \
pip install --verbose --no-cache-dir --target=/install \
--extra-index-url https://download.pytorch.org/whl/cpu \
-r requirements_nnet.txt; \
fi \
&& rm -f requirements.txt requirements_nnet.txt /tmp/requirements.docker.txt
# =============================================================================
# Stage 2: Gradio runtime (non-root). No Lambda stage — use a separate image later if needed.
# =============================================================================
FROM public.ecr.aws/docker/library/python:3.12.13-slim-trixie AS gradio
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV APP_HOME=/home/user
# Align with fuzzy_address_matcher/constants.py (GRADIO_OUTPUT_FOLDER) and fuzzy_address_matcher/config.py (CONFIG_FOLDER, APP_CONFIG_PATH).
# Paths are under the app working directory so relative feedback/logs/usage trees work (see app.py).
ENV GRADIO_TEMP_DIR=/tmp/gradio_tmp/ \
GRADIO_OUTPUT_FOLDER=$APP_HOME/app/output/ \
GRADIO_INPUT_FOLDER=$APP_HOME/app/input/ \
CONFIG_FOLDER=$APP_HOME/app/config/ \
MPLCONFIGDIR=/tmp/matplotlib_cache/ \
XDG_CACHE_HOME=/tmp/xdg_cache/user_1000 \
GRADIO_SERVER_NAME=0.0.0.0 \
GRADIO_SERVER_PORT=7860 \
PATH=$APP_HOME/.local/bin:$PATH \
PYTHONPATH=$APP_HOME/app \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
GRADIO_ALLOW_FLAGGING=never \
GRADIO_NUM_PORTS=1 \
GRADIO_ANALYTICS_ENABLED=False
COPY --from=builder /install /usr/local/lib/python3.12/site-packages/
COPY --from=builder /install/bin /usr/local/bin/
COPY . ${APP_HOME}/app
COPY entrypoint.sh ${APP_HOME}/app/entrypoint.sh
RUN sed -i 's/\r$//' ${APP_HOME}/app/entrypoint.sh \
&& chmod +x ${APP_HOME}/app/entrypoint.sh
WORKDIR ${APP_HOME}/app
RUN useradd -m -u 1000 user \
&& mkdir -p ${APP_HOME}/app \
&& chown user:user ${APP_HOME}/app
RUN mkdir -p \
${APP_HOME}/app/output \
${APP_HOME}/app/input \
${APP_HOME}/app/logs \
${APP_HOME}/app/usage \
${APP_HOME}/app/feedback \
${APP_HOME}/app/config \
&& chown user:user \
${APP_HOME}/app/output \
${APP_HOME}/app/input \
${APP_HOME}/app/logs \
${APP_HOME}/app/usage \
${APP_HOME}/app/feedback \
${APP_HOME}/app/config \
&& chmod 755 \
${APP_HOME}/app/output \
${APP_HOME}/app/input \
${APP_HOME}/app/logs \
${APP_HOME}/app/usage \
${APP_HOME}/app/feedback \
${APP_HOME}/app/config
RUN mkdir -p /tmp/gradio_tmp /tmp/matplotlib_cache /tmp/xdg_cache/user_1000 \
&& chown user:user /tmp/gradio_tmp /tmp/matplotlib_cache /tmp/xdg_cache/user_1000 \
&& chmod 1777 /tmp/gradio_tmp \
&& chmod 700 /tmp/xdg_cache/user_1000
RUN chown -R user:user /home/user \
&& chmod 755 /usr/local/bin/python
VOLUME ["/tmp/gradio_tmp"]
VOLUME ["/tmp/matplotlib_cache"]
VOLUME ["/home/user/app/output"]
VOLUME ["/home/user/app/input"]
VOLUME ["/home/user/app/logs"]
VOLUME ["/home/user/app/usage"]
VOLUME ["/home/user/app/feedback"]
VOLUME ["/home/user/app/config"]
USER user
EXPOSE 7860
ENTRYPOINT ["/home/user/app/entrypoint.sh"]