@@ -25,7 +25,9 @@ using module ".\logo.psm1"
25
25
26
26
# ---------------------------------[Parameters]--------------------------------------------------------
27
27
param (
28
- [string ] $ModulePackageName = " "
28
+ [string ] $ModulePackageName = " " ,
29
+ [string ] $Tag = " " ,
30
+ [switch ] $GenerateCdContentDirectory
29
31
)
30
32
31
33
# ---------------------------------[Read configuration]------------------------------------------------
@@ -42,164 +44,198 @@ if (!$ModulePackageName) {
42
44
Write-Host " ERROR - Make sure you pass in the -ModulePackageName parameter. e.g. .\\Create-SitecoreModule-DockerAssetImage.ps1 -ModulePackageName 'YOUR PACKAGE NAME'" - ForegroundColor Red
43
45
Write-Host " `n "
44
46
Write-Host " ================================================================================================================================="
47
+ Break
45
48
}
46
- else {
47
- Write-Host " ================================================================================================================================="
48
- Write-Host " `n "
49
- Write-Host " START - [Sitecore Azure Toolkit download]"
50
- Write-Host " `n "
51
49
52
- $satDirecory = $PSScriptRoot + " \SAT"
50
+ Write-Host " ================================================================================================================================="
51
+ Write-Host " `n "
52
+ Write-Host " START - [Sitecore Azure Toolkit download]"
53
+ Write-Host " `n "
53
54
54
- If (! (Test-Path ($satDirecory ))) {
55
- New-Item - ItemType Directory - Force - Path $satDirecory
56
- }
55
+ $satDirecory = $PSScriptRoot + " \SAT"
57
56
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
66
- }
57
+ If (! (Test-Path ($satDirecory ))) {
58
+ New-Item - ItemType Directory - Force - Path $satDirecory
59
+ }
67
60
61
+ if (Test-Path - Path " $satDirecory \$satPackageName " ) {
62
+ Write-Host " SKIPPING - $satDirecory folder already contains the $satPackageName file" - ForegroundColor Cyan
63
+ }
64
+ else {
65
+ Write-Host " START - downloading the $satPackageName file from dev.sitecore.net"
66
+ Invoke-WebRequest - Uri $satUrl - OutFile " $satDirecory \$satPackageName "
68
67
Write-Host " `n "
68
+ Write-Host " SUCCESS - Downloaded the $satPackageName file from dev.sitecore.net" - ForegroundColor Green
69
+ }
69
70
70
- Write-Host " =================================================================================================================================="
71
+ Write-Host " `n "
72
+
73
+ Write-Host " =================================================================================================================================="
74
+ Write-Host " `n "
75
+ Write-Host " START - [Sitecore Azure Toolkit extract]"
76
+ Write-Host " `n "
77
+
78
+ if (-not (Test-Path " $satDirecory \tools\Sitecore.Cloud.Cmdlets.dll" )) {
79
+ Expand-Archive - Path " $satDirecory \$satPackageName " - DestinationPath " $satDirecory " - Force
80
+ Write-Host " SUCCESS - Extracted $satPackageName to the $satDirecory directory" - ForegroundColor Green
71
81
Write-Host " `n "
72
- Write-Host " START - [Sitecore Azure Toolkit extract]"
82
+ }
83
+ else {
84
+ Write-Host " SKIPPING - $satPackageName is already extracted to the $satDirecory directory" - ForegroundColor Cyan
73
85
Write-Host " `n "
86
+ }
74
87
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 "
79
- }
80
- else {
81
- Write-Host " SKIPPING - $satPackageName is already extracted to the $satDirecory directory" - ForegroundColor Cyan
82
- Write-Host " `n "
88
+ Write-Host " =================================================================================================================================="
89
+ Write-Host " `n "
90
+ Write-Host " START - [Convert Sitecore Module to .scwdp]"
91
+ Write-Host " `n "
92
+
93
+ $dateTime = (Get-Date ).tostring(" yyyyMMdd_HHmmss" )
94
+ $packagePath = $PSScriptRoot + " \Package\$ModulePackageName "
95
+ $modulePackageItem = Get-Item $packagePath
96
+ $modulePackageNameSinExtension = $modulePackageItem.BaseName
97
+ $scwdpDirectory = $PSScriptRoot + " \scwdp"
98
+ $scwdpModuleFolder = $modulePackageNameSinExtension + " _$dateTime "
99
+ $scwdpDestination = " $scwdpDirectory \$scwdpModuleFolder "
100
+
101
+
102
+ Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.psm1
103
+ Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.dll
104
+
105
+ If (! (Test-Path ($packagePath ))) {
106
+ Write-Host " ERROR - Make sure the $packagePath exists!" - ForegroundColor Red
107
+ Break
108
+ }
109
+
110
+ If (! (Test-Path ($scwdpDirectory ))) {
111
+ New-Item - ItemType Directory - Force - Path $scwdpDirectory
112
+ }
113
+
114
+ $scwdpPath = ConvertTo-SCModuleWebDeployPackage - Path $packagePath - Destination $scwdpDestination - Force
115
+ Write-Host " SUCCESS - Your Sitecore Module was converted to a Sitecore WebDeploy package and is located at:" - ForegroundColor Green
116
+ Write-Host " `n "
117
+ Write-Host " $scwdpDestination " - ForegroundColor Yellow
118
+ Write-Host " `n "
119
+
120
+ Write-Host " =================================================================================================================================="
121
+ Write-Host " `n "
122
+ Write-Host " START - [Extracting Sitecore WebDeploy package]"
123
+ Write-Host " `n "
124
+
125
+ $extractSCwdpDirectory = $scwdpDestination + " \extract_scwdp"
126
+
127
+ if (! (Test-Path ($extractSCwdpDirectory ))) {
128
+ New-Item - ItemType Directory - Force - Path $extractSCwdpDirectory
129
+ }
130
+
131
+ $extractSCwdpDirectory
132
+
133
+ Expand-Archive - Path " $scwdpPath " - DestinationPath " $extractSCwdpDirectory " - Force
134
+
135
+ Write-Host " =================================================================================================================================="
136
+ Write-Host " `n "
137
+ Write-Host " START - [Creating Sitecore module asset image structure]"
138
+ Write-Host " `n "
139
+
140
+ $moduleDirectory = " $scwdpDestination \Module"
141
+
142
+ $cmContentDirectory = $moduleDirectory + " \cm\content"
143
+ $cdContentDirectory = $moduleDirectory + " \cd\content"
144
+ $dbDirectory = $moduleDirectory + " \db"
145
+ $solrDirectory = $moduleDirectory + " \solr"
146
+ $toolsDirectory = $moduleDirectory + " \tools"
147
+
148
+ If (! (Test-Path ($moduleDirectory ))) {
149
+ New-Item - ItemType Directory - Force - Path $moduleDirectory
150
+ }
151
+
152
+ If (! (Test-Path ($cmContentDirectory ))) {
153
+ New-Item - ItemType Directory - Force - Path $cmContentDirectory
154
+ }
155
+
156
+ If ($GenerateCdContentDirectory -and ! (Test-Path ($cdContentDirectory ))) {
157
+ New-Item - ItemType Directory - Force - Path $cdContentDirectory
158
+ }
159
+
160
+ If (! (Test-Path ($dbDirectory ))) {
161
+ New-Item - ItemType Directory - Force - Path $dbDirectory
162
+ }
163
+
164
+ If (! (Test-Path ($solrDirectory ))) {
165
+ New-Item - ItemType Directory - Force - Path $solrDirectory
166
+ }
167
+
168
+ If (! (Test-Path ($toolsDirectory ))) {
169
+ New-Item - ItemType Directory - Force - Path $toolsDirectory
170
+ }
171
+
172
+ Write-Host " =================================================================================================================================="
173
+ Write-Host " `n "
174
+ Write-Host " START - [Copying over .scwdp contents to Sitecore module asset image structure]"
175
+ Write-Host " `n "
176
+
177
+ # Copy content
178
+ Copy-Item - Path " $extractSCwdpDirectory \Content\Website\*" - Destination $cmContentDirectory - PassThru - Recurse
179
+
180
+ if ($GenerateCdContentDirectory ) {
181
+ # Copy content to create CD layer folders
182
+ Copy-Item - Path $cmContentDirectory \* - Destination $cdContentDirectory - PassThru - Recurse
183
+ }
184
+
185
+ # Copy dacpacs + rename
186
+ if (Test-Path (" $extractSCwdpDirectory \core.dacpac" )) {
187
+ Copy-Item - Path " $extractSCwdpDirectory \core.dacpac" - Destination $dbDirectory - PassThru
188
+ Rename-Item - Path " $dbDirectory \core.dacpac" - NewName " Sitecore.Core.dacpac"
189
+ }
190
+
191
+ if (Test-Path (" $extractSCwdpDirectory \master.dacpac" )) {
192
+ Copy-Item - Path " $extractSCwdpDirectory \master.dacpac" - Destination $dbDirectory - PassThru
193
+ Rename-Item - Path " $dbDirectory \master.dacpac" - NewName " Sitecore.Master.dacpac"
194
+ }
195
+
196
+ Write-Host " =================================================================================================================================="
197
+ Write-Host " `n "
198
+ Write-Host " START - [Copying over dockerfile]"
199
+ Write-Host " `n "
200
+
201
+ Copy-Item - Path " $PSScriptRoot \dockerfile" - Destination $moduleDirectory - PassThru
202
+ Copy-Item - Path " $PSScriptRoot \.dockerignore" - Destination $moduleDirectory - PassThru
203
+
204
+ Write-Host " =================================================================================================================================="
205
+ Write-Host " `n "
206
+ Write-Host " SUCCESS - Succesfully created the Docker Asset Image structure in directory $moduleDirectory " - ForegroundColor Green
207
+ Write-Host " `n "
208
+
209
+ tree $moduleDirectory / f / a
210
+
211
+ if ($Tag ) {
212
+
213
+ if (-Not (docker ps)) {
214
+ Write-Host " FAILED - Could not create the Docker image. Are you sure the Docker daemon is running?" - ForegroundColor Red
215
+ Break
83
216
}
84
217
85
- Write-Host " ================================================================================================================================== "
218
+ Write-Host " ========================================================================================================================"
86
219
Write-Host " `n "
87
- Write-Host " START - [Convert Sitecore Module to .scwdp] "
220
+ Write-Host " START - [Building Docker Image] - " $Tag .ToLower ()
88
221
Write-Host " `n "
89
222
90
- $dateTime = (Get-Date ).tostring(" yyyyMMdd_HHmmss" )
91
- $packagePath = $PSScriptRoot + " \Package\$ModulePackageName "
92
- $modulePackageItem = Get-Item $packagePath
93
- $modulePackageNameSinExtension = $modulePackageItem.BaseName
94
- $scwdpDirectory = $PSScriptRoot + " \scwdp"
95
- $scwdpModuleFolder = $modulePackageNameSinExtension + " _$dateTime "
96
- $scwdpDestination = " $scwdpDirectory \$scwdpModuleFolder "
97
-
98
-
99
- Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.psm1
100
- Import-Module .\SAT\tools\Sitecore.Cloud.Cmdlets.dll
223
+ Set-Location - Path $moduleDirectory
224
+ docker build -- tag $Tag.ToLower () .
101
225
102
- If (! (Test-Path ($packagePath ))) {
103
- Write-Host " ERROR - Make sure the $packagePath exists!" - ForegroundColor Red
104
- }
105
- else {
106
- If (! (Test-Path ($scwdpDirectory ))) {
107
- New-Item - ItemType Directory - Force - Path $scwdpDirectory
108
- }
109
-
110
- $scwdpPath = ConvertTo-SCModuleWebDeployPackage - Path $packagePath - Destination $scwdpDestination - Force
111
- Write-Host " SUCCESS - Your Sitecore Module was converted to a Sitecore WebDeploy package and is located at:" - ForegroundColor Green
112
- Write-Host " `n "
113
- Write-Host " $scwdpDestination " - ForegroundColor Yellow
114
- Write-Host " `n "
115
-
116
- Write-Host " =================================================================================================================================="
117
- Write-Host " `n "
118
- Write-Host " START - [Extracting Sitecore WebDeploy package]"
119
- Write-Host " `n "
120
-
121
- $extractSCwdpDirectory = $scwdpDestination + " \extract_scwdp"
122
-
123
- if (! (Test-Path ($extractSCwdpDirectory ))) {
124
- New-Item - ItemType Directory - Force - Path $extractSCwdpDirectory
125
- }
126
-
127
- $extractSCwdpDirectory
128
-
129
- Expand-Archive - Path " $scwdpPath " - DestinationPath " $extractSCwdpDirectory " - Force
130
-
131
- Write-Host " =================================================================================================================================="
132
- Write-Host " `n "
133
- Write-Host " START - [Creating Sitecore module asset image structure]"
134
- Write-Host " `n "
135
-
136
- $moduleDirectory = " $scwdpDestination \Module"
137
-
138
- $cmContentDirectory = $moduleDirectory + " \cm\content"
139
- $dbDirectory = $moduleDirectory + " \db"
140
- $solrDirectory = $moduleDirectory + " \solr"
141
- $toolsDirectory = $moduleDirectory + " \tools"
142
-
143
- If (! (Test-Path ($moduleDirectory ))) {
144
- New-Item - ItemType Directory - Force - Path $moduleDirectory
145
- }
146
-
147
- If (! (Test-Path ($cmContentDirectory ))) {
148
- New-Item - ItemType Directory - Force - Path $cmContentDirectory
149
- }
150
-
151
- If (! (Test-Path ($dbDirectory ))) {
152
- New-Item - ItemType Directory - Force - Path $dbDirectory
153
- }
154
-
155
- If (! (Test-Path ($solrDirectory ))) {
156
- New-Item - ItemType Directory - Force - Path $solrDirectory
157
- }
158
-
159
- If (! (Test-Path ($toolsDirectory ))) {
160
- New-Item - ItemType Directory - Force - Path $toolsDirectory
161
- }
162
-
163
- Write-Host " =================================================================================================================================="
164
- Write-Host " `n "
165
- Write-Host " START - [Copying over .scwdp contents to Sitecore module asset image structure]"
166
- Write-Host " `n "
167
-
168
- # Copy content
169
- Copy-Item - Path " $extractSCwdpDirectory \Content\Website\*" - Destination $cmContentDirectory - PassThru - Recurse
170
-
171
- # Copy dacpacs + rename
172
- if (Test-Path (" $extractSCwdpDirectory \core.dacpac" )) {
173
- Copy-Item - Path " $extractSCwdpDirectory \core.dacpac" - Destination $dbDirectory - PassThru
174
- Rename-Item - Path " $dbDirectory \core.dacpac" - NewName " Sitecore.Core.dacpac"
175
- }
176
-
177
- if (Test-Path (" $extractSCwdpDirectory \master.dacpac" )) {
178
- Copy-Item - Path " $extractSCwdpDirectory \master.dacpac" - Destination $dbDirectory - PassThru
179
- Rename-Item - Path " $dbDirectory \master.dacpac" - NewName " Sitecore.Master.dacpac"
180
- }
181
-
182
- Write-Host " =================================================================================================================================="
183
- Write-Host " `n "
184
- Write-Host " START - [Copying over dockerfile]"
185
- Write-Host " `n "
186
-
187
- Copy-Item - Path " $PSScriptRoot \dockerfile" - Destination $moduleDirectory - PassThru
188
-
189
- Write-Host " =================================================================================================================================="
190
- Write-Host " `n "
191
- Write-Host " SUCCESS - Succesfully created the Docker Asset Image structure in directory $moduleDirectory " - ForegroundColor Green
192
- Write-Host " `n "
193
-
194
- tree $moduleDirectory / f / a
195
-
196
- Write-Host " `n "
197
- Write-Host " =================================================================================================================================="
198
- Write-Host " `n "
199
- }
226
+ Write-Host " =================================================================================================================================="
227
+ Write-Host " `n "
228
+ Write-Host " SUCCESS - Created local image" $Tag.ToLower () - ForegroundColor Green
229
+ Write-Host " Don't forget to push the image to the Container Registry or Docker Hub." - ForegroundColor Yellow
230
+ Write-Host " `n "
200
231
}
201
232
233
+ Write-Host " `n "
234
+ Write-Host " =================================================================================================================================="
235
+ Write-Host " `n "
236
+
202
237
Show-Stop
238
+ Set-Location - Path $PSScriptRoot
203
239
204
240
# Cleaning up the modules
205
241
Get-Module | Remove-Module
0 commit comments