From fc25874255b62118c722b607c82379bd5df654c6 Mon Sep 17 00:00:00 2001 From: Liz Baron <10554+lizbaron@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:49:58 -0500 Subject: [PATCH 1/3] dockerfile and related supporting scripts for creating a sql server w/ssis container --- CI/AKS/docker/Dockerfile.ssis.mssql2017 | 46 +++++++++++++++++++++++++ CI/AKS/docker/createSSISCatalog.ps1 | 26 ++++++++++++++ CI/AKS/docker/enableCLR.sql | 8 +++++ CI/AKS/docker/setupSSIS.ps1 | 8 +++++ 4 files changed, 88 insertions(+) create mode 100644 CI/AKS/docker/Dockerfile.ssis.mssql2017 create mode 100644 CI/AKS/docker/createSSISCatalog.ps1 create mode 100644 CI/AKS/docker/enableCLR.sql create mode 100644 CI/AKS/docker/setupSSIS.ps1 diff --git a/CI/AKS/docker/Dockerfile.ssis.mssql2017 b/CI/AKS/docker/Dockerfile.ssis.mssql2017 new file mode 100644 index 000000000..8b08a42da --- /dev/null +++ b/CI/AKS/docker/Dockerfile.ssis.mssql2017 @@ -0,0 +1,46 @@ +# 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 setupSSIS.ps1 / + +# 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 ; \ + Get-Service MSSQLSERVER ; + +ADD enableCLR.sql SSIS_SCRIPTS/ +ADD createSSISCatalog.ps1 SSIS_SCRIPTS/ + +RUN .\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 diff --git a/CI/AKS/docker/createSSISCatalog.ps1 b/CI/AKS/docker/createSSISCatalog.ps1 new file mode 100644 index 000000000..ac4427168 --- /dev/null +++ b/CI/AKS/docker/createSSISCatalog.ps1 @@ -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 \ No newline at end of file diff --git a/CI/AKS/docker/enableCLR.sql b/CI/AKS/docker/enableCLR.sql new file mode 100644 index 000000000..c07415b9a --- /dev/null +++ b/CI/AKS/docker/enableCLR.sql @@ -0,0 +1,8 @@ +sp_configure 'show advanced options', 1; +GO +RECONFIGURE; +GO +sp_configure 'clr enabled', 1; +GO +RECONFIGURE; +GO \ No newline at end of file diff --git a/CI/AKS/docker/setupSSIS.ps1 b/CI/AKS/docker/setupSSIS.ps1 new file mode 100644 index 000000000..a0a3add19 --- /dev/null +++ b/CI/AKS/docker/setupSSIS.ps1 @@ -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 \ No newline at end of file From 3752a25947e09927d3dc0908fe39f754e3548b75 Mon Sep 17 00:00:00 2001 From: Liz Baron <10554+lizbaron@users.noreply.github.com> Date: Fri, 31 Dec 2021 07:37:00 -0500 Subject: [PATCH 2/3] reorganized and added the beginning of a deployment script for SSIS. --- CI/AKS/docker/Dockerfile.ssis.mssql2017 | 8 +- .../{ => ssis_scripts}/createSSISCatalog.ps1 | 0 CI/AKS/docker/ssis_scripts/deployISPAC.ps1 | 89 +++++++++++++++++++ .../docker/{ => ssis_scripts}/enableCLR.sql | 0 .../docker/{ => ssis_scripts}/setupSSIS.ps1 | 0 5 files changed, 92 insertions(+), 5 deletions(-) rename CI/AKS/docker/{ => ssis_scripts}/createSSISCatalog.ps1 (100%) create mode 100644 CI/AKS/docker/ssis_scripts/deployISPAC.ps1 rename CI/AKS/docker/{ => ssis_scripts}/enableCLR.sql (100%) rename CI/AKS/docker/{ => ssis_scripts}/setupSSIS.ps1 (100%) diff --git a/CI/AKS/docker/Dockerfile.ssis.mssql2017 b/CI/AKS/docker/Dockerfile.ssis.mssql2017 index 8b08a42da..8100721e5 100644 --- a/CI/AKS/docker/Dockerfile.ssis.mssql2017 +++ b/CI/AKS/docker/Dockerfile.ssis.mssql2017 @@ -13,7 +13,7 @@ ENV exe "https://go.microsoft.com/fwlink/?linkid=840945" ENV box "https://go.microsoft.com/fwlink/?linkid=840944" ENV ACCEPT_EULA="Y" -COPY setupSSIS.ps1 / +COPY ssis_scripts/* SSIS_SCRIPTS/ # Install MSSQL 2017 RUN mode CON: CP /status ; \ @@ -25,12 +25,10 @@ RUN mode CON: CP /status ; \ 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 ; -ADD enableCLR.sql SSIS_SCRIPTS/ -ADD createSSISCatalog.ps1 SSIS_SCRIPTS/ - -RUN .\setupSSIS +RUN .\SSIS_SCRIPTS\setupSSIS RUN Get-Service MSSQLSERVER ; \ Stop-Service MSSQLSERVER ; \ diff --git a/CI/AKS/docker/createSSISCatalog.ps1 b/CI/AKS/docker/ssis_scripts/createSSISCatalog.ps1 similarity index 100% rename from CI/AKS/docker/createSSISCatalog.ps1 rename to CI/AKS/docker/ssis_scripts/createSSISCatalog.ps1 diff --git a/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 b/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 new file mode 100644 index 000000000..50934c8d5 --- /dev/null +++ b/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 @@ -0,0 +1,89 @@ +# 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, + [String[]]$PackageNames +) + +# 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." \ No newline at end of file diff --git a/CI/AKS/docker/enableCLR.sql b/CI/AKS/docker/ssis_scripts/enableCLR.sql similarity index 100% rename from CI/AKS/docker/enableCLR.sql rename to CI/AKS/docker/ssis_scripts/enableCLR.sql diff --git a/CI/AKS/docker/setupSSIS.ps1 b/CI/AKS/docker/ssis_scripts/setupSSIS.ps1 similarity index 100% rename from CI/AKS/docker/setupSSIS.ps1 rename to CI/AKS/docker/ssis_scripts/setupSSIS.ps1 From 61207875bf22cb1ddf8b1dc7c1b98dccff83d946 Mon Sep 17 00:00:00 2001 From: Liz Baron <10554+lizbaron@users.noreply.github.com> Date: Sat, 1 Jan 2022 06:43:46 -0500 Subject: [PATCH 3/3] Beginning of deployment script for container. May not be required depending on how far we can get with Windows Authentication on containers. --- CI/AKS/docker/ssis_scripts/deployISPAC.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 b/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 index 50934c8d5..789361956 100644 --- a/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 +++ b/CI/AKS/docker/ssis_scripts/deployISPAC.ps1 @@ -6,8 +6,7 @@ param( [string]$IspacUrl, [string]$TargetFolderName, [string]$ProjectFile, - [string]$ProjectName, - [String[]]$PackageNames + [string]$ProjectName ) # Load the IntegrationServices Assembly