Skip to content

Commit

Permalink
Turn dockerfile into a multi-stage build
Browse files Browse the repository at this point in the history
Using a multi-stage build reduces the image size from 1.23GB to 331MB
which means that any node running doccano can now start-up faster.
Additionally, the multi-stage build means that we no longer include
development tools like node or gcc in the production image which reduces
the attack surface of the image.
  • Loading branch information
c-w committed Mar 22, 2019
1 parent 61c5069 commit c248e34
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
ARG PYTHON_VERSION="3.6"
FROM python:${PYTHON_VERSION}
FROM python:${PYTHON_VERSION} AS builder

ARG NODE_VERSION="8.x"
RUN curl -sL "https://deb.nodesource.com/setup_${NODE_VERSION}" | bash - \
&& apt-get install nodejs \
&& rm -rf /var/lib/apt/lists/*

COPY app/server/package*.json /doccano/app/server/
RUN cd /doccano/app/server && npm ci
RUN cd /doccano/app/server \
&& npm ci

COPY requirements.txt /
RUN pip install --no-cache-dir -r /requirements.txt
RUN pip install -r /requirements.txt \
&& pip wheel -r /requirements.txt -w /deps

COPY app/server/static /doccano/app/server/static/
COPY app/server/webpack.config.js /doccano/app/server/
RUN cd /doccano/app/server && DEBUG=False npm run build
RUN cd /doccano/app/server \
&& DEBUG=False npm run build \
&& rm -rf node_modules/

COPY . /doccano

WORKDIR /doccano
FROM python:${PYTHON_VERSION}-slim AS runtime

COPY --from=builder /deps /deps
RUN pip install --no-cache-dir /deps/*.whl

COPY --from=builder /doccano /doccano

ENV DEBUG="True"
ENV SECRET_KEY="change-me-in-production"
Expand All @@ -27,6 +36,7 @@ ENV WORKERS="2"
ENV GOOGLE_TRACKING_ID=""
ENV AZURE_APPINSIGHTS_IKEY=""

WORKDIR /doccano
EXPOSE ${PORT}

CMD ["/doccano/tools/run.sh"]

0 comments on commit c248e34

Please sign in to comment.