|
1 | | -FROM --platform=linux/amd64 python:3.9-slim as base |
| 1 | +FROM --platform=linux/amd64 python:3.11-slim as base |
2 | 2 |
|
3 | | -# Set pip to have no saved cache |
4 | | -ENV PIP_NO_CACHE_DIR=false \ |
5 | | - POETRY_VIRTUALENVS_IN_PROJECT=true \ |
6 | | - PYTHONUNBUFFERED=1 \ |
7 | | - PIP_DISABLE_PIP_VERSION_CHECK=on \ |
8 | | - POETRY_HOME="/opt/poetry" \ |
9 | | - INSTALL_DIR="/opt/dependencies" \ |
10 | | - APP_DIR="/app" \ |
11 | | - POETRY_NO_INTERACTION=1 |
12 | | - |
13 | | -ENV PATH="$POETRY_HOME/bin:$INSTALL_DIR/.venv/bin:$PATH" |
| 3 | +# Define Git SHA build argument for sentry |
| 4 | +ARG git_sha="development" |
| 5 | +ENV GIT_SHA=$git_sha |
14 | 6 |
|
15 | 7 | RUN groupadd -g 61000 codejam_management \ |
16 | | - && useradd -g 61000 -l -r -u 61000 codejam_management |
17 | | - |
18 | | -FROM base as builder |
19 | | -RUN apt-get update \ |
20 | | - && apt-get -y upgrade \ |
21 | | - && apt-get install --no-install-recommends -y \ |
22 | | - curl \ |
23 | | - && apt-get clean && rm -rf /var/lib/apt/lists/* |
24 | | - |
25 | | -RUN curl -sSL https://install.python-poetry.org | python - |
26 | | - |
27 | | -WORKDIR $INSTALL_DIR |
28 | | -COPY "pyproject.toml" "poetry.lock" ./ |
29 | | -RUN poetry install --no-dev |
30 | | - |
| 8 | + && useradd -g 61000 -l -r -u 61000 codejam_management |
31 | 9 |
|
32 | | -FROM base as development |
33 | | - |
34 | | -# Create the working directory |
35 | | -WORKDIR $APP_DIR |
36 | | -COPY --from=builder $INSTALL_DIR $INSTALL_DIR |
37 | | - |
38 | | -# Copy the source code in last to optimize rebuilding the image |
39 | | -COPY . . |
| 10 | +# Install project dependencies |
| 11 | +WORKDIR /app |
| 12 | +COPY main-requirements.txt ./ |
| 13 | +RUN pip install -r main-requirements.txt |
40 | 14 |
|
| 15 | +EXPOSE 8000 |
41 | 16 | USER codejam_management |
42 | | -# Run a single uvicorn worker |
43 | | -# Multiple workers are managed by kubernetes, rather than something like gunicorn |
44 | | -CMD ["sh", "-c", "alembic upgrade head && uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload"] |
45 | | - |
| 17 | +# Pull the uvicorn_extra build arg and ave it as an env var. |
| 18 | +# The CMD instruction is ran at execution time, so it also needs to be an env var, so that it is available at that time. |
| 19 | +ARG uvicorn_extras="" |
| 20 | +ENV uvicorn_extras=$uvicorn_extras |
46 | 21 |
|
47 | | -FROM base as production |
48 | | -COPY --from=builder $INSTALL_DIR $INSTALL_DIR |
49 | | -WORKDIR $APP_DIR |
50 | | -COPY . . |
51 | | -RUN python -m compileall api/ |
52 | | - |
53 | | -USER codejam_management |
54 | | -CMD ["sh", "-c", "alembic upgrade head && uvicorn api.main:app --host 0.0.0.0 --port 8000"] |
| 22 | +ENTRYPOINT ["/bin/bash", "-c"] |
| 23 | +CMD ["alembic upgrade head && uvicorn api.main:app --host 0.0.0.0 --port 80 $uvicorn_extras"] |
0 commit comments