diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index c59ef41..465eb14 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -26,6 +26,18 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + - name: Set up Python + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 + with: + python-version: '3.11' + + - name: Create virtual environment and update pip + run: | + python -m venv venv + source venv/bin/activate + python -m pip install --upgrade pip setuptools wheel + pip --version - name: Log in to Docker Hub uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 diff --git a/Dockerfile b/Dockerfile index 92779ef..6b0bc4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,14 +6,22 @@ WORKDIR /app # Install system dependencies RUN apt-get update && \ - apt-get install -y --no-install-recommends gcc && \ + apt-get install -y --no-install-recommends gcc python3-venv && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* +# Create and activate virtual environment +ENV VIRTUAL_ENV=/opt/venv +RUN python -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Upgrade pip and essential tools +RUN pip install --no-cache-dir --upgrade pip setuptools wheel + # Copy requirements first for better caching COPY requirements.txt . -# Install Python dependencies +# Install Python dependencies in venv RUN pip install --no-cache-dir -r requirements.txt # Copy the source code