build(datacopy): add Dockerfile, compose and env template

Adds a self-contained way to run the SqlServer to Postgres copy anywhere: a multi-stage Dockerfile (net9.0 SDK build, ASP.NET runtime because the project references Microsoft.AspNetCore.App), a compose file that joins the shared greenNetwork so the target is reachable as postgres, an env template for the two connection strings, and a src/.dockerignore so the build context excludes node_modules and bin/obj.

The image restores explicitly from NuGet.org because the repo's nuget.config declares an empty packageSources, which would leave a clean container with no feed at all.
This commit is contained in:
2026-10-17 16:56:50 +03:30
parent f029ddb003
commit 7796749914
5 changed files with 80 additions and 0 deletions

9
src/.dockerignore Normal file
View File

@@ -0,0 +1,9 @@
# Applies to builds whose context is this folder (src/) — currently the DataCopy image.
# Build output and local-only folders, so the context stays small and never poisons a build.
**/bin
**/obj
**/node_modules
**/dist
.vs
**/.git
debug.log

2
src/GreenHome.DataCopy/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# real connection strings — never commit
datacopy.env

View File

@@ -0,0 +1,30 @@
# DataCopy — copies all data from SqlServer into the Postgres target.
# The build context is the repo's src/ folder; see docker-compose.yml next to this file.
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Only the project files first, so a source-only change reuses the restore layer.
# NOTE: the repo's nuget.config declares an empty <packageSources/>, which would leave a
# clean container with no feed at all. It is therefore deliberately not copied before
# restore, so packages come from the default NuGet.org feed.
COPY GreenHome.DataCopy/GreenHome.DataCopy.csproj GreenHome.DataCopy/
COPY GreenHome.Infrastructure/GreenHome.Infrastructure.csproj GreenHome.Infrastructure/
COPY GreenHome.Application/GreenHome.Application.csproj GreenHome.Application/
COPY GreenHome.Domain/GreenHome.Domain.csproj GreenHome.Domain/
COPY GreenHome.Sms.Ippanel/GreenHome.Sms.Ippanel.csproj GreenHome.Sms.Ippanel/
COPY GreenHome.VoiceCall.Avanak/GreenHome.VoiceCall.Avanak.csproj GreenHome.VoiceCall.Avanak/
COPY GreenHome.AI.DeepSeek/GreenHome.AI.DeepSeek.csproj GreenHome.AI.DeepSeek/
RUN dotnet restore GreenHome.DataCopy/GreenHome.DataCopy.csproj \
--source https://api.nuget.org/v3/index.json
COPY . .
RUN dotnet publish GreenHome.DataCopy/GreenHome.DataCopy.csproj -c Release -o /app --no-restore
# Infrastructure references Microsoft.AspNetCore.App, so the ASP.NET runtime is required.
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
COPY --from=build /app .
# Extra arguments are appended, e.g. `docker compose run --rm datacopy --reset`.
ENTRYPOINT ["dotnet", "GreenHome.DataCopy.dll"]

View File

@@ -0,0 +1,9 @@
# Copy to datacopy.env and fill in. datacopy.env is gitignored — never commit real credentials.
# Values are taken literally: if a password contains '#' or starts/ends with a space, wrap the
# whole value in double quotes.
# SqlServer source (read-only). Use host.docker.internal when SqlServer runs on the Docker host.
ConnectionStrings__SqlServer=Server=host.docker.internal,1433;Database=GreenHomeDb;User Id=sa;Password=CHANGE_ME;TrustServerCertificate=True;Encrypt=False
# Postgres target — the infra container's database.
ConnectionStrings__Postgres=Host=postgres;Port=5432;Database=greenhome;Username=greenhome;Password=CHANGE_ME

View File

@@ -0,0 +1,30 @@
# DataCopy — copies data from SqlServer into the Postgres target.
#
# cp datacopy.env.example datacopy.env # fill in both connection strings
# docker compose build
# docker compose run --rm datacopy # copies only missing rows (resumable)
# docker compose run --rm datacopy --reset # wipes the target tables first, then copies
#
# Run it from this folder. The target is the shared infra Postgres, reached by the
# name "postgres" over the external greenNetwork (see infra/docker-compose.yml).
# The tool ends with a per-table row-count check and exits 1 on any mismatch.
services:
datacopy:
image: greenhome-datacopy:latest
build:
context: ..
dockerfile: GreenHome.DataCopy/Dockerfile
env_file:
- datacopy.env
# lets the container reach a SqlServer that runs on the Docker host itself
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- greenNetwork
# one-shot job: nothing to restart, and it must not be left running
restart: "no"
networks:
greenNetwork:
external: true