@@ -29,20 +29,20 @@ $ResultBuilder = New-Object System.Text.StringBuilder
2929$Artifact = Get-Content - Path $Manifest - Raw | ConvertFrom-Json
3030
3131if ($Artifact.Status -eq ' Present' ) {
32+ $DockerfileTemplate = ' Dockerfile-IIS.template'
3233 Write-Verbose (' Copying {0} configuration files' -f $ArtifactName )
3334 $ConfigPath = $Mount.Path + " \" + " Windows\System32\inetsrv\config"
3435 if (Test-Path - Path $ConfigPath ) {
3536 Copy-Item $ConfigPath $ManifestPath - Recurse
3637 }
37-
38- Write-Verbose - Message (' Writing instruction to install IIS' )
39- $null = $ResultBuilder.AppendLine (' # Install Windows features for IIS' )
40- $null = $ResultBuilder.Append (' RUN Add-WindowsFeature Web-server' )
4138 if ($Artifact.AspNetStatus -eq ' Present' ) {
42- Write-Verbose - Message (' Writing instruction to install ASP.NET' )
43- $null = $ResultBuilder.Append (' , NET-Framework-45-ASPNET, Web-Asp-Net45' )
39+ $DockerfileTemplate = ' Dockerfile-ASPNET.template'
4440 }
45- $null = $ResultBuilder.AppendLine (' ' )
41+ if ($Artifact.AspNet35Status -eq ' Present' ) {
42+ $DockerfileTemplate = ' Dockerfile-ASPNET-35.template'
43+ }
44+ $Dockerfile = Get-Content - Raw - Path " $ModulePath \Resources\$DockerfileTemplate "
45+ $null = $ResultBuilder.AppendLine ($Dockerfile.Trim ())
4646
4747 if ($Artifact.FeatureName.length -gt 0 ) {
4848 $null = $ResultBuilder.AppendLine (" RUN Enable-WindowsOptionalFeature -Online -FeatureName $ ( $Artifact.FeatureName.Replace (' ;' , ' ,' )) " )
@@ -58,31 +58,93 @@ if ($Artifact.Status -eq 'Present') {
5858 $null = $ResultBuilder.AppendLine (' ' )
5959 }
6060
61- $null = $ResultBuilder.AppendLine (' ' )
62- $null = $ResultBuilder.AppendLine (" RUN Remove-Website 'Default Web Site'" )
63-
6461 $null = $ResultBuilder.AppendLine (' ' )
6562 for ($i = 0 ;$i -lt $Artifact.Websites.Count ;$i ++ ) {
63+ $WebSiteBuilder = New-Object System.Text.StringBuilder
6664 $Site = $Artifact.Websites [$i ]
67- $SitePath = $Mount.Path + $Site.PhysicalPath
68- Write-Verbose - Message (' Copying website files from {0} to {1}' -f $SitePath , $ManifestPath )
69- Copy-Item $SitePath $ManifestPath - Recurse
65+ $null = $WebSiteBuilder.AppendLine (" # Set up website: $ ( $Site.Name ) " )
7066
71- Write-Verbose - Message (' Writing instruction to copy files for {0} site' -f $Site.Name )
72- $null = $ResultBuilder.AppendLine (" # Set up website: $ ( $Site.Name ) " )
73- $copy = " COPY {0} {1}" -f (Split-Path $Site.PhysicalPath - Leaf), ($Site.PhysicalPath -Replace " \\" , " /" )
74- $null = $ResultBuilder.AppendLine ($copy )
67+ if ($Site.Applications -is [system.array ]){
68+ $mainApp = $Site.Applications.where {$_.Path -eq ' /' }
69+ }
70+ else {
71+ $mainApp = $Site.Applications
72+ }
73+ if ($mainApp.VirtualDirectories -is [system.array ]){
74+ $mainVirtualDir = $mainApp.VirtualDirectories.where {$_.Path -eq ' /' }
75+ }
76+ else {
77+ $mainVirtualDir = $mainApp.VirtualDirectories
78+ }
79+ $mainBinding = $Site.Bindings [0 ]
7580
7681 Write-Verbose - Message (' Writing instruction to create site {0}' -f $Site.Name )
77- $newSite = ' RUN New-Website -Name '' {0}'' -PhysicalPath "C:{1}" -Port {2} -Force' -f ($Site.Name -replace " '" , " ''" ), $Site.PhysicalPath , $Site.binding.bindingInformation.split (' :' )[-2 ]
78- $null = $ResultBuilder.AppendLine ($newSite )
7982
80- Write-Verbose - Message (' Writing instruction to expose port for site {0}' -f $Site.Name )
81- $null = $ResultBuilder.AppendLine (" EXPOSE $ ( $Site.binding.bindingInformation.split (' :' )[-2 ]) " )
83+ # create empty paths for all the site directories
84+ $newPath = " RUN New-Item -Path 'C:$ ( $mainVirtualDir.PhysicalPath ) ' -Type Directory; `` "
85+ $null = $WebSiteBuilder.AppendLine ($newPath )
86+
87+ $sourcePaths = $Site.Applications.VirtualDirectories.PhysicalPath
88+ ForEach ($sourcePath in $sourcePaths ) {
89+ if ($sourcePath -ne $mainVirtualDir.PhysicalPath ) {
90+ $newPath = " New-Item -Path 'C:$sourcePath ' -Type Directory -Force; `` "
91+ $null = $WebSiteBuilder.AppendLine ($newPath )
92+ }
93+ }
94+
95+ $null = $ResultBuilder.AppendLine ($WebSiteBuilder.ToString ().Trim().TrimEnd(' ``' ))
96+ $null = $ResultBuilder.AppendLine (' ' )
97+ $WebSiteBuilder = New-Object System.Text.StringBuilder
98+
99+ # creating the website creates the default app & vdir underneath it
100+ $newSite = " RUN New-Website -Name '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $mainVirtualDir.PhysicalPath ) ' -Port $ ( $mainBinding.BindingInformation.split (' :' )[-2 ]) -Force; `` "
101+ $null = $WebSiteBuilder.AppendLine ($newSite )
102+
103+ # now create additional apps and vdirs
104+ ForEach ($application in $Site.Applications ) {
105+ $appVirtualDir = $application.VirtualDirectories.where {$_.Path -eq ' /' }
106+ $appName = $application.Path.Substring (1 ) # remove initial '/'
107+
108+ if ($appName.Length -gt 0 ) {
109+ Write-Verbose - Message (' Creating web app {0}' -f $appName )
110+ $newApp = " New-WebApplication -Name '$appName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $appVirtualDir.PhysicalPath ) ' -Force; `` "
111+ $null = $WebSiteBuilder.AppendLine ($newApp )
112+ }
113+
114+ $virtualDirectories = $application.VirtualDirectories.where {$_.Path -ne ' /' }
115+ ForEach ($virtualDir in $virtualDirectories ) {
116+ $dirName = $virtualDir.Path.Substring (1 ) # remove initial '/'
117+ Write-Verbose - Message (' Creating virtual directory {0}' -f $dirName )
118+ $newDir = ' '
119+ if ($appName.Length -gt 0 ) {
120+ $newDir = " New-WebVirtualDirectory -Name '$dirName ' -Application '$appName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $virtualDir.PhysicalPath ) '; `` "
121+ }
122+ else {
123+ $newDir = " New-WebVirtualDirectory -Name '$dirName ' -Site '$ ( $Site.Name ) ' -PhysicalPath 'C:$ ( $virtualDir.PhysicalPath ) '; `` "
124+ }
125+ $null = $WebSiteBuilder.AppendLine ($newDir )
126+ }
127+ }
128+ $null = $ResultBuilder.AppendLine ($WebSiteBuilder.ToString ().Trim().TrimEnd(' ``' ))
129+ $null = $ResultBuilder.AppendLine (' ' )
130+
131+ Write-Verbose - Message (' Writing instruction to expose port for site {0}' -f $Site.Name )
132+ $null = $ResultBuilder.AppendLine (" EXPOSE $ ( $mainBinding.BindingInformation.split (' :' )[-2 ]) " )
82133 $null = $ResultBuilder.AppendLine (' ' )
134+
135+ $sourcePaths = $Site.Applications.VirtualDirectories.PhysicalPath
136+ ForEach ($sourcePath in $sourcePaths ) {
137+ $SitePath = $Mount.Path + $sourcePath
138+ Write-Verbose - Message (' Copying website files from {0} to {1}' -f $SitePath , $ManifestPath )
139+ Copy-Item $SitePath $ManifestPath - Recurse - Force
140+
141+ Write-Verbose - Message (' Writing instruction to copy files for {0} site' -f $Site.Name )
142+ $copy = " COPY {0} {1}" -f (Split-Path $sourcePath - Leaf), ($sourcePath -Replace " \\" , " /" )
143+ $null = $ResultBuilder.AppendLine ($copy )
144+ }
145+
146+ $null = $ResultBuilder.AppendLine (' ' )
83147 }
84-
85- $null = $ResultBuilder.AppendLine (' CMD /Wait-Service.ps1 -ServiceName W3SVC -AllowServiceRestart' )
86148}
87149
88150
0 commit comments