[CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [string] [ValidateNotNullOrEmpty()] $LicenseXmlPath, # We do not need to use [SecureString] here since the value will be stored unencrypted in .env, # and used only for transient local example environment. [string] $SitecoreAdminPassword = "Password12345", # We do not need to use [SecureString] here since the value will be stored unencrypted in .env, # and used only for transient local example environment. [string] $SqlSaPassword = "Password12345" ) $ErrorActionPreference = "Stop"; if (-not (Test-Path $LicenseXmlPath)) { throw "Did not find $LicenseXmlPath" } if (-not (Test-Path $LicenseXmlPath -PathType Leaf)) { throw "$LicenseXmlPath is not a file" } # Check for Sitecore Gallery Import-Module PowerShellGet $SitecoreGallery = Get-PSRepository | Where-Object { $_.SourceLocation -eq "https://sitecore.myget.org/F/sc-powershell/api/v2" } if (-not $SitecoreGallery) { Write-Host "Adding Sitecore PowerShell Gallery..." -ForegroundColor Green Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2 -InstallationPolicy Trusted $SitecoreGallery = Get-PSRepository -Name SitecoreGallery } # Install and Import SitecoreDockerTools $dockerToolsVersion = "10.0.5" Remove-Module SitecoreDockerTools -ErrorAction SilentlyContinue if (-not (Get-InstalledModule -Name SitecoreDockerTools -RequiredVersion $dockerToolsVersion -AllowPrerelease -ErrorAction SilentlyContinue)) { Write-Host "Installing SitecoreDockerTools..." -ForegroundColor Green Install-Module SitecoreDockerTools -RequiredVersion $dockerToolsVersion -AllowPrerelease -Scope CurrentUser -Repository $SitecoreGallery.Name } Write-Host "Importing SitecoreDockerTools..." -ForegroundColor Green Import-Module SitecoreDockerTools -RequiredVersion $dockerToolsVersion ############################### # Populate the environment file ############################### Write-Host "Populating required .env file variables..." -ForegroundColor Green # SITECORE_ADMIN_PASSWORD Set-DockerComposeEnvFileVariable "SITECORE_ADMIN_PASSWORD" -Value $SitecoreAdminPassword # SQL_SA_PASSWORD Set-DockerComposeEnvFileVariable "SQL_SA_PASSWORD" -Value $SqlSaPassword # TELERIK_ENCRYPTION_KEY = random 64-128 chars Set-DockerComposeEnvFileVariable "TELERIK_ENCRYPTION_KEY" -Value (Get-SitecoreRandomString 128) # SITECORE_IDSECRET = random 64 chars Set-DockerComposeEnvFileVariable "SITECORE_IDSECRET" -Value (Get-SitecoreRandomString 64 -DisallowSpecial) # SITECORE_ID_CERTIFICATE $idCertPassword = Get-SitecoreRandomString 12 -DisallowSpecial Set-DockerComposeEnvFileVariable "SITECORE_ID_CERTIFICATE" -Value (Get-SitecoreCertificateAsBase64String -DnsName "localhost" -Password (ConvertTo-SecureString -String $idCertPassword -Force -AsPlainText)) # SITECORE_ID_CERTIFICATE_PASSWORD Set-DockerComposeEnvFileVariable "SITECORE_ID_CERTIFICATE_PASSWORD" -Value $idCertPassword # SITECORE_LICENSE Set-DockerComposeEnvFileVariable "SITECORE_LICENSE" -Value (ConvertTo-CompressedBase64String -Path $LicenseXmlPath) # XC_IDENTITY_COMMERCEENGINECONNECTCLIENT_CLIENTSECRET1=random 64 chars Set-DockerComposeEnvFileVariable "XC_IDENTITY_COMMERCEENGINECONNECTCLIENT_CLIENTSECRET1" -Value (Get-SitecoreRandomString 64 -DisallowSpecial) # REPORTING_API_KEY=random 32 chars Set-DockerComposeEnvFileVariable "REPORTING_API_KEY" -Value (Get-SitecoreRandomString 32) ################################## # Configure TLS/HTTPS certificates ################################## Push-Location traefik\certs try { $mkcert = ".\mkcert.exe" if ($null -ne (Get-Command mkcert.exe -ErrorAction SilentlyContinue)) { # mkcert installed in PATH $mkcert = "mkcert" } elseif (-not (Test-Path $mkcert)) { Write-Host "Downloading and installing mkcert certificate tool..." -ForegroundColor Green Invoke-WebRequest "https://github.com/FiloSottile/mkcert/releases/download/v1.4.1/mkcert-v1.4.1-windows-amd64.exe" -UseBasicParsing -OutFile mkcert.exe if ((Get-FileHash mkcert.exe).Hash -ne "1BE92F598145F61CA67DD9F5C687DFEC17953548D013715FF54067B34D7C3246") { Remove-Item mkcert.exe -Force throw "Invalid mkcert.exe file" } } Write-Host "Generating Traefik TLS certificates..." -ForegroundColor Green & $mkcert -install & $mkcert -cert-file navancommcm.localhost.crt -key-file navancommcm.localhost.key "navancommcm.localhost" & $mkcert -cert-file navancommid.localhost.crt -key-file navancommid.localhost.key "navancommid.localhost" & $mkcert -cert-file navancommauthoring.localhost.crt -key-file navancommauthoring.localhost.key "navancommauthoring.localhost" & $mkcert -cert-file navancommshops.localhost.crt -key-file navancommshops.localhost.key "navancommshops.localhost" & $mkcert -cert-file navancommminions.localhost.crt -key-file navancommminions.localhost.key "navancommminions.localhost" & $mkcert -cert-file navancommops.localhost.crt -key-file navancommops.localhost.key "navancommops.localhost" & $mkcert -cert-file navancommbizfx.localhost.crt -key-file navancommbizfx.localhost.key "navancommbizfx.localhost" } catch { Write-Host "An error occurred while attempting to generate TLS certificates: $_" -ForegroundColor Red } finally { Pop-Location } ################################ # Add Windows hosts file entries ################################ Write-Host "Adding Windows hosts file entries..." -ForegroundColor Green Add-HostsEntry "navancommcm.localhost" Add-HostsEntry "navancommid.localhost" Add-HostsEntry "navancommbizfx.localhost" Add-HostsEntry "navancommauthoring.localhost" Add-HostsEntry "navancommshops.localhost" Add-HostsEntry "navancommops.localhost" Add-HostsEntry "navancommminions.localhost" Write-Host "Done!" -ForegroundColor Green ############################################## # Create containers folder and related volumes ############################################## Write-Host "Create containers folder..." -ForegroundColor Green ..\scripts\CreateVolumeFolders.ps1 Write-Host "Done!" -ForegroundColor Green