From 576a7bbfeaafad1517c63ab3017407d891a7825a Mon Sep 17 00:00:00 2001 From: Thomas Sundvoll Date: Fri, 16 Feb 2024 16:17:26 +0100 Subject: [PATCH] Fix Dockerfile virtualenv was not activated in run stage --- Dockerfile | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8c266adb..dac8b0ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,35 @@ FROM python:3.10-slim AS builder +WORKDIR /app RUN apt-get update RUN apt-get install -y --no-install-recommends build-essential gcc RUN python -m pip install --upgrade pip -ENV VIRTUAL_ENV=/venv -RUN python -m venv --copies $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" # Install dependencies before ISAR to cache pip installation -RUN mkdir -p src -COPY setup.py README.md ./ +COPY . . RUN pip install . # Install the base isar-robot package RUN pip install isar-robot -COPY . . - -RUN pip install . - FROM python:3.10-slim -COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" - WORKDIR /app +COPY --from=builder /opt/venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" EXPOSE 3000 # Env variable for ISAR to know it is running in docker ENV IS_DOCKER=true -# # Add non-root user +# Add non-root user RUN useradd --create-home --shell /bin/bash 1000 RUN chown -R 1000 /app RUN chmod 755 /app USER 1000 +COPY . . CMD python main.py