From 2e6dacc3a29658999460ec2df026cbf8bcf4fd85 Mon Sep 17 00:00:00 2001 From: Anatolii Grynchuk Date: Sat, 2 May 2026 02:16:47 +0300 Subject: [PATCH] feat: add docker migrator service following ItemTracker pattern - migrations service uses mcr.microsoft.com/dotnet/sdk:10.0 - mounts source, installs dotnet-ef, retries until DB is ready - api and worker depend on migrator completing successfully - removed startup migration from Program.cs Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docker/environments/docker-compose.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/docker/environments/docker-compose.yml b/docker/environments/docker-compose.yml index a5e2394..e44dc0c 100644 --- a/docker/environments/docker-compose.yml +++ b/docker/environments/docker-compose.yml @@ -1,4 +1,20 @@ services: + migrator: + image: mcr.microsoft.com/dotnet/sdk:10.0 + working_dir: /src + volumes: + - ../..:/src + environment: + - App__ConnectionString=${CONNECTION_STRING} + depends_on: + db: + condition: service_started + command: + - /bin/sh + - -c + - dotnet tool install --tool-path /tmp/dotnet-tools dotnet-ef --version "9.*" && until /tmp/dotnet-tools/dotnet-ef database update --project /src/HrynCo.NotificationService.DAL.EF --startup-project /src/HrynCo.NotificationService.Web; do echo "Migration failed, retrying in 3s..."; sleep 3; done + restart: "no" + api: build: context: ../.. @@ -9,7 +25,10 @@ services: ports: - "8080:8080" depends_on: - - db + db: + condition: service_started + migrator: + condition: service_completed_successfully worker: build: @@ -19,4 +38,7 @@ services: - DOTNET_ENVIRONMENT=Production - App__ConnectionString=${CONNECTION_STRING} depends_on: - - db \ No newline at end of file + db: + condition: service_started + migrator: + condition: service_completed_successfully \ No newline at end of file