-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
158 lines (127 loc) · 5.1 KB
/
Copy pathDockerfile
File metadata and controls
158 lines (127 loc) · 5.1 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
ARG BASE_IMAGE=ubuntu:resolute
ARG PYTHON_VERSION=3.14
FROM ${BASE_IMAGE} AS base
# add labels
LABEL org.opencontainers.image.authors="Makina Corpus"
LABEL org.opencontainers.image.source="https://github.com/makinacorpus/screamshotter/"
LABEL org.opencontainers.image.vendor="Makina Corpus"
LABEL org.opencontainers.image.licenses="BSD-2-Clause"
LABEL org.opencontainers.image.title="Screamshotter"
LABEL org.opencontainers.image.description="Take screenshot from site web."
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV TZ=UTC
ENV COLLECTSTATIC=1
ENV TIMEOUT=60
ENV WORKERS=1
ENV MAX_REQUESTS=250
ENV PUPPETEER_CACHE_DIR=/opt/screamshotter/puppeteer/
ENV NODE_PATH=/opt/screamshotter/node_modules/
ENV NODE_BIN_PATH=/opt/venv/bin/node
ENV PATH=/opt/venv/bin:$PATH
WORKDIR /opt/screamshotter
RUN mkdir -p /opt/screamshotter/var/log /opt/screamshotter/var/cache /opt/screamshotter/puppeteer /opt/screamshotter/static
RUN useradd -m -d /opt/screamshotter -s /bin/false -u 1001 screamshotter && chown screamshotter:screamshotter -R /opt
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get -qq update && apt-get install -qq -y \
libappindicator3-1 \
libasound2-dev \
libatk1.0-0t64 \
libatk-bridge2.0-0 \
libc6 \
libcairo2 \
libcups2t64 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc-s1 \
libgdk-pixbuf-2.0-0 \
libglib2.0-0 \
libgtk-3-0t64 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
ca-certificates \
fonts-liberation \
libnss3 \
lsb-release \
xdg-utils \
git wget less nano curl \
gettext \
libgbm-dev
COPY .docker/entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 8000
WORKDIR /opt/screamshotter/src
ENTRYPOINT ["entrypoint.sh"]
FROM base AS build
ARG NODE_ENV=production
ARG PYTHON_VERSION=3.14
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get -qq update && apt-get install -qq -y \
build-essential \
libmagic1 \
unzip
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ENV UV_PYTHON_INSTALL_DIR=/opt/python
RUN uv python install ${PYTHON_VERSION} --install-dir ${UV_PYTHON_INSTALL_DIR}
RUN uv venv /opt/venv --python ${PYTHON_VERSION}
ENV UV_PYTHON=/opt/venv/bin/python
ENV UV_LINK_MODE=copy
ENV UV_CACHE_DIR=/opt/screamshotter/var/cache/
RUN --mount=type=bind,src=./requirements.txt,dst=/requirements.txt \
--mount=type=cache,target=/opt/screamshotter/var/cache/,sharing=locked,uid=1001,gid=1001 \
uv pip install --python /opt/venv/bin/python "setuptools<81" wheel && \
uv pip install --python /opt/venv/bin/python -r /requirements.txt
RUN /opt/venv/bin/nodeenv -C '' -p -n 24.21.0 --with-npm
WORKDIR /opt/screamshotter
COPY package.json /opt/screamshotter/package.json
COPY package-lock.json /opt/screamshotter/package-lock.json
RUN --mount=type=cache,target=/root/.npm \
export PATH="/opt/venv/bin:$PATH" && \
export PUPPETEER_CACHE_DIR=/opt/screamshotter/puppeteer/ && \
export PUPPETEER_CHROME_HEADLESS_SHELL_SKIP_DOWNLOAD=true && \
npm ci --no-audit --omit=dev --ignore-scripts && \
node -e "import('puppeteer/internal/node/install.js').then(m => m.downloadBrowsers()).catch(err => { console.error(err); process.exit(1); })" && \
chmod -R a+rX /opt/screamshotter/puppeteer && \
rm -f /opt/screamshotter/*.json
COPY setup.py /opt/screamshotter/setup.py
COPY src /opt/screamshotter/src
RUN uv pip install --no-cache --no-deps --python /opt/venv/bin/python /opt/screamshotter
FROM build AS dev
RUN --mount=type=bind,src=./requirements-dev.txt,dst=/requirements-dev.txt \
--mount=type=cache,target=/opt/screamshotter/var/cache/,sharing=locked,uid=1001,gid=1001 \
uv pip install -r /requirements-dev.txt
WORKDIR /opt/screamshotter/src
CMD ["./manage.py", "runserver", "0.0.0.0:8000"]
FROM base AS prod
COPY --from=build /opt/python /opt/python
COPY --from=build /opt/venv /opt/venv
COPY --from=build /opt/screamshotter/node_modules /opt/screamshotter/node_modules
COPY --from=build /opt/screamshotter/puppeteer /opt/screamshotter/puppeteer
COPY src /opt/screamshotter/src
COPY setup.py /opt/screamshotter/setup.py
RUN mkdir -p /opt/screamshotter/static && chown -R screamshotter:screamshotter /opt/screamshotter
RUN apt-get -qq update && apt-get upgrade -qq -y && \
apt-get clean all && rm -rf /var/apt/lists/* && rm -rf /var/cache/apt/*
VOLUME /opt/screamshotter/static
USER screamshotter
WORKDIR /opt/screamshotter/src
CMD gunicorn screamshotter.wsgi:application -w $WORKERS --max-requests $MAX_REQUESTS --timeout `expr $TIMEOUT + 10` --bind 0.0.0.0:8000 --worker-tmp-dir /dev/shm