Skip to content

dockerfile and related supporting scripts for creating a sql server w… #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions CI/AKS/docker/Dockerfile.ssis.mssql2017
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Adapted from: https://github.com/Microsoft/mssql-docker/blob/master/windows/mssql-server-windows-developer/dockerfile
#
#
FROM mcr.microsoft.com/windows/servercore:ltsc2019
LABEL maintainer "Liz B & Sebastian M"

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Continue'; $ProgressPreference = 'SilentlyContinue';"]

WORKDIR /

# MSSQL 2017 Download links
ENV exe "https://go.microsoft.com/fwlink/?linkid=840945"
ENV box "https://go.microsoft.com/fwlink/?linkid=840944"
ENV ACCEPT_EULA="Y"

COPY ssis_scripts/* SSIS_SCRIPTS/

# Install MSSQL 2017
RUN mode CON: CP /status ; \
CHCP ; \
CHCP 437 ; \
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" | Select-Object OEMCP, ACP ; \
Invoke-WebRequest -Uri $env:box -OutFile SQL.box ; \
Invoke-WebRequest -Uri $env:exe -OutFile SQL.exe ; \
Start-Process -Wait -FilePath .\SQL.exe -ArgumentList /qs, /x:setup ; \
.\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine,IS /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS ; \
Remove-Item -Recurse -Force SQL.exe, SQL.box, setup ; \
mkdir SSIS_TMP ; \
Get-Service MSSQLSERVER ;

RUN .\SSIS_SCRIPTS\setupSSIS

RUN Get-Service MSSQLSERVER ; \
Stop-Service MSSQLSERVER ; \
Set-ItemProperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
Set-ItemProperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
Set-ItemProperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\' -name LoginMode -value 2 ;
HEALTHCHECK CMD [ "sqlcmd", "-Q", "select 1" ]

COPY start.ps1 /
RUN net user /add LOCAL_SQLSRVR
RUN powershell -Command Add-LocalGroupMember -Group "Administrators" -Member "LOCAL_SQLSRVR"
USER LOCAL_SQLSRVR
CMD .\start -ACCEPT_EULA $env:ACCEPT_EULA -sqlsrvrlogin "LOCAL_SQLSRVR" -Verbose *> start_script.log
26 changes: 26 additions & 0 deletions CI/AKS/docker/ssis_scripts/createSSISCatalog.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# from https://github.com/teach-for-america/ssiscicd/blob/master/docker/mssqlssis/create_ssis_catalog.ps1
# script to create ssis catalog and deploy ssis ispac file

# Load the IntegrationServices Assembly
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices")

# Store the IntegrationServices Assembly namespace to avoid typing it every time
$ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"

Write-Host "Connecting to server ..."

# Create a connection to the server
$sqlConnectionString = "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

Write-Host "connection string: "+$sqlConnectionString
Write-Host "connection: "+$sqlConnection

# Create the Integration Services object
$integrationServices = New-Object $ISNamespace".IntegrationServices" $sqlConnection

# Provision a new SSIS Catalog
$catalog = New-Object $ISNamespace".Catalog" ($integrationServices, "SSISDB", "P@assword1")
$catalog.Create()

Write-Host "Catalog created: "+$catalog
88 changes: 88 additions & 0 deletions CI/AKS/docker/ssis_scripts/deployISPAC.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# script to deploy ssis ispac file and run the file as a Windows Authenticated user on the SQL Server machine.
# Adapted from https://docs.microsoft.com/en-us/sql/integration-services/ssis-quickstart-deploy-powershell?view=sql-server-ver15
# Adapted most recently from https://github.com/teach-for-america/ssiscicd/blob/master/docker/mssqlssis/deploy_ssis_package.ps1

param(
[string]$IspacUrl,
[string]$TargetFolderName,
[string]$ProjectFile,
[string]$ProjectName
)

# Load the IntegrationServices Assembly
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices")

# Store the IntegrationServices Assembly namespace to avoid typing it every time
$ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"

# Create a connection to the server
$sqlConnectionString = "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
Write-Host "Connecting to server ..."
Write-Host "connection string: "+$sqlConnectionString
Write-Host "connection: "+$sqlConnection

# Create the Integration Services object
$integrationServices = New-Object $ISNamespace".IntegrationServices" $sqlConnection
Write-Host "IntegrationServices object: "+$integrationServices

# Get the Integration Services catalog
$catalog = $integrationServices.Catalogs["SSISDB"]
Write-Host "Catalog: " +$catalog

# Wait till catalog is available
while ($true){
# Get the Integration Services catalog
$catalog = $integrationServices.Catalogs["SSISDB"]
if(!$catalog){
Write-Verbose "Waiting for create SSISDB Catalog to complete."
Start-Sleep -Seconds 5
}
else {
break
Write-Verbose "SSIS Catalog is available."
}
}

$folder = $catalog.Folders[$TargetFolderName]

if(!$folder){
# Create the target folder
$folder = New-Object $ISNamespace".CatalogFolder" ($catalog, $TargetFolderName, "Folder description")
$folder.Create()
Write-Host "Folder created: " + $folder
} else {
Write-Host "Folder exists: " + $folder
}

# $IspacUrl - url to download from Azure blob storage
Write-Host "Downloading " $IspacUrl " ispac file ..."

$targetDir = "C:\SSIS_ISPACS";

if( -Not (Test-Path -Path $targetDir ) ) {
New-Item -ItemType directory -Path $targetDir
Write-Host "Folder created: " + $targetDir
}
else {
Write-Host "$targetDir Folder exists: "
}

Invoke-WebRequest -Uri $IspacUrl -UseBasicParsing -OutFile "C:\SSIS_ISPACS\$ProjectFile"

$ProjectFilePath="C:\SSIS_ISPACS\$ProjectFile"

Write-Host "Folder: " + $folder
Write-Host "Deploying " $ProjectName " project ..."
Write-Host "From " $ProjectFilePath " project file path..."

# Read the project file and deploy it
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($ProjectFilePath)
$folder.DeployProject($ProjectName, $projectFile)

# Get the project
$project = $folder.Projects[$ProjectName]

Write-Host "Project deployment complete... " $project "..."

Write-Host "Done."
8 changes: 8 additions & 0 deletions CI/AKS/docker/ssis_scripts/enableCLR.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
8 changes: 8 additions & 0 deletions CI/AKS/docker/ssis_scripts/setupSSIS.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# from https://github.com/teach-for-america/ssiscicd/blob/master/docker/mssqlssis/setupSSIS.ps1
Write-Verbose "Enable CLR Integration."
$enableCLRsqlcmd = "C:\SSIS_SCRIPTS\enableCLR.sql"
& sqlcmd -i $enableCLRsqlcmd

Write-Verbose "Create SSIS Catalog."
$create_SSIS_Catalog_Script= "C:\SSIS_SCRIPTS\createSSISCatalog.ps1"
&$create_SSIS_Catalog_Script