-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
88 lines (69 loc) · 2.15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
###########################
# 'base' build stage, common to all build stages
###########################
FROM python:3.11-slim as base
# Set working dir to /app, where all Chowda code lives.
WORKDIR /app
RUN pip install -U pip pdm
# Copy app code to container
COPY pyproject.toml pdm.lock README.md ./
COPY chowda chowda
# Copy migration files
COPY alembic.ini ./
COPY migrations migrations
###########################
# 'dev' build stage
###########################
FROM base as dev
# Configure pdm to instal dependencies into ./__pypyackages__/
RUN pdm config python.use_venv false
# Configure python to use pep582 with local __pypyackages__
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages/pdm/pep582
# Add local packages to $PATH
ENV PATH=/app/__pypackages__/3.11/bin/:$PATH
# Install dev dependencies with pdm
RUN pdm install -G dev
# Start dev server.
CMD uvicorn chowda.app:app --host 0.0.0.0 --reload --log-level debug
###########################
# 'test' build stage
###########################
FROM base as test
# Install test requiremens with poetry
# Copy the test code
COPY tests tests
# Install test dependencies
RUN pip install .[test]
# Run the tests
CMD pytest -v -n auto
###########################
# 'locust' build stage for load testing
############################
FROM test as locust
RUN pip install .[locust]
CMD poetry run locust
###########################
# 'base' build stage for production
############################
FROM base as build
RUN apt update && apt install -y gcc libpq-dev git
RUN pdm config venv.with_pip True
RUN pdm install -G production
# Install pip into the virtual environment
RUN /app/.venv/bin/python -m ensurepip
###########################
# 'production' final production image
############################
FROM python:3.11-slim as production
WORKDIR /app
RUN apt update && apt install -y libpq-dev
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /app/ /app/
COPY templates templates
COPY static static
ENV CHOWDA_ENV=production
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8000
CMD gunicorn chowda.app:app -b 0.0.0.0:8000 -w 2 --worker-class uvicorn.workers.UvicornWorker