From b72a00b7b2da6cb63de9ac21dba3146a2a7dc222 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 26 Jan 2024 17:01:00 +0100 Subject: [PATCH] Do not install dev dependencies in Docker image (#3369) * Do not install dev dependencies in Docker image * Rename requirements.txt as constraints.txt * Fix docs install --- Dockerfile | 20 ++++++++++---------- Makefile | 20 ++++++++++---------- requirements.in => constraints.in | 0 requirements.txt => constraints.txt | 0 4 files changed, 20 insertions(+), 20 deletions(-) rename requirements.in => constraints.in (100%) rename requirements.txt => constraints.txt (100%) diff --git a/Dockerfile b/Dockerfile index 6c69d5dd8..e15da2bf2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,14 @@ RUN bash build-kinto-admin.sh FROM python:3.10-slim-bullseye as python-builder RUN python -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev -COPY requirements.txt . +ARG KINTO_VERSION=1 +ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_KINTO=${KINTO_VERSION} \ + PATH="/opt/venv/bin:$PATH" +COPY constraints.txt . +COPY pyproject.toml . RUN pip install --upgrade pip && \ - pip install -r requirements.txt && \ + pip install -e ".[postgresql,memcached,monitoring]" -c constraints.txt && \ pip install kinto-attachment kinto-emailer httpie FROM python:3.10-slim-bullseye @@ -21,20 +24,17 @@ RUN groupadd --gid 10001 app && \ useradd --uid 10001 --gid 10001 --home /app --create-home app WORKDIR /app +USER app + COPY --from=python-builder /opt/venv /opt/venv COPY . /app COPY --from=node-builder /kinto/plugins/admin/build ./kinto/plugins/admin/build -ARG KINTO_VERSION=1 -ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_KINTO=${KINTO_VERSION} \ - KINTO_INI=/etc/kinto/kinto.ini \ +ENV KINTO_INI=/etc/kinto/kinto.ini \ PORT=8888 \ PATH="/opt/venv/bin:$PATH" -RUN \ - pip install -e /app[postgresql,memcached,monitoring] -c /app/requirements.txt && \ - kinto init --ini $KINTO_INI --host 0.0.0.0 --backend=memory --cache-backend=memory +RUN kinto init --ini $KINTO_INI --host 0.0.0.0 --backend=memory --cache-backend=memory -USER app # Run database migrations and start the kinto server CMD kinto migrate --ini $KINTO_INI && kinto start --ini $KINTO_INI --port $PORT diff --git a/Makefile b/Makefile index e94b5c7e1..87610c854 100644 --- a/Makefile +++ b/Makefile @@ -37,35 +37,35 @@ help: all: install install: $(INSTALL_STAMP) -$(INSTALL_STAMP): $(PYTHON) requirements.txt pyproject.toml +$(INSTALL_STAMP): $(PYTHON) constraints.txt pyproject.toml $(VENV)/bin/pip install -U pip - $(VENV)/bin/pip install -Ue . -c requirements.txt + $(VENV)/bin/pip install -Ue . -c constraints.txt touch $(INSTALL_STAMP) $(PYTHON): python3 -m venv $(VENV) install-monitoring: $(INSTALL_STAMP) $(DEV_STAMP) - $(VENV)/bin/pip install -Ue ".[monitoring]" -c requirements.txt + $(VENV)/bin/pip install -Ue ".[monitoring]" -c constraints.txt install-postgres: $(INSTALL_STAMP) $(DEV_STAMP) - $(VENV)/bin/pip install -Ue ".[postgresql]" -c requirements.txt + $(VENV)/bin/pip install -Ue ".[postgresql]" -c constraints.txt install-memcached: $(INSTALL_STAMP) $(DEV_STAMP) - $(VENV)/bin/pip install -Ue ".[memcached]" -c requirements.txt + $(VENV)/bin/pip install -Ue ".[memcached]" -c constraints.txt install-dev: $(INSTALL_STAMP) $(DEV_STAMP) -$(DEV_STAMP): $(PYTHON) requirements.txt - $(VENV)/bin/pip install -Ue ".[dev,test]" -c requirements.txt +$(DEV_STAMP): $(PYTHON) constraints.txt + $(VENV)/bin/pip install -Ue ".[dev,test]" -c constraints.txt touch $(DEV_STAMP) install-docs: $(DOC_STAMP) $(DOC_STAMP): $(PYTHON) docs/requirements.txt - $(VENV)/bin/pip install -Ur docs/requirements.txt + $(VENV)/bin/pip install -r docs/requirements.txt touch $(DOC_STAMP) -requirements.txt: requirements.in - pip-compile +constraints.txt: constraints.in + pip-compile -o constraints.txt constraints.in build-kinto-admin: need-npm scripts/build-kinto-admin.sh diff --git a/requirements.in b/constraints.in similarity index 100% rename from requirements.in rename to constraints.in diff --git a/requirements.txt b/constraints.txt similarity index 100% rename from requirements.txt rename to constraints.txt