Skip to content

Commit f8cd437

Browse files
committed
Added in extra checks + dockerfile copy
1 parent 6a2ffcc commit f8cd437

File tree

2 files changed

+131
-113
lines changed

2 files changed

+131
-113
lines changed

Create-SitecoreModule-DockerAssetImage.ps1

Lines changed: 127 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using module ".\logo.psm1"
2525

2626
#---------------------------------[Parameters]--------------------------------------------------------
2727
param(
28-
[string] $ModulePackageName = "Gutters.for.Sitecore.Data.Exchange.Framework-Sitecore.10.1.0.for.DEF.5.0.0.zip"
28+
[string] $ModulePackageName = ""
2929
)
3030

3131
#---------------------------------[Read configuration]------------------------------------------------
@@ -36,149 +36,163 @@ $satPackageName = $jsonConfiguration.Parameters.SitecoreAzureToolkitPackageName.
3636

3737
Show-Start
3838

39-
Write-Host "================================================================================================================================="
40-
Write-Host "`n"
41-
Write-Host "START - [Sitecore Azure Toolkit download]"
42-
Write-Host "`n"
43-
44-
$satDirecory = $PSScriptRoot + "\SAT"
45-
46-
If (!(Test-Path($satDirecory))) {
47-
New-Item -ItemType Directory -Force -Path $satDirecory
48-
}
49-
50-
if (Test-Path -Path "$satDirecory\$satPackageName") {
51-
Write-Host "SKIPPING - $satDirecory folder already contains the $satPackageName file" -ForegroundColor Cyan
52-
}
53-
else {
54-
Write-Host "START - downloading the $satPackageName file from dev.sitecore.net"
55-
Invoke-WebRequest -Uri $satUrl -OutFile "$satDirecory\$satPackageName"
39+
if (!$ModulePackageName) {
40+
Write-Host "================================================================================================================================="
5641
Write-Host "`n"
57-
Write-Host "SUCCESS - Downloaded the $satPackageName file from dev.sitecore.net" -ForegroundColor Green
58-
}
59-
60-
Write-Host "`n"
61-
62-
Write-Host "=================================================================================================================================="
63-
Write-Host "`n"
64-
Write-Host "START - [Sitecore Azure Toolkit extract]"
65-
Write-Host "`n"
66-
67-
if (-not(Test-Path ".\SAT\tools\Sitecore.Cloud.Cmdlets.dll")) {
68-
Expand-Archive -Path "$satDirecory\$satPackageName" -DestinationPath "$satDirecory" -Force
69-
Write-Host "SUCCESS - Extracted $satPackageName to the $satDirecory directory" -ForegroundColor Green
42+
Write-Host "ERROR - Make sure you pass in the -ModulePackageName parameter. e.g. .\\Create-SitecoreModule-DockerAssetImage.ps1 -ModulePackageName 'YOUR PACKAGE NAME'" -ForegroundColor Red
7043
Write-Host "`n"
44+
Write-Host "================================================================================================================================="
7145
}
7246
else {
73-
Write-Host "SKIPPING - $satPackageName is already extracted to the $satDirecory directory" -ForegroundColor Cyan
47+
Write-Host "================================================================================================================================="
7448
Write-Host "`n"
75-
}
76-
77-
Write-Host "=================================================================================================================================="
78-
Write-Host "`n"
79-
Write-Host "START - [Convert Sitecore Module to .scwdp]"
80-
Write-Host "`n"
81-
82-
$packagePath = $PSScriptRoot + "\Package\$ModulePackageName"
83-
$scwdpDirectory = $PSScriptRoot + "\scwpd"
84-
85-
Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.psm1
86-
Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.dll
87-
88-
If (!(Test-Path($packagePath))) {
89-
Write-Host "ERROR - Make sure the $packagePath exists!" -ForegroundColor Red
90-
}
91-
else {
92-
If (!(Test-Path($scwdpDirectory))) {
93-
New-Item -ItemType Directory -Force -Path $scwdpDirectory
94-
}
95-
96-
Get-ChildItem -Path $scwdpDirectory -Recurse | Foreach-object { Remove-item -Recurse -path $_.FullName }
97-
98-
$scwdpPath = ConvertTo-SCModuleWebDeployPackage -Path $packagePath -Destination $scwdpDirectory -Force
99-
Write-Host "SUCCESS - Your Sitecore Module was converted to a Sitecore WebDeploy package and is located at:" -ForegroundColor Green
100-
Write-Host "`n"
101-
Write-Host "$scwdpPath" -ForegroundColor Yellow
49+
Write-Host "START - [Sitecore Azure Toolkit download]"
10250
Write-Host "`n"
10351

104-
Write-Host "=================================================================================================================================="
105-
Write-Host "`n"
106-
Write-Host "START - [Extracting Sitecore WebDeploy package]"
107-
Write-Host "`n"
52+
$satDirecory = $PSScriptRoot + "\SAT"
10853

109-
$extractSCwdpDirectory = $scwdpDirectory + "\extract"
54+
If (!(Test-Path($satDirecory))) {
55+
New-Item -ItemType Directory -Force -Path $satDirecory
56+
}
11057

111-
if (!(Test-Path($extractSCwdpDirectory))) {
112-
New-Item -ItemType Directory -Force -Path $extractSCwdpDirectory
58+
if (Test-Path -Path "$satDirecory\$satPackageName") {
59+
Write-Host "SKIPPING - $satDirecory folder already contains the $satPackageName file" -ForegroundColor Cyan
60+
}
61+
else {
62+
Write-Host "START - downloading the $satPackageName file from dev.sitecore.net"
63+
Invoke-WebRequest -Uri $satUrl -OutFile "$satDirecory\$satPackageName"
64+
Write-Host "`n"
65+
Write-Host "SUCCESS - Downloaded the $satPackageName file from dev.sitecore.net" -ForegroundColor Green
11366
}
11467

115-
Expand-Archive -Path "$scwdpPath" -DestinationPath "$extractSCwdpDirectory" -Force
68+
Write-Host "`n"
11669

11770
Write-Host "=================================================================================================================================="
11871
Write-Host "`n"
119-
Write-Host "START - [Creating Sitecore module asset image structure]"
72+
Write-Host "START - [Sitecore Azure Toolkit extract]"
12073
Write-Host "`n"
12174

122-
$moduleDirectory = $PSScriptRoot + "\Module"
123-
$cmContentDirectory = $moduleDirectory + "\cm\content"
124-
$dbDirectory = $moduleDirectory + "\db"
125-
$solrDirectory = $moduleDirectory + "\solr"
126-
$toolsDirectory = $moduleDirectory + "\tools"
127-
128-
If (!(Test-Path($moduleDirectory))) {
129-
New-Item -ItemType Directory -Force -Path $moduleDirectory
130-
}
131-
132-
Remove-Item -Path $moduleDirectory -Recurse
133-
134-
If (!(Test-Path($cmContentDirectory))) {
135-
New-Item -ItemType Directory -Force -Path $cmContentDirectory
136-
}
137-
138-
If (!(Test-Path($dbDirectory))) {
139-
New-Item -ItemType Directory -Force -Path $dbDirectory
75+
if (-not(Test-Path "$satDirecory\tools\Sitecore.Cloud.Cmdlets.dll")) {
76+
Expand-Archive -Path "$satDirecory\$satPackageName" -DestinationPath "$satDirecory" -Force
77+
Write-Host "SUCCESS - Extracted $satPackageName to the $satDirecory directory" -ForegroundColor Green
78+
Write-Host "`n"
14079
}
141-
142-
If (!(Test-Path($solrDirectory))) {
143-
New-Item -ItemType Directory -Force -Path $solrDirectory
144-
}
145-
146-
If (!(Test-Path($toolsDirectory))) {
147-
New-Item -ItemType Directory -Force -Path $toolsDirectory
80+
else {
81+
Write-Host "SKIPPING - $satPackageName is already extracted to the $satDirecory directory" -ForegroundColor Cyan
82+
Write-Host "`n"
14883
}
14984

15085
Write-Host "=================================================================================================================================="
15186
Write-Host "`n"
152-
Write-Host "START - [Copying over .scwdp contents to Sitecore module asset image structure]"
87+
Write-Host "START - [Convert Sitecore Module to .scwdp]"
15388
Write-Host "`n"
15489

155-
# Copy content
156-
Copy-Item -Path "$extractSCwdpDirectory\Content\Website\*" -Destination $cmContentDirectory -PassThru -Recurse
90+
$packagePath = $PSScriptRoot + "\Package\$ModulePackageName"
91+
$scwdpDirectory = $PSScriptRoot + "\scwpd"
15792

158-
# Copy dacpacs + rename
159-
if (Test-Path("$extractSCwdpDirectory\core.dacpac")) {
160-
Copy-Item -Path "$extractSCwdpDirectory\core.dacpac" -Destination $dbDirectory -PassThru
161-
Rename-Item -Path "$dbDirectory\core.dacpac" -NewName "Sitecore.Core.dacpac"
162-
}
93+
Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.psm1
94+
Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.dll
16395

164-
if (Test-Path("$extractSCwdpDirectory\master.dacpac")) {
165-
Copy-Item -Path "$extractSCwdpDirectory\master.dacpac" -Destination $dbDirectory -PassThru
166-
Rename-Item -Path "$dbDirectory\master.dacpac" -NewName "Sitecore.Master.dacpac"
96+
If (!(Test-Path($packagePath))) {
97+
Write-Host "ERROR - Make sure the $packagePath exists!" -ForegroundColor Red
16798
}
99+
else {
100+
If (!(Test-Path($scwdpDirectory))) {
101+
New-Item -ItemType Directory -Force -Path $scwdpDirectory
102+
}
103+
104+
Get-ChildItem -Path $scwdpDirectory -Recurse | Foreach-object { Remove-item -Recurse -path $_.FullName }
105+
106+
$scwdpPath = ConvertTo-SCModuleWebDeployPackage -Path $packagePath -Destination $scwdpDirectory -Force
107+
Write-Host "SUCCESS - Your Sitecore Module was converted to a Sitecore WebDeploy package and is located at:" -ForegroundColor Green
108+
Write-Host "`n"
109+
Write-Host "$scwdpPath" -ForegroundColor Yellow
110+
Write-Host "`n"
111+
112+
Write-Host "=================================================================================================================================="
113+
Write-Host "`n"
114+
Write-Host "START - [Extracting Sitecore WebDeploy package]"
115+
Write-Host "`n"
116+
117+
$extractSCwdpDirectory = $scwdpDirectory + "\extract"
118+
119+
if (!(Test-Path($extractSCwdpDirectory))) {
120+
New-Item -ItemType Directory -Force -Path $extractSCwdpDirectory
121+
}
122+
123+
Expand-Archive -Path "$scwdpPath" -DestinationPath "$extractSCwdpDirectory" -Force
124+
125+
Write-Host "=================================================================================================================================="
126+
Write-Host "`n"
127+
Write-Host "START - [Creating Sitecore module asset image structure]"
128+
Write-Host "`n"
129+
130+
$moduleDirectory = $PSScriptRoot + "\Module"
131+
$cmContentDirectory = $moduleDirectory + "\cm\content"
132+
$dbDirectory = $moduleDirectory + "\db"
133+
$solrDirectory = $moduleDirectory + "\solr"
134+
$toolsDirectory = $moduleDirectory + "\tools"
135+
136+
If (!(Test-Path($moduleDirectory))) {
137+
New-Item -ItemType Directory -Force -Path $moduleDirectory
138+
}
139+
140+
Remove-Item -Path $moduleDirectory -Recurse
141+
142+
If (!(Test-Path($cmContentDirectory))) {
143+
New-Item -ItemType Directory -Force -Path $cmContentDirectory
144+
}
145+
146+
If (!(Test-Path($dbDirectory))) {
147+
New-Item -ItemType Directory -Force -Path $dbDirectory
148+
}
149+
150+
If (!(Test-Path($solrDirectory))) {
151+
New-Item -ItemType Directory -Force -Path $solrDirectory
152+
}
153+
154+
If (!(Test-Path($toolsDirectory))) {
155+
New-Item -ItemType Directory -Force -Path $toolsDirectory
156+
}
157+
158+
Write-Host "=================================================================================================================================="
159+
Write-Host "`n"
160+
Write-Host "START - [Copying over .scwdp contents to Sitecore module asset image structure]"
161+
Write-Host "`n"
162+
163+
# Copy content
164+
Copy-Item -Path "$extractSCwdpDirectory\Content\Website\*" -Destination $cmContentDirectory -PassThru -Recurse
165+
166+
# Copy dacpacs + rename
167+
if (Test-Path("$extractSCwdpDirectory\core.dacpac")) {
168+
Copy-Item -Path "$extractSCwdpDirectory\core.dacpac" -Destination $dbDirectory -PassThru
169+
Rename-Item -Path "$dbDirectory\core.dacpac" -NewName "Sitecore.Core.dacpac"
170+
}
171+
172+
if (Test-Path("$extractSCwdpDirectory\master.dacpac")) {
173+
Copy-Item -Path "$extractSCwdpDirectory\master.dacpac" -Destination $dbDirectory -PassThru
174+
Rename-Item -Path "$dbDirectory\master.dacpac" -NewName "Sitecore.Master.dacpac"
175+
}
168176

169-
Write-Host "=================================================================================================================================="
170-
Write-Host "`n"
171-
Write-Host "SUCCESS - Succesfully created the Docker Asset Image structure in directory $moduleDirectory" -ForegroundColor Green
172-
Write-Host "`n"
177+
Write-Host "=================================================================================================================================="
178+
Write-Host "`n"
179+
Write-Host "START - [Copying over dockerfile]"
180+
Write-Host "`n"
173181

174-
tree $moduleDirectory /f /a
182+
Copy-Item -Path "$PSScriptRoot\dockerfile" -Destination $moduleDirectory -PassThru
175183

176-
Write-Host "`n"
177-
Write-Host "=================================================================================================================================="
178-
Write-Host "`n"
179-
}
184+
Write-Host "=================================================================================================================================="
185+
Write-Host "`n"
186+
Write-Host "SUCCESS - Succesfully created the Docker Asset Image structure in directory $moduleDirectory" -ForegroundColor Green
187+
Write-Host "`n"
180188

189+
tree $moduleDirectory /f /a
181190

191+
Write-Host "`n"
192+
Write-Host "=================================================================================================================================="
193+
Write-Host "`n"
194+
}
195+
}
182196

183197
Show-Stop
184198

dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM mcr.microsoft.com/windows/nanoserver:1809 AS build
2+
3+
# Copy assets into the image, keeping the folder structure
4+
COPY \ .\

0 commit comments

Comments
 (0)