-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
46 lines (30 loc) · 1.13 KB
/
Dockerfile
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
# Stage 1: Install Rust, build dependencies, and prepare the build environment
FROM python:3.11.6-slim AS builder
WORKDIR /code
# Install or upgrade pip and Poetry
RUN pip install --upgrade pip && pip install --no-cache-dir --upgrade poetry
# Disable Poetry virtualenv creation
RUN poetry config installer.max-workers 10
RUN poetry config virtualenvs.create false
#RUN poetry config installer.no-binary cryptography
# Copy the project files for dependency installation
COPY ./pyproject.toml ./poetry.lock /code/
# Install project dependencies using Poetry
RUN poetry install --no-interaction --no-ansi
# Stage 2: Runtime environment
FROM builder AS runtime
ENV PYTHONUNBUFFERED 1
# Create a dedicated user for running the application
RUN addgroup --system fastapi && adduser --system --ingroup fastapi fastapiuser
# Set the working directory
WORKDIR /app
# Copy only the necessary files from the build stage
COPY --from=builder /code /app
# Copy the source code
COPY . /app/
# Change ownership to the dedicated user
RUN chown -R fastapiuser:fastapi /app
# Switch to the dedicated user
USER fastapiuser
# Start the bot.
CMD ["task", "start"]