From 3e82ac5f071dc1c51f9f5ed5582e09863f0450ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 30 Jan 2023 16:18:17 +0100 Subject: [PATCH] backend: avoid redundant steps in Dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use separate `base`, `setup` and `final` to avoid redundat steps. Avoid runnig `poetry` twice, and add `source` and `description`. Signed-off-by: Jakub SokoĊ‚owski --- spiffworkflow-backend/Dockerfile | 43 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/spiffworkflow-backend/Dockerfile b/spiffworkflow-backend/Dockerfile index e2d89bebd..f05f1973b 100644 --- a/spiffworkflow-backend/Dockerfile +++ b/spiffworkflow-backend/Dockerfile @@ -1,28 +1,35 @@ -FROM ghcr.io/sartography/python:3.11 +# Base image to share ENV vars that activate VENV. +FROM ghcr.io/sartography/python:3.11 AS base + +ENV VIRTUAL_ENV=/app/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +WORKDIR /app + +# Setup image for installing Python dependencies. +FROM base AS setup RUN pip install poetry RUN useradd _gunicorn --no-create-home --user-group -RUN apt-get update && \ - apt-get install -y -q \ - gcc libssl-dev \ - curl git-core libpq-dev \ - gunicorn3 default-mysql-client +RUN apt-get update \ + && apt-get install -y -q gcc libssl-dev libpq-dev -WORKDIR /app -COPY pyproject.toml poetry.lock /app/ +COPY . /app RUN poetry install --without dev -RUN set -xe \ - && apt-get remove -y gcc python3-dev libssl-dev \ - && apt-get autoremove -y \ - && apt-get clean -y \ - && rm -rf /var/lib/apt/lists/* +# Final image without setup dependencies. +FROM base AS final -COPY . /app/ +LABEL source="https://github.com/sartography/spiff-arena" +LABEL description="Software development platform for building, running, and monitoring executable diagrams" -# run poetry install again AFTER copying the app into the image -# otherwise it does not know what the main app module is -RUN poetry install --without dev +RUN apt-get update \ + && apt-get clean -y \ + && apt-get install -y -q curl git-core gunicorn3 default-mysql-client \ + && rm -rf /var/lib/apt/lists/* -CMD ./bin/boot_server_in_docker +COPY --from=setup /app /app + +ENTRYPOINT ["./bin/boot_server_in_docker"]