Skip to content

minor parameter improvements and ability to download and extract automatically from dev.sitecore.net #17

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.log
*.InstallLog
/.vs
/9.0/9.0.1 Commerce/assets
/9.0/9.0.1 Commerce/Downloads
/9.0/9.0.1 Commerce/dev.creds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ param(
[string]$SqlDbPrefix = $Prefix,
[string]$CommerceSearchProvider = "SOLR",
[string]$CommerceSiteName = "$Prefix.commerce",
[string]$Drive = $($Env:SYSTEMDRIVE),
[string]$WebRoot = "C:\inetpub\wwwroot",
[string]$XConnectSiteHostHeaderName = "$($Prefix).xconnect",
[string]$SolrUrl = "https://localhost:8983/solr",
[string]$SolrInstallDir = "C:/tools/solr-6.6.2",
Expand Down Expand Up @@ -69,8 +69,8 @@ $params = @{
# CM instance and XConnect settings
SiteName = $SiteName
SiteHostHeader = $siteHostHeader
SiteInstallDir = "$($Drive)\inetpub\wwwroot\$Prefix.local"
XConnectInstallDir = "$($Drive)\inetpub\wwwroot\$Prefix.xconnect"
SiteInstallDir = "$(Join-Path $WebRoot $Prefix.local)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to wrap Join-Path in a string interpolation

XConnectInstallDir = "$(Join-Path $WebRoot $Prefix.xconnect)"

# SQL
SqlCommerceServicesDbName = "$($Prefix)_SitecoreCommerce_SharedEnvironments"
Expand All @@ -83,42 +83,42 @@ $params = @{
CommerceAuthoring = "$CommerceSiteName-authoring"
CommerceAuthoringCertificateDnsName = "*.$Prefix.local"
CommerceAuthoringCertificateName = "all.$Prefix.local"
CommerceAuthoringDir = "$($Env:SYSTEMDRIVE)\inetpub\wwwroot\$CommerceSiteName-authoring"
CommerceAuthoringDir = "$(Join-Path $WebRoot $('{0}-authoring' -f $CommerceSiteName))"
CommerceAuthoringHostHeader = "commerce-authoring.$SiteName"
CommerceAuthoringServicesPort = "443"

CommerceMinions = "$CommerceSiteName-minions"
CommerceMinionsCertificateDnsName = "*.$Prefix.local"
CommerceMinionsCertificateName = "all.$Prefix.local"
CommerceMinionsDir = "$($Env:SYSTEMDRIVE)\inetpub\wwwroot\$CommerceSiteName-minions"
CommerceMinionsDir = "$(Join-Path $WebRoot $('{0}-minions' -f $CommerceSiteName))"
CommerceMinionsHostHeader = "commerce-minions.$SiteName"
CommerceMinionsServicesPort = "443"

CommerceOps = "$CommerceSiteName-ops"
CommerceOpsCertificateDnsName = "*.$Prefix.local"
CommerceOpsCertificateName = "all.$Prefix.local"
CommerceOpsDir = "$($Env:SYSTEMDRIVE)\inetpub\wwwroot\$CommerceSiteName-ops"
CommerceOpsDir = "$(Join-Path $WebRoot $('{0}-ops' -f $CommerceSiteName))"
CommerceOpsHostHeader = "commerce-ops.$SiteName"
CommerceOpsServicesPort = "443"

CommerceShops = "$CommerceSiteName-shops"
CommerceShopsCertificateDnsName = "*.$Prefix.local"
CommerceShopsCertificateName = "all.$Prefix.local"
CommerceShopsDir = "$($Env:SYSTEMDRIVE)\inetpub\wwwroot\$CommerceSiteName-shops"
CommerceShopsDir = "$(Join-Path $WebRoot $('{0}-shops' -f $CommerceSiteName))"
CommerceShopsHostHeader = "commerce-shops.$SiteName"
CommerceShopsServicesPort = "443"

SitecoreIdentityServer = "$CommerceSiteName-identity"
SitecoreIdentityServerCertificateDnsName = "*.$Prefix.local"
SitecoreIdentityServerCertificateName = "all.$Prefix.local"
SitecoreIdentityServerDir = "$($Env:SYSTEMDRIVE)\inetpub\wwwroot\$CommerceSiteName-identity"
SitecoreIdentityServerDir = "$(Join-Path $WebRoot $('{0}-identity' -f $CommerceSiteName))"
SitecoreIdentityServerHostHeader = "identity.$SiteName"
SitecoreIdentityServerServicesPort = "443"

SitecoreBizFx = "$CommerceSiteName-bizfx"
SitecoreBizFxCertificateDnsName = "*.$Prefix.local"
SitecoreBizFxCertificateName = "all.$Prefix.local"
SitecoreBizFxDir = "$($Env:SYSTEMDRIVE)\inetpub\wwwroot\$CommerceSiteName-bizfx"
SitecoreBizFxDir = "$(Join-Path $WebRoot $('{0}-bizfx' -f $CommerceSiteName))"
SitecoreBizFxHostHeader = "bizfx.$SiteName"
SitecoreBizFxServicesPort = "443"

Expand All @@ -127,24 +127,24 @@ $params = @{
CommerceEngineCertificateName = $CommerceSiteName

# Packages
PackageAdventureWorksImagesPath = Resolve-Path -Path "..\Adventure Works Images.zip"
PackageCEConnectPath = Resolve-Path -Path "..\Sitecore.Commerce.Engine.Connect*.update"
PackageCommerceConnectPath = Resolve-Path -Path "..\Sitecore Commerce Connect*.zip"
PackageCommerceEngineDacPacPath = Resolve-Path -Path "..\Sitecore.Commerce.Engine.SDK.2.1.10\Sitecore.Commerce.Engine.DB.dacpac"
PackageHabitatImagesPath = Resolve-Path -Path "..\Sitecore.Commerce.Habitat.Images-*.zip"
PackagePowerShellExtensionsPath = Resolve-Path -Path "..\Sitecore PowerShell Extensions-4.7.2 for Sitecore 8.zip"
PackageSitecoreBizFxServicesContentDir = Resolve-Path -Path "..\Sitecore.BizFX.1.1.9"
PackageSitecoreCommerceEnginePath = Resolve-Path -Path "..\Sitecore.Commerce.Engine.2.*.zip"
PackageSitecoreIdentityServerPath = Resolve-Path -Path "..\Sitecore.IdentityServer.1.*.zip"
PackageSXACommercePath = Resolve-Path -Path "..\Sitecore Commerce Experience Accelerator 1.*.zip"
PackageSXAPath = Resolve-Path -Path "..\Sitecore Experience Accelerator 1.7 rev. 180410 for 9.0.zip"
PackageSXAStorefrontCatalogPath = Resolve-Path -Path "..\Sitecore Commerce Experience Accelerator Habitat Catalog*.zip"
PackageSXAStorefrontPath = Resolve-Path -Path "..\Sitecore Commerce Experience Accelerator Storefront 1.*.zip"
PackageSXAStorefrontThemePath = Resolve-Path -Path "..\Sitecore Commerce Experience Accelerator Storefront Themes*.zip"
PackageAdventureWorksImagesPath = Resolve-Path -Path "..\assets\Adventure Works Images.zip"
PackageCEConnectPath = Resolve-Path -Path "..\assets\Sitecore.Commerce.Engine.Connect*.update"
PackageCommerceConnectPath = Resolve-Path -Path "..\assets\Sitecore Commerce Connect*.zip"
PackageCommerceEngineDacPacPath = Resolve-Path -Path "..\assets\Sitecore.Commerce.Engine.SDK.2.1.10\Sitecore.Commerce.Engine.DB.dacpac"
PackageHabitatImagesPath = Resolve-Path -Path "..\assets\Sitecore.Commerce.Habitat.Images-*.zip"
PackagePowerShellExtensionsPath = Resolve-Path -Path "..\assets\Sitecore PowerShell Extensions-4.7.2 for Sitecore 8.zip"
PackageSitecoreBizFxServicesContentDir = Resolve-Path -Path "..\assets\Sitecore.BizFX.1.1.9"
PackageSitecoreCommerceEnginePath = Resolve-Path -Path "..\assets\Sitecore.Commerce.Engine.2.*.zip"
PackageSitecoreIdentityServerPath = Resolve-Path -Path "..\assets\Sitecore.IdentityServer.1.*.zip"
PackageSXACommercePath = Resolve-Path -Path "..\assets\Sitecore Commerce Experience Accelerator 1.*.zip"
PackageSXAPath = Resolve-Path -Path "..\assets\Sitecore Experience Accelerator 1.7 rev. 180410 for 9.0.zip"
PackageSXAStorefrontCatalogPath = Resolve-Path -Path "..\assets\Sitecore Commerce Experience Accelerator Habitat Catalog*.zip"
PackageSXAStorefrontPath = Resolve-Path -Path "..\assets\Sitecore Commerce Experience Accelerator Storefront 1.*.zip"
PackageSXAStorefrontThemePath = Resolve-Path -Path "..\assets\Sitecore Commerce Experience Accelerator Storefront Themes*.zip"

# Tools
ToolsSiteUtilitiesDir = ( Join-Path -Path $DEPLOYMENT_DIRECTORY -ChildPath "SiteUtilityPages" )
ToolsMergeToolPath = Resolve-Path -Path "..\msbuild.microsoft.visualstudio.web.targets.14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.XmlTransform.dll"
ToolsMergeToolPath = Resolve-Path -Path "..\assets\msbuild.microsoft.visualstudio.web.targets.14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.XmlTransform.dll"

# Accounts
SitecoreUsername = $SitecoreUsername
Expand Down
1 change: 1 addition & 0 deletions 9.0/9.0.1 Commerce/assets/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop all files here as outlined in the installation documents
206 changes: 206 additions & 0 deletions 9.0/9.0.1 Commerce/download-and-extract.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@

Param(
$DownloadFolder = "", #Defaults to .\assets\Downloads
$CommerceAssetFolder = "" #Defaults to .\assets

)


$packagesToExtract = ('{"files":[
{
"name": "SIF.Sitecore.Commerce",
"version": "1.1.4"
},
{
"name": "Sitecore.Commerce.Engine",
"version": "2.1.55"
},
{
"name": "Sitecore.BizFX",
"version": "1.1.9"
},
{
"name": "Sitecore.Commerce.Engine.SDK",
"version": "2.1.10"
}
]}') | ConvertFrom-Json

if ($DownloadFolder -eq "" -or $DownloadFolder -eq $null) {
$DownloadFolder = Join-Path "$PWD" "Downloads"
if (!(Test-Path $DownloadFolder)) {
New-Item -ItemType Directory -Force -Path $DownloadFolder
}
}
if ($CommerceAssetFolder -eq "" -or $CommerceAssetFolder -eq $null) {
$CommerceAssetFolder = Join-Path "$PWD" "assets"
}

Function Invoke-FetchSitecoreCredentials {
# Credit: https://jermdavis.wordpress.com/2017/11/27/downloading-stuff-from-dev-sitecore-net/
$file = "dev.creds.xml"

if (Test-Path ".\\$file") {
$cred = Import-Clixml ".\\$file"
}
else {
$cred = Get-Credential -Message "Enter your SDN download credentials:"
$cred | Export-Clixml ".\\$file"
}

return $cred
}

Function Invoke-FetchDownloadAuthentication($cred) {
# Credit: https://jermdavis.wordpress.com/2017/11/27/downloading-stuff-from-dev-sitecore-net/

$authUrl = "https://dev.sitecore.net/api/authorization"

$pwd = $cred.GetNetworkCredential().Password

$postParams = "{ ""username"":""$($cred.UserName)"", ""password"":""$pwd"" }"

$authResponse = Invoke-WebRequest -Uri $authUrl -Method Post -ContentType "application/json;charset=UTF-8" -Body $postParams -SessionVariable webSession
$authCookies = $webSession.Cookies.GetCookies("https://sitecore.net")

$marketPlaceCookie = $authCookies["marketplace_login"]

if ([String]::IsNullOrWhiteSpace($marketPlaceCookie)) {
throw "Credentials appear invalid"
}

$devUrl = "https://dev.sitecore.net"

$devResponse = Invoke-WebRequest -Uri $devUrl -WebSession $webSession
$devCookies = $webSession.Cookies.GetCookies("https://dev.sitecore.net")

$sessionCookie = $devCookies["ASP.Net_SessionId"]

return "$marketPlaceCookie; $sessionCookie"
}

function Invoke-SitecoreFileDownload {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string] $Uri,

[Parameter(Mandatory)]
[string] $OutputFile,

[string] $cookies
)
# Credit: https://jermdavis.wordpress.com/2017/11/27/downloading-stuff-from-dev-sitecore-net/

$webClient = New-Object System.Net.WebClient

if (!([String]::IsNullOrWhiteSpace($cookies))) {
$webClient.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie)
}

$data = New-Object psobject -Property @{Uri = $Uri; OutputFile = $OutputFile}

$changed = Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged -MessageData $data -Action {
Write-Progress -Activity "Downloading $($event.MessageData.Uri)" -Status "To $($event.MessageData.OutputFile)" -PercentComplete $eventArgs.ProgressPercentage
}

try {
$handle = $webClient.DownloadFileAsync($Uri, $PSCmdlet.GetUnresolvedProviderPathFromPSPath($OutputFile))

while ($webClient.IsBusy) {
Start-Sleep -Milliseconds 1000
}
}
finally {
Write-Progress -Activity "Downloading $Uri" -Completed

Remove-Job $changed -Force
Get-EventSubscriber | Where SourceObject -eq $webClient | Unregister-Event -Force
}
}
Function Invoke-SitecoreDownload {
param(
[string]$url,
[string]$target
)

$cred = Invoke-FetchSitecoreCredentials
$cookie = Invoke-FetchDownloadAuthentication $cred

Invoke-SitecoreFileDownload -Uri $url -OutputFile $target -Cookies $cookie
Copy link
Owner

@asmagin asmagin Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all Invoke-FetchDownloadAuthentication, Invoke-SitecoreFileDownload
can be replaced with:

$loginRequest = Invoke-RestMethod -Uri https://dev.sitecore.net/api/authorization -Method Post -ContentType "application/json" -Body "{username: '$user', password: '$password'}" -SessionVariable session -UseBasicParsing
Invoke-WebRequest -Uri $package_url -WebSession $session -OutFile $package_zip_path -UseBasicParsing

Using this approach in sitecore-packer
https://github.com/asmagin/sitecore-packer/blob/5af9ed72746d3bb64fe598373594db2eb5458f95/src/components/commerce/chef/cookbooks/scp_commerce/resources/901.rb#L20-L23


}
Function Invoke-DownloadAndExtractAssets {


$CommercePackageUrl = "https://dev.sitecore.net/~/media/F08E9950D0134D1DA325801057C96B35.ashx" #Your download url here
$commercePackageFileName = "Sitecore.Commerce.2018.03-2.1.55.zip"
$commercePackageDestination = $([io.path]::combine($DownloadFolder, $commercePackageFileName)).ToString()

Write-Host "Saving $CommercePackageUrl to $commercePackageDestination - if required" -ForegroundColor Green
if (!(Test-Path $commercePackageDestination)) {
Invoke-SitecoreDownload $CommercePackageUrl $commercePackageDestination
}


$sxaPackageUrl = "https://dev.sitecore.net/~/media/573443081B494E2B9D83D3208B549E49.ashx"
$sxaPackageDestination = $([io.path]::combine($CommerceAssetFolder, "Sitecore Experience Accelerator 1.7 rev. 180410 for 9.0.zip"))
if (!(Test-Path $sxaPackageDestination)) {
Invoke-SitecoreDownload $sxaPackageUrl $sxaPackageDestination
}

$spePackageUrl = "https://marketplace.sitecore.net/services/~/download/3D2CADDAB4A34CEFB1CFD3DD86D198D5.ashx?data=Sitecore%20PowerShell%20Extensions-4.7.2%20for%20Sitecore%208&itemId=6aaea046-83af-4ef1-ab91-87f5f9c1aa57"
$spePackageDestination = $([io.path]::combine($CommerceAssetFolder, "Sitecore PowerShell Extensions-4.7.2 for Sitecore 8.zip"))

if (!(Test-Path $spePackageDestination)) {
Invoke-SitecoreDownload $spePackageUrl $spePackageDestination
}

$msbuildNuGetUrl = "https://www.nuget.org/api/v2/package/MSBuild.Microsoft.VisualStudio.Web.targets/14.0.0.3"
$msbuildNuGetPackageFileName = "msbuild.microsoft.visualstudio.web.targets.14.0.0.3.nupkg"
$msbuildNuGetPackageDestination = $([io.path]::combine($DownloadFolder, $msbuildNuGetPackageFileName))

Write-Host "Saving $msbuildNuGetUrl to $msbuildNuGetPackageDestination - if required" -ForegroundColor Green
if (!(Test-Path $msbuildNuGetPackageDestination)) {
Invoke-WebRequest -Uri $msbuildNuGetUrl -OutFile $msbuildNuGetPackageDestination
#Start-BitsTransfer -source $msbuildNuGetUrl -Destination $msbuildNuGetPackageDestination
}
$aspnetCoreGetUrl = "https://aka.ms/dotnetcore-2-windowshosting"
$aspnetCoreFileName = "DotNetCore.2.0.5-WindowsHosting.exe"
$aspnetPackageDestination = $([io.path]::combine($DownloadFolder, $aspnetCoreFileName))

Write-Host "Saving $aspnetCoreGetUrl to $aspnetPackageDestination - if required" -ForegroundColor Green
if (!(Test-Path $aspnetPackageDestination)) {
Start-BitsTransfer -source $aspnetCoreGetUrl -Destination $aspnetPackageDestination
}

$netCoreSDKUrl = "https://download.microsoft.com/download/0/F/D/0FD852A4-7EA1-4E2A-983A-0484AC19B92C/dotnet-sdk-2.0.0-win-x64.exe"
$netCoreSDKFileName = "dotnet-sdk-2.0.0-win-x64.exe"
$netCoreSDKPackageDestination = $([io.path]::combine($DownloadFolder, $netCoreSDKFileName))

Write-Host "Saving $netCoreSDKUrl to $netCoreSDKPackageDestination - if required" -ForegroundColor Green
if (!(Test-Path $netCoreSDKPackageDestination)) {
Start-BitsTransfer -source $netCoreSDKUrl -Destination $netCoreSDKPackageDestination
}
Copy link
Collaborator

@KayeeNL KayeeNL Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not take the latest version of the .net core runtime and sdk of 2.1.0? And I think we need to explicitly add something to the readme file that these installers (pre-reqs) need to be installed first before running the deploy script

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't it be installed once you have XP 9 on the machine?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XP 9 doesn't require .NET core, that's why it was part of my XC 9 install.



Write-Host "Extracting to $($CommerceAssetFolder)"
set-alias sz "$env:ProgramFiles\7-zip\7z.exe"
sz x -o"$CommerceAssetFolder" $commercePackageDestination -y -aoa

foreach ($package in $packagesToExtract.files) {

$extract = Join-Path $CommerceAssetFolder $($package.name + "." + $package.version + ".zip")
$output = Join-Path $CommerceAssetFolder $($package.name + "." + $package.version)


sz x -o"$($output)" $extract -r -y -aoa
}
#Extract MSBuild nuget package
$extract = $(Join-Path $DownloadFolder "msbuild.microsoft.visualstudio.web.targets.14.0.0.3.nupkg")
$output = $(Join-Path $CommerceAssetFolder "msbuild.microsoft.visualstudio.web.targets.14.0.0.3")
sz x -o"$($output)" $extract -r -y -aoa

}


Invoke-DownloadAndExtractAssets