Added custom DB ATTACH support to the start.ps1 as well as dockerfile.

Changes to be committed:
	modified:   dockerfile
	modified:   start.ps1
This commit is contained in:
Max Knor
2016-06-21 15:12:52 +02:00
parent e742ec8a06
commit 2188003b5f
2 changed files with 32 additions and 5 deletions
@@ -12,6 +12,7 @@ MAINTAINER Perry Skountrianos
# set environment variables
ENV sql_express_download_url "https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe"
ENV sa_password _
ENV attach_dbs "[]"
# make install files accessible
COPY . /
@@ -22,9 +23,9 @@ RUN powershell -Command (New-Object System.Net.WebClient).DownloadFile('%sql_exp
RUN powershell -Command \
set-strictmode -version latest ; \
stop-service MSSQL`$%sqlinstance% ; \
stop-service MSSQL`$SQLEXPRESS ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2 ;
CMD powershell ./start %sa_password%
CMD powershell ./start -sa_password %sa_password% -attach_dbs \"%attach_dbs%\"
@@ -1,17 +1,43 @@
# The script sets the sa password and start the SQl Service
# The script sets the sa password and start the SQL Service
# Also it attaches additional database from the disk
# The format for attach_dbs
param(
[Parameter(Mandatory=$false)]
[string]$sa_password
[string]$sa_password,
[Parameter(Mandatory=$false)]
[string]$attach_dbs
)
# start the service
Write-Verbose "Starting SQL Server"
start-service MSSQL`$SQLEXPRESS
if($sa_password -ne "_"){
Write-Verbose "Changing SA login credentials"
$sqlcmd = "ALTER LOGIN sa with password=" +"'" + $sa_password + "'" + ";ALTER LOGIN sa ENABLE;"
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
}
$attach_dbs = $attach_dbs | ConvertFrom-Json
if ($null -ne $attach_dbs){
Write-Verbose "Attaching database(s)"
Foreach($db in $attach_dbs)
{
$files = @();
Foreach($file in $db.dbFiles)
{
$files += "(FILENAME = 'N$($file)')";
}
$files = $files -join ","
$sqlcmd = "sp_detach_db $($db.dbName);GO;CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;GO;"
Write-Host Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance ".\SQLEXPRESS"
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
}
}
while ($true) { Start-Sleep -Seconds 3600 }