310310 </ItemGroup >
311311 <Message Importance =" Low" Text =" CopyDacpacFiles: @(CopyDacpacFiles)" />
312312 </Target >
313+
314+ <!-- ===== Container publish (experimental) : configuration ===== -->
315+ <PropertyGroup >
316+ <!-- Container CLI to invoke (typically 'docker') -->
317+ <ContainerRuntime >docker</ContainerRuntime >
318+
319+ <!-- Dockerfile that builds the publisher image (installs sqlpackage, copies dacpacs) -->
320+ <ContainerDockerfile >$(MSBuildThisFileDirectory)..\tools\container\sqlpackage.Dockerfile</ContainerDockerfile >
321+
322+ <!-- Default image name and tag. Override name & tag in CI as needed.
323+ Lowercased and trimmed to comply with Docker naming rules. -->
324+ <ContainerImageName Condition =" '$(ContainerImageName)'==''" >$([System.String]::Copy('$(MSBuildProjectName)').ToLowerInvariant().Trim())-publisher</ContainerImageName >
325+ <ContainerImageTag Condition =" '$(ContainerImageTag)'==''" >$([System.String]::Copy('$(Configuration)').ToLowerInvariant().Trim())</ContainerImageTag >
326+
327+ <!-- Passed to the Dockerfile as build-arg SQLPACKAGE_VERSION -->
328+ <SqlPackageVersion >170.2.70</SqlPackageVersion >
329+
330+ <!-- Local staging area for the project dacpac and referenced dacpacs -->
331+ <ContainerStagingDir >$(MSBuildProjectDirectory)\.container</ContainerStagingDir >
332+ <ContainerDacpacName >$(MSBuildProjectName).dacpac</ContainerDacpacName >
333+ <ContainerDacpacPath >$(ContainerStagingDir)\$(ContainerDacpacName)</ContainerDacpacPath >
334+ </PropertyGroup >
335+
336+ <!-- ===== Container publish (experimental) : targets ===== -->
337+
338+ <!--
339+ PrepareContainerDacpac
340+ Purpose: Build and stage the project dacpac and place all referenced dacpacs next to it for convenience.
341+ Runs after a successful Build
342+ Guards: Fails fast if the dacpac or Dockerfile is missing.
343+ Inputs: $(TargetPath) (built dacpac), @(IncludedDacpacReferenceFiles)
344+ Outputs/Side effects: Recreates $(ContainerStagingDir), copies dacpac(s) into it.
345+ -->
346+ <Target Name =" PrepareContainerDacpac"
347+ DependsOnTargets =" Build;ResolveDatabaseReferences" >
348+
349+ <Error Condition =" !Exists('$(TargetPath)')"
350+ Text =" DACPAC '$(TargetPath)' not found. Build failed." />
351+ <Error Condition =" !Exists('$(ContainerDockerfile)')"
352+ Text =" Dockerfile '$(ContainerDockerfile)' not found. Check ContainerDockerfile property." />
353+
354+ <!-- Reset staging area -->
355+ <RemoveDir Directories =" $(ContainerStagingDir)" Condition =" Exists('$(ContainerStagingDir)')" />
356+ <MakeDir Directories =" $(ContainerStagingDir)" />
357+
358+ <!-- Copy the project dacpac to the known staging path -->
359+ <Copy SourceFiles =" $(TargetPath)"
360+ DestinationFiles =" $(ContainerDacpacPath)"
361+ OverWriteReadOnlyFiles =" true" />
362+
363+ <!-- Also stage all referenced dacpacs beside the project dacpac (useful for Docker COPY patterns) -->
364+ <Copy SourceFiles =" @(IncludedDacpacReferenceFiles)"
365+ DestinationFolder =" $(ContainerStagingDir)"
366+ SkipUnchangedFiles =" true" />
367+ </Target >
368+
369+ <!--
370+ PublishContainer
371+ Purpose: Build the publisher container image from the staged dacpac(s).
372+ Runs after PrepareContainerDacpac
373+ Behavior: Executes '<runtime> build' with tag and SQLPACKAGE_VERSION build-arg.
374+ Output: Local container image $(ContainerImageName):$(ContainerImageTag)
375+ -->
376+ <Target Name =" PublishContainer"
377+ DependsOnTargets =" PrepareContainerDacpac" >
378+ <Message Text =" Building container $(ContainerImageName):$(ContainerImageTag)"
379+ Importance =" high" />
380+ <Exec Command =' "$(ContainerRuntime)" build -f "$(ContainerDockerfile)" -t "$(ContainerImageName):$(ContainerImageTag)" --build-arg SQLPACKAGE_VERSION=$(SqlPackageVersion) --build-arg DACPAC_NAME=$(ContainerDacpacName) "$(MSBuildProjectDirectory)"'
381+ IgnoreExitCode =" false" />
382+ </Target >
383+
384+ <!--
385+ PushContainer
386+ Pushes to the registry implied by ContainerImageName (e.g., 'ghcr.io/org/name').
387+ Ensure you've run 'docker login' (or equivalent) for that registry first.
388+ -->
389+ <Target Name =" PushContainer" >
390+ <Message Text =" Pushing container $(ContainerImageName):$(ContainerImageTag)"
391+ Importance =" high" />
392+ <Exec Command =' "$(ContainerRuntime)" push "$(ContainerImageName):$(ContainerImageTag)"'
393+ IgnoreExitCode =" false" />
394+ </Target >
313395</Project >
0 commit comments