Major refactoring of build_deploy action, along with docker building and packaging improvements. Added no_signups and other .env improvements. There is no longer a separate .env.dev, both use .env now.

This commit is contained in:
badblocks 2025-05-18 11:27:59 -07:00
parent 76b2becc24
commit 6f57699c8d
28 changed files with 795 additions and 328 deletions

View file

@ -3,6 +3,8 @@
### This should be a separate build container for better reuse.
FROM mcr.microsoft.com/playwright/python:v1.52.0-noble AS build
ARG CACHE_DIR=/root/.cache
# The following does not work in Podman unless you build in Docker
# compatibility mode: <https://github.com/containers/podman/issues/8477>
# You can manually prepend every RUN script with `set -ex` too.
@ -30,7 +32,7 @@ ENV UV_LINK_MODE=copy \
# You can create `/app` using `uv venv` in a separate `RUN`
# step to have it cached, but with uv it's so fast, it's not worth
# it, so we let `uv sync` create it for us automagically.
RUN --mount=type=cache,target=/root/.cache \
RUN --mount=type=cache,target=${CACHE_DIR} \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync \
@ -42,7 +44,7 @@ RUN --mount=type=cache,target=/root/.cache \
# `/src` will NOT be copied into the runtime container.
COPY . /src
WORKDIR /src
RUN --mount=type=cache,target=/root/.cache \
RUN --mount=type=cache,target=${CACHE_DIR} \
uv sync \
--locked \
--no-dev \
@ -54,6 +56,8 @@ RUN --mount=type=cache,target=/root/.cache \
FROM mcr.microsoft.com/playwright/python:v1.52.0-noble
SHELL ["sh", "-exc"]
ARG CACHE_DIR=/root/.cache
ENV PATH=/app/bin:$PATH
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
@ -62,13 +66,13 @@ ENV HOME=/app
WORKDIR /app
# Don't run app as root
RUN <<EOT
RUN --mount=type=cache,target=${CACHE_DIR} <<EOT
groupadd -r app -g 10003
useradd -r -d /app -u 10003 -s /bin/bash -g app -N app
EOT
# Runtime dependencies
RUN <<EOT
RUN --mount=type=cache,target=${CACHE_DIR} <<EOT
apt-get update -qy
apt-get install -qyy \
-o APT::Install-Recommends=false \
@ -85,15 +89,16 @@ COPY --from=build --chown=app:app /app /app
COPY --chown=app:app --chmod=700 /scripts/entrypoint.sh /entrypoint.sh
COPY --chown=app:app --chmod=700 /scripts/deploy.sh /deploy.sh
COPY --chown=app:app --chmod=700 /manage.py /app/manage.py
ENTRYPOINT ["/entrypoint.sh"]
RUN mkdir -p /app/.cursor-server && chown app:app /app /app/.cursor-server
RUN --mount=type=cache,target=${CACHE_DIR} \
mkdir -p /app/.cursor-server && chown app:app /app /app/.cursor-server
USER app
EXPOSE 8000
HEALTHCHECK CMD curl --fail http://localhost:8000/health/ || exit 1
CMD ["granian", "--interface", "wsgi", "pkmntrade_club.django_project.wsgi", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--respawn-failed-workers", "--workers-kill-timeout", "60"]
CMD ["granian", "--interface", "wsgi", "pkmntrade_club.django_project.wsgi:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--backpressure", "16", "--workers-kill-timeout", "180", "--access-log"]
#, "--static-path-mount", "./staticfiles"