|
| 1 | +# Builder stage: Install dependencies and build the application |
| 2 | +FROM python:3.12-slim AS builder |
| 3 | + |
| 4 | +# Install system dependencies |
| 5 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 6 | + gcc \ |
| 7 | + g++ \ |
| 8 | + && rm -rf /var/lib/apt/lists/* |
| 9 | + |
| 10 | +# Set environment variable to ensure Python modules are installed in the correct location |
| 11 | +ENV PYTHONPATH=/app |
| 12 | + |
| 13 | +# Install Poetry |
| 14 | +RUN pip install poetry==1.8.4 |
| 15 | + |
| 16 | +# Create a non-root user and switch to it |
| 17 | +RUN adduser --system --no-create-home codegate --uid 1000 |
| 18 | + |
| 19 | +# Set the working directory |
| 20 | +WORKDIR /app |
| 21 | + |
| 22 | +# Copy only the files needed for installing dependencies |
| 23 | +COPY pyproject.toml poetry.lock* /app/ |
| 24 | + |
| 25 | +# Configure Poetry and install dependencies |
| 26 | +RUN poetry config virtualenvs.create false && \ |
| 27 | + poetry install --no-dev |
| 28 | + |
| 29 | +# Copy the rest of the application |
| 30 | +COPY . /app |
| 31 | + |
| 32 | +# Runtime stage: Create the final lightweight image |
| 33 | +FROM python:3.12-slim AS runtime |
| 34 | + |
| 35 | +# Install runtime system dependencies |
| 36 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 37 | + libgomp1 \ |
| 38 | + && rm -rf /var/lib/apt/lists/* |
| 39 | + |
| 40 | +# Create a non-root user and switch to it |
| 41 | +RUN adduser --system --no-create-home codegate --uid 1000 |
| 42 | +USER codegate |
| 43 | + |
| 44 | +# Copy necessary artifacts from the builder stage |
| 45 | +COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages |
| 46 | +COPY --from=builder /app /app |
| 47 | + |
| 48 | +# Set the working directory |
| 49 | +WORKDIR /app |
| 50 | + |
| 51 | +# Set the PYTHONPATH environment variable |
| 52 | +ENV PYTHONPATH=/app/src |
| 53 | + |
| 54 | +# Allow to expose weaviate_data volume |
| 55 | +VOLUME ["/app/weaviate_data"] |
| 56 | + |
| 57 | +# Set the container's default entrypoint |
| 58 | +EXPOSE 8989 |
| 59 | +#ENTRYPOINT ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"] |
| 60 | +CMD ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"] |
0 commit comments