I am trying to automate installing a "zip" package files from Sitecore's installation wizard.
But I'm unable to work out how to allow an automation using PowerShell DSC to log in and trigger the install from here...
You can install packages via DSC - but I don't think automating the UI is the right way to go about it. When I worked through this issue I dealt with it by creating an endpoint that DSC can push the packages to without bothering with the UI:
First up, you'll need an endpoint to trigger the install. My DSC approach was based on an approach I first tried using plain PowerShell. The endpoint I used was a simple ASPX file that I grabbed from someone else's work on GitHub. The file was: https://github.com/adoprog/Sitecore-Deployment-Helpers/blob/9c93812f799216c4c676f800fb2a3f083bf73fd9/InstallModules.aspx However that's not the only example of this approach that exists, and you could just as well use someone else's endpoint file.
All that's important is that you end up with something you can deploy with a file copy and can call Sitecore's internal package management APIs as a result of an HTTP POST or GET operation.
Getting the endpoint installed requires two things: Your DSC needs to know where the file is, and it needs to copy it over.
Knowing where to find it is easy - just extend the config data you already have for your DSC script in your .psd1
file. I added the PackageInstallFile
property, and made sure that this file (from the repo linked above) was copied into the same location that all my other dependency files like the Sitecore installer were put in:
@{
AllNodes = @(
@{
WWWRoot = "C:\inetpub\wwwroot"
Sitecore = @{
InstanceName = "MyInstance"
PackageInstallFile = "PackageDeploy.aspx" <<-- This bit is new
}
}
);
}
Then you need a DSC resource to do the install. That's just a file copy:
File AddRemoteDeploy
{
DependsOn = "[script]InstallSitecore"
SourcePath = "$PackagePath\$($Node.Sitecore.PackageInstallFile)"
DestinationPath = "$($Node.WWWRoot)\$($Node.Sitecore.InstanceName)\website\$($Node.Sitecore.PackageInstallFile)"
Type = "File"
Ensure = "Present"
}
The DependsOn
property here needs to ensure this runs after you've installed Sitecore, so make sure the resource name matches yours.
Something I found that was also useful here was to make sure you "warm up" Sitecore and get it loaded into memory once you've done this bit of the install. (See my blog post on this topic for the script) as this helps ensure you don't get timeouts for the package installs.
Once you've done that, you just need to call the package installer endpoint.
I don't have a blog post on general package installs via this route for DSC (Though the logic is much the same as the pure PowerShell approach here), but I did write up how to install the Coveo for Sitecore zip package like this here: https://jermdavis.wordpress.com/2015/12/07/development-environments-with-powershell-dsc-part-7/ and you can adapt that for general installs. The key bits are putting the zip package into the right folder and calling the endpoint to trigger Sitecore to install it.
You need to have some config to describe the package to install:
@{
AllNodes = @(
@{
WWWRoot = "C:\inetpub\wwwroot"
Sitecore = @{
InstanceName = "MyInstance"
PackageInstallFile = "PackageDeploy.aspx"
NameOfYourPackage = "MyPackageFile.zip" <<-- This bit is new
}
}
);
}
That package file needs to end up copied over to Sitecore's Package directory:
File AddThePackage
{
DependsOn = "[script]InstallSitecore"
SourcePath = "$PackagePath\$($Node.Sitecore.NameOfYourPackage)"
DestinationPath = "$($Node.WWWRoot)\$($Node.Sitecore.InstanceName)\Data\packages"
Type = "File"
Ensure = "Present"
}
Then you can call the endpoint:
Script InstallAPackage
{
DependsOn = "[file]AddThePackage"
GetScript = {
@{ Feature = "Install A zip package for Sitecore" }
}
TestScript = {
$folder = "$($using:Node.WWWRoot)\$($using:Node.Sitecore.InstanceName)\Website\SomeFileOrFolderThePackageCreates"
Test-Path -Path $folder
}
SetScript = {
$siteName = $using:Node.Sitecore.InstanceName
$sitecoreFolder = "$($using:Node.WWWRoot)\$($siteName)\Data\packages"
$module = "$($using:Node.Sitecore.NameOfYourPackage)"
$query = (Split-Path -Path $module -Leaf)
Write-Verbose "Calling package upload tool for $using:query"
$url = "http://$siteName/PackageDeploy.aspx?modules=$query"
$result = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 600 -OutFile ".\$siteName-PackageResponse-$query.log" -PassThru
if($result.StatusCode -ne 200) {
Write-Verbose "StatusCode: $($result.StatusCode)"
throw "Package install failed for $query"
}
else {
Write-Verbose "Install ok"
}
$file = Join-Path $sitecoreFolder $query
Remove-Item $file -Force
}
}
Depending on the size of the package, that step may take a while. The code above tries to avoid timeouts (especially if combined with the warm-up script discussed above) but you may need further tricks for really big packages or slow servers.
The example above does only a single file, but you can extend it to install multiple things in sequence by extending the config and putting a for-loop around the install process...
(This is typed from memory - apologies in advance for any typos I've made)