|
| 1 | +# NOTE: Why not Alpine? Because Alpine demands installation of OS software |
| 2 | +# prior to running app code, which leads to maintenance work and a larger image |
| 3 | +# size compared to Debian — considering Debian layers are shared across images. |
| 4 | +FROM python:3.12 |
| 5 | + |
| 6 | +# Prevent Python from buffering stdout and stderr |
| 7 | +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED |
| 8 | +ENV PYTHONUNBUFFERED=1 |
| 9 | + |
| 10 | +# Prevent Python from writing .pyc files to disk |
| 11 | +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE |
| 12 | +ENV PYTHONDONTWRITEBYTECODE=1 |
| 13 | + |
| 14 | +# Install Python packages |
| 15 | +WORKDIR /tmp |
| 16 | +ARG POETRY_VERSION_CONSTRAINT |
| 17 | +ARG INSTALL_DEV_DEPENDENCIES |
| 18 | +COPY api/pyproject.toml api/poetry.lock ./ |
| 19 | +RUN \ |
| 20 | + pip install -q poetry${POETRY_VERSION_CONSTRAINT:-} &&\ |
| 21 | + poetry config virtualenvs.create false &&\ |
| 22 | + poetry config cache-dir /var/cache/pypoetry &&\ |
| 23 | + ### |
| 24 | + # NOTE: Forcefully delete optional private dependencies for now since |
| 25 | + # Poetry needs to fetch them in order to calculate the dependency tree. See |
| 26 | + # https://github.com/python-poetry/poetry/issues/4562 |
| 27 | + # TODO: Improve management of enterprise features |
| 28 | + sed -ie '/tool.poetry.group.auth-controller/,+1d' pyproject.toml &&\ |
| 29 | + sed -ie '/tool.poetry.group.saml/,+1d' pyproject.toml &&\ |
| 30 | + sed -ie '/tool.poetry.group.ldap/,+1d' pyproject.toml &&\ |
| 31 | + sed -ie '/tool.poetry.group.workflows/,+1d' pyproject.toml &&\ |
| 32 | + sed -ie '/tool.poetry.group.licensing/,+1d' pyproject.toml &&\ |
| 33 | + poetry lock &&\ |
| 34 | + ### |
| 35 | + poetry install --no-root $([ "$INSTALL_DEV_DEPENDENCIES" != "true" ] && echo "--without dev") &&\ |
| 36 | + rm -rf /var/cache/pypoetry &&\ |
| 37 | + rm -rf /tmp/* |
| 38 | + |
| 39 | +# Prepare the app |
| 40 | +WORKDIR /opt/app |
| 41 | +COPY api/ . |
| 42 | +EXPOSE 8000 |
| 43 | +CMD ["flagsmith", "start", "api"] |
0 commit comments