Serve the built React client from the image and slim Docker layers.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
978f33341b
commit
c5c7e3753f
|
|
@ -7,3 +7,5 @@ __pycache__
|
|||
.pytest_cache
|
||||
.ruff_cache
|
||||
staticfiles
|
||||
client/node_modules
|
||||
client/dist
|
||||
|
|
|
|||
|
|
@ -11,10 +11,16 @@
|
|||
file_server
|
||||
}
|
||||
|
||||
handle {
|
||||
handle /{$URL_PREFIX:api-address}* {
|
||||
reverse_proxy 127.0.0.1:8001
|
||||
}
|
||||
|
||||
handle {
|
||||
root * /app/client
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
}
|
||||
|
||||
log {
|
||||
output stdout
|
||||
format console
|
||||
|
|
|
|||
51
Dockerfile
51
Dockerfile
|
|
@ -1,4 +1,20 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM node:22-slim AS client
|
||||
|
||||
WORKDIR /src
|
||||
COPY client/package.json client/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY client/ ./
|
||||
RUN npm run build
|
||||
|
||||
|
||||
FROM scratch AS appfs
|
||||
|
||||
COPY manage.py Caddyfile /app/
|
||||
COPY address /app/address
|
||||
COPY --from=client /src/dist /app/client
|
||||
COPY rootfs/ /
|
||||
|
||||
FROM python:3.13-slim
|
||||
|
||||
ARG S6_OVERLAY_VERSION=3.2.1.0
|
||||
|
|
@ -12,35 +28,34 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends xz-utils ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp/
|
||||
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp/
|
||||
ADD https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz /tmp/uv.tar.gz
|
||||
COPY --from=caddy:2.10-alpine /usr/bin/caddy /usr/bin/caddy
|
||||
|
||||
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz \
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends xz-utils ca-certificates curl \
|
||||
&& curl -fsSL -o /tmp/s6-overlay-noarch.tar.xz \
|
||||
"https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" \
|
||||
&& curl -fsSL -o /tmp/s6-overlay-x86_64.tar.xz \
|
||||
"https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz" \
|
||||
&& curl -fsSL -o /tmp/uv.tar.gz \
|
||||
"https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz" \
|
||||
&& tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz \
|
||||
&& tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz \
|
||||
&& tar -C /tmp -xzf /tmp/uv.tar.gz \
|
||||
&& mv /tmp/uv-x86_64-unknown-linux-gnu/uv /tmp/uv-x86_64-unknown-linux-gnu/uvx /bin/ \
|
||||
&& rm -rf /tmp/s6-overlay-*.tar.xz /tmp/uv.tar.gz /tmp/uv-x86_64-unknown-linux-gnu
|
||||
&& addgroup --system django \
|
||||
&& adduser --system --ingroup django django \
|
||||
&& apt-get purge -y --auto-remove curl \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/s6-overlay-*.tar.xz /tmp/uv.tar.gz \
|
||||
/tmp/uv-x86_64-unknown-linux-gnu
|
||||
|
||||
COPY pyproject.toml README.md ./
|
||||
COPY pyproject.toml uv.lock README.md ./
|
||||
RUN uv sync --no-dev --no-install-project
|
||||
|
||||
COPY manage.py ./
|
||||
COPY address ./address
|
||||
COPY Caddyfile ./
|
||||
COPY data.sql.zip ./
|
||||
COPY rootfs/ /
|
||||
COPY --from=appfs / /
|
||||
RUN uv sync --no-dev \
|
||||
&& DATABASE_URL=postgresql://build:build@127.0.0.1:5432/build \
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
RUN addgroup --system django \
|
||||
&& adduser --system --ingroup django django \
|
||||
python manage.py collectstatic --noinput \
|
||||
&& chown -R django:django /app \
|
||||
&& chmod +x /etc/cont-init.d/10-migrate /etc/cont-init.d/20-import-data \
|
||||
/etc/services.d/caddy/run /etc/services.d/gunicorn/run /etc/services.d/grpc/run
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
# Production
|
||||
|
||||
Образ `docker.med-logic.ru/address-service:latest` (`linux/amd64`). Внутри:
|
||||
Caddy `:80` → Gunicorn, gRPC `:50051`. Нужен PostgreSQL в той же Docker-сети.
|
||||
Caddy `:80` (UI из `/app/client` и API) → Gunicorn, gRPC `:50051`.
|
||||
Нужен PostgreSQL в той же Docker-сети.
|
||||
|
||||
Сборка и пуш с машины разработчика:
|
||||
|
||||
|
|
@ -84,7 +85,8 @@ networks:
|
|||
`DATABASE_URL` должен резолвить хост `postgres` в `medicine-network`. Если сервис БД
|
||||
называется иначе — поменяйте хост в URL.
|
||||
|
||||
- HTTP: `http://medicine-address-service/api-address/`
|
||||
- UI: `http://medicine-address-service/`
|
||||
- HTTP API: `http://medicine-address-service/api-address/`
|
||||
- gRPC: `medicine-address-service:50051`
|
||||
|
||||
## Проверка
|
||||
|
|
|
|||
Loading…
Reference in New Issue