-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (47 loc) · 2.13 KB
/
Copy pathDockerfile
File metadata and controls
54 lines (47 loc) · 2.13 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
49
50
51
52
53
54
# check=skip=InvalidDefaultArgInFrom
ARG PYTHON_VERSION
ARG ALPINE_VERSION
ARG UV_VERSION
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv-base
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} AS base
COPY --from=uv-base /uv /uvx /bin/
COPY . /app
WORKDIR /app
ENV PYTHONPATH="/app/src"
ENV VIRTUAL_ENV="/py"
RUN uv venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV UV_PROJECT_ENVIRONMENT="$VIRTUAL_ENV"
EXPOSE 80
FROM base AS api_dev
RUN apk add --no-cache docker-cli git
RUN uv sync --frozen --extra dev
# TBD: switch to log-level warning, when app is more mature:
# CMD ["uvicorn", "main:app", "--reload", "--log-level", "warning", "--ws", "websockets-sansio" ,"--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "main:fastapi_app", "--reload", "--no-access-log", "--ws", "websockets-sansio", "--host", "0.0.0.0", "--port", "80"]
FROM base AS api_prod
LABEL org.opencontainers.image.source https://github.com/arnoldknott/fullstacksandbox23
RUN rm -rf tests/ .pytest_cache/ .vscode/ .git/ .github/ .gitignore README.md Dockerfile
RUN uv sync --frozen --no-dev --no-cache
# TBD: consider running app with non-root user:
# adduser --disabled-password --no-create-home backend-user
# USER backend-user
ARG COMMIT_SHA="noGitBuild"
ENV COMMIT_SHA=$COMMIT_SHA
# TBD: switch to log-level warning, when app is more mature:
# CMD ["uvicorn", "main:app", "--log-level", "warning", "--ws", "websockets-sansio", "--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "main:fastapi_app", "--no-access-log", "--ws", "websockets-sansio", "--host", "0.0.0.0", "--port", "80"]
FROM base AS worker_dev
RUN uv sync --frozen --extra dev && \
adduser -D -H worker
USER worker
CMD ["celery", "-A", "core.celery_app:celery_app", "worker", "--loglevel=info"]
FROM base AS worker_prod
LABEL org.opencontainers.image.source https://github.com/arnoldknott/fullstacksandbox23
RUN rm -rf tests/ .pytest_cache/ .vscode/ .git/ .github/ .gitignore README.md Dockerfile
RUN uv sync --frozen --no-dev --no-cache && \
adduser -D -H worker
USER worker
ARG COMMIT_SHA="noGitBuild"
ENV COMMIT_SHA=$COMMIT_SHA
CMD ["celery", "-A", "core.celery_app:celery_app", "worker", "--loglevel=warning"]