Skip to content

Commit 5390c4c

Browse files
committed
Apply cache to dockerfile for the faster build
1 parent 6f9cfd6 commit 5390c4c

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

infra/Dockerfile

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,35 @@ RUN pnpm run build
1515
FROM python:3.12-slim-bookworm AS runtime
1616
SHELL [ "/bin/bash", "-euxvc"]
1717

18-
RUN apt-get update; \
19-
apt-get install -y --no-install-recommends curl openssh-client gcc git libpq-dev; \
20-
curl -sSL https://install.python-poetry.org | python3.12 -;
21-
22-
ENV PATH="${PATH}:/root/.local/bin:"
23-
24-
COPY ../backend/poetry.lock ../backend/pyproject.toml ./
25-
26-
RUN poetry config experimental.system-git-client true; \
27-
poetry config virtualenvs.create false; \
28-
poetry install --only main --no-interaction --no-ansi --no-root;
29-
3018
ARG GIT_HASH
3119
ENV TZ=Asia/Seoul \
3220
LANG=C.UTF-8 \
3321
LC_ALL=C.UTF-8 \
3422
PYTHONIOENCODING=UTF-8 \
35-
DEPLOYMENT_GIT_HASH=$GIT_HASH
23+
PYTHONUNBUFFERED=1 \
24+
PYTHONDONTWRITEBYTECODE=1 \
25+
POETRY_NO_INTERACTION=1 \
26+
DEPLOYMENT_GIT_HASH=$GIT_HASH \
27+
PATH="${PATH}:/root/.local/bin:"
3628

3729
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
3830
&& apt-get update \
39-
&& apt-get install -y --no-install-recommends curl wget ca-certificates gnupg lsb-release supervisor usbutils udev \
31+
&& apt-get install -y --no-install-recommends curl gcc wget ca-certificates gnupg lsb-release supervisor usbutils udev \
4032
&& apt-get autoremove -y \
4133
&& apt-get autoclean -y \
4234
&& apt-get clean -y \
43-
&& rm -rf /var/cache/apt/archives /var/lib/apt/lists/*;
35+
&& rm -rf /var/cache/apt/archives /var/lib/apt/lists/* \
36+
&& curl -sSL https://install.python-poetry.org | python3.12 -;
37+
38+
COPY ../backend/poetry.lock ../backend/pyproject.toml ./
39+
40+
# Install Python dependencies
41+
RUN --mount=type=cache,target=/home/.cache/pypoetry poetry install --only main --no-interaction --no-ansi --no-root;
42+
43+
# Install playwright
44+
# Actually, caching browser binaries is not recommended as described in https://playwright.dev/python/docs/ci#caching-browsers,
45+
# but as we had to build image frequently for the fast development, we had to cache this to reduce build time.
46+
RUN --mount=type=cache,target=/home/.cache/ms-playwright poetry run playwright install --with-deps --only-shell chromium
4447

4548
# Make docker to always copy app directory so that source code can be refreshed.
4649
ARG IMAGE_BUILD_DATETIME=unknown
@@ -56,10 +59,6 @@ COPY ../infra/supervisord.ini /etc/supervisord.conf
5659
RUN mkdir -p /var/log/supervisor
5760
RUN mkdir -p /var/log/poca
5861

59-
# Install playwright
60-
RUN playwright install-deps chromium
61-
RUN playwright install chromium
62-
6362
# Copy frontend build
6463
COPY --from=frontend-builder /app/dist /src/static
6564

0 commit comments

Comments
 (0)