-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-sql.msbuild
More file actions
44 lines (36 loc) · 2.34 KB
/
Copy pathtest-sql.msbuild
File metadata and controls
44 lines (36 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildDatabase">
<PropertyGroup>
<SQLServer Condition="'$(SQLServer)'==''">localhost</SQLServer>
<SQLServerUser Condition="'$(SQLServerUser)'==''">SA</SQLServerUser>
<SQLServerPassword Condition="'$(SQLServerPassword)'==''">MyPass@word</SQLServerPassword>
<SQLServerDataPath Condition="'$(SQLServerDataPath)'==''">$(MSBuildThisFileDirectory)sqldata</SQLServerDataPath>
<SQLImage Condition="'$(SQLImage)'==''">mcr.microsoft.com/azure-sql-edge</SQLImage>
<SQLContainerName Condition="'$(SQLContainerName)'==''">sqltest</SQLContainerName>
<DockerNetworkName>kb-builder-net</DockerNetworkName>
<SQLSetupScriptName>./setup-and-wait-for-sql.sh</SQLSetupScriptName>
</PropertyGroup>
<Target Name="BuildDatabase" DependsOnTargets="RunSqlContainer;CreateDatabase;StopSqlContainer;CopyMdfFiles;ListMdfFiles" />
<Target Name="RunSqlContainer">
<Message Text="Executing SQL Server setup and wait script..." Importance="High" />
<Exec Command="$(SQLSetupScriptName) $(SQLContainerName) $(SQLImage) '$(SQLServerPassword)'" ConsoleToMSBuild="true" />
</Target>
<Target Name="StopSqlContainer">
<Message Text="Stopping SQL container..." Importance="High" />
<Exec Command="docker stop $(SQLContainerName)" IgnoreExitCode="true" />
<Exec Command="docker rm $(SQLContainerName)" />
</Target>
<Target Name="CreateDatabase">
<Message Text="Creating TestDB..." Importance="High" />
<Exec Command="/opt/mssql-tools18/bin/sqlcmd -S $(SQLContainerName) -U $(SQLServerUser) -P "$(SQLServerPassword)" -C -Q "CREATE DATABASE TestDB"" />
<Exec Command="/opt/mssql-tools18/bin/sqlcmd -S $(SQLContainerName) -U $(SQLServerUser) -P "$(SQLServerPassword)" -C -Q "SELECT name FROM sys.databases"" />
</Target>
<Target Name="CopyMdfFiles">
<Message Text="Creating local directory to store database files..." Importance="High" />
<Exec Command="docker cp "$(SQLContainerName):/var/opt/mssql/data/GX_KB_Base.mdf" "$(KBPath)"" />
<Exec Command="docker cp "$(SQLContainerName):/var/opt/mssql/data/GX_KB_Base_log.ldf" "$(KBPath)"" />
</Target>
<Target Name="ListMdfFiles">
<Message Text="Listing MDF/LDF files in $(KBPath)" Importance="High" />
<Exec Command="ls -l $(KBPath)" />
</Target>
</Project>