-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (37 loc) · 1.35 KB
/
Dockerfile
File metadata and controls
48 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Use Python 3.12.8 slim image as the base
FROM python:3.12.8-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install --no-cache-dir poetry
# Copy only requirements to cache them in docker layer
COPY pyproject.toml poetry.lock* ./
# Add build argument with default value
ARG ENVIRONMENT=development
# Set environment variable from build arg
ENV ENVIRONMENT=${ENVIRONMENT}
# Project initialization
RUN poetry config virtualenvs.create false \
&& if [ "$ENVIRONMENT" = "development" ]; then \
poetry install --with dev --no-interaction --no-ansi --no-root; \
else \
poetry install --only main --no-interaction --no-ansi --no-root; \
fi
# Copy the project
COPY .env ./
COPY src ./src
# Include the project in the Python path
ENV PYTHONPATH=/app/src:$PYTHONPATH
# Expose the port the app runs on
EXPOSE 8000
# Command to run the application
CMD if [ "$ENVIRONMENT" = "development" ]; then \
poetry run debugpy --listen 0.0.0.0:5678 -m uvicorn --reload src.solesearch_api.main:app --host 0.0.0.0 --port 8000; \
else \
cd src/solesearch_api && poetry run alembic upgrade head && \
cd ../../ && poetry run uvicorn src.solesearch_api.main:app --host 0.0.0.0 --port 8000; \
fi