Created
August 9, 2025 07:25
-
-
Save keyan1603/5c1f9fea423796853f923c726fbb8ad7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory = $false)] | |
| [hashtable]$WatchDirectoryParameters | |
| ) | |
| # Set logging and error handling preferences | |
| $ErrorActionPreference = "Stop" | |
| $InformationPreference = "Continue" | |
| $timeFormat = "HH:mm:ss:fff" | |
| Write-Host "$(Get-Date -Format $timeFormat): Development ENTRYPOINT: starting..." | |
| # Determine if Watch-Directory.ps1 should run | |
| $watchDirectoryJobName = "Watch-Directory.ps1" | |
| $useWatchDirectory = $null -ne $WatchDirectoryParameters -bor (Test-Path -Path "C:\deploy" -PathType "Container") -eq $true | |
| if ($useWatchDirectory) | |
| { | |
| if ($null -eq $WatchDirectoryParameters) | |
| { | |
| $WatchDirectoryParameters = @{ Path = "C:\deploy"; Destination = "C:\inetpub\wwwroot"; } | |
| } | |
| Write-Host "$(Get-Date -Format $timeFormat): Validating '$watchDirectoryJobName'..." | |
| # Dry run to validate parameters | |
| $WatchDirectoryParameters["WhatIf"] = $true | |
| & "C:\tools\scripts\Watch-Directory.ps1" @WatchDirectoryParameters | |
| $WatchDirectoryParameters["WhatIf"] = $false | |
| Write-Host "$(Get-Date -Format $timeFormat): Starting '$watchDirectoryJobName'..." | |
| # Start background file watcher | |
| Start-Job -Name $watchDirectoryJobName -ArgumentList $WatchDirectoryParameters -ScriptBlock { | |
| param([hashtable]$params) | |
| & "C:\tools\scripts\Watch-Directory.ps1" @params | |
| } | Out-Null | |
| Write-Host "$(Get-Date -Format $timeFormat): '$watchDirectoryJobName' started." | |
| } | |
| else | |
| { | |
| Write-Host "$(Get-Date -Format $timeFormat): Skipping '$watchDirectoryJobName'. Mount 'C:\deploy' to enable." | |
| } | |
| # Apply Sitecore development patches | |
| Write-Host "$(Get-Date -Format $timeFormat): Applying SITECORE_DEVELOPMENT_PATCHES..." | |
| Push-Location $PSScriptRoot\..\..\ | |
| try { | |
| . .\scripts\Get-PatchFolders.ps1 | |
| Get-PatchFolders -Path dev-patches | ForEach-Object { | |
| Write-Host "$(Get-Date -Format $timeFormat): Patching from $($_.Name)" | |
| & .\scripts\Invoke-XdtTransform.ps1 -XdtPath $_.FullName -Path $WatchDirectoryParameters.Destination | |
| & .\scripts\Install-ConfigurationFolder.ps1 -PatchPath $_.FullName -Path $WatchDirectoryParameters.Destination | |
| } | |
| } finally { | |
| Pop-Location | |
| } | |
| Write-Host "$(Get-Date -Format $timeFormat): Development ENTRYPOINT: ready!" | |
| # ------------------------ | |
| # Custom DNS Fix Section | |
| # ------------------------ | |
| $hostsFile = "C:\Windows\System32\drivers\etc\hosts" | |
| try { | |
| $DnsEntries = @("host.docker.internal", "gateway.docker.internal") | |
| foreach ($Entry in $DnsEntries) { | |
| Resolve-DnsName -Name $Entry -ErrorAction Stop | |
| } | |
| Write-Host("DNS settings are already configured.") | |
| } catch { | |
| $ip = (ipconfig | where-object {$_ -match "Default Gateway"} | foreach-object{$_.Split(":")[1]}).Trim() | |
| $src = [System.IO.File]::ReadAllLines($hostsFile) | |
| $lines = $src += "" | |
| if((cat $hostsFile | Select-String -Pattern "host.docker.internal") -And (cat $hostsFile | Select-String -Pattern "gateway.docker.internal")) { | |
| For ($i=0; $i -le $lines.length; $i++) { | |
| if ($lines[$i].Contains("host.docker.internal")) | |
| { | |
| $lines[$i] = ("{0} host.docker.internal" -f $ip) | |
| $lines[$i+1] = ("{0} gateway.docker.internal" -f $ip) | |
| break | |
| } | |
| } | |
| } else { | |
| $lines = $lines += "# Added by Docker for Windows" | |
| $lines = $lines += ("{0} host.docker.internal" -f $ip) | |
| $lines = $lines += ("{0} gateway.docker.internal" -f $ip) | |
| $lines = $lines += "# End of section" | |
| } | |
| [System.IO.File]::WriteAllLines($hostsFile, [string[]]$lines) | |
| Write-Host("New DNS settings written successfully.") | |
| } | |
| # Start Sitecore IIS service using LogMonitor | |
| & "C:\LogMonitor\LogMonitor.exe" "powershell" "C:\Run-W3SVCService.ps1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment