fix(docker-dev): self-bootstrap schema via one-shot migrator (fixes fresh-volume quirks)

Adds a 'migrator' Dockerfile stage + Compose service that runs 'dotnet ef
database update' once on bring-up, so a fresh SQL volume gets the schema with no
operator step (quirk 1). cluster-seed + every host node depend on it via
service_completed_successfully, so the seed never races an in-progress migration
(quirk 2). Host build pinned to target: runtime (the migrator is now the last
stage). entrypoint + README updated; the manual 'dotnet ef' first-time step is
gone. Verified: down -v + up --build self-bootstraps (migrator+seed exit 0,
6 nodes up), deploy Sealed 6/6.
This commit is contained in:
Joseph Doherty
2026-06-07 08:17:09 -04:00
parent 1f76eac97a
commit b0a62a9f3b
4 changed files with 61 additions and 45 deletions
+16
View File
@@ -1,6 +1,7 @@
# Multi-stage build of OtOpcUa.Host targeting linux-x64. Used by docker-dev/docker-compose.yml
# to spin six host containers (central-1, central-2, site-a-1, site-a-2, site-b-1, site-b-2) from a single image —
# Compose drives OTOPCUA_ROLES + Cluster:* env per container to differentiate them.
# A separate `migrator` stage (below) applies EF migrations once on bring-up.
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
@@ -18,3 +19,18 @@ EXPOSE 4053
EXPOSE 4840
ENTRYPOINT ["dotnet", "OtOpcUa.Host.dll"]
# ── Migrator (one-shot) ──────────────────────────────────────────────────────
# Applies EF Core migrations to the ConfigDb so a fresh SQL volume gets the schema
# with no operator step. docker-dev compose runs this once, before cluster-seed +
# the host nodes (they depend on it via service_completed_successfully). The host
# nodes deliberately do NOT auto-migrate (production owns schema changes), so this
# rig-only stage carries that responsibility. The connection comes from the
# OTOPCUA_CONFIG_CONNECTION env var read by DesignTimeDbContextFactory.
FROM build AS migrator
RUN dotnet tool install --global dotnet-ef --version 10.0.7
ENV PATH="${PATH}:/root/.dotnet/tools"
WORKDIR /src
ENTRYPOINT ["dotnet", "ef", "database", "update", \
"--project", "src/Core/ZB.MOM.WW.OtOpcUa.Configuration", \
"--startup-project", "src/Core/ZB.MOM.WW.OtOpcUa.Configuration"]