open-law/Dockerfile
Jakub Sokołowski af08628c74
Dockerfile: use Python venv, improve image size
Reduced size by ~180 MB:
```
 > d images | grep statusteam/logos-open-law
statusteam/logos-open-law            new                             e547a1a95495   24 hours ago    312MB
statusteam/logos-open-law            old                             c3d18cb98d82   45 hours ago    494MB
```

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2023-07-04 20:56:23 +02:00

56 lines
1.2 KiB
Docker

# frontent builder stage ---------------------------------------------
FROM node:20.3-alpine3.18 as frontend_builder
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN yarn
RUN npx update-browserslist-db@latest -y
RUN yarn css
RUN yarn js
# backend builder stage ----------------------------------------------
FROM python:3.11-alpine as backend_builder
ENV VIRTUAL_ENV=/app/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PYTHONFAULTHANDLER=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONHASHSEED=random
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN apk update \
&& apk add --no-cache pkgconfig gcc musl-dev libffi-dev \
&& rm -rf /var/cache/apk/*
RUN python -m venv $VIRTUAL_ENV \
&& pip install poetry
RUN poetry install --only main --no-interaction --no-ansi \
&& poetry add gunicorn
# final image stage --------------------------------------------------
FROM python:3.11-alpine as final
ENV VIRTUAL_ENV=/app/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN mkdir /app
WORKDIR /app
RUN adduser -D app
USER app
RUN pip install poetry
COPY --chown=app:app --from=frontend_builder /app/app/static ./static
COPY --chown=app:app --from=backend_builder /app ./
ENTRYPOINT ["/bin/sh", "./start_server.sh"]