Skip to content

Commit a92782b

Browse files
authored
Merge pull request #6 from konabos/main
Create Docker image from the files after transformation
2 parents 3014a4d + dce4bb5 commit a92782b

File tree

3 files changed

+190
-145
lines changed

3 files changed

+190
-145
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.dockerignore
2+
dockerfile

Create-SitecoreModule-DockerAssetImage.ps1

+176-140
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ using module ".\logo.psm1"
2525

2626
#---------------------------------[Parameters]--------------------------------------------------------
2727
param(
28-
[string] $ModulePackageName = ""
28+
[string] $ModulePackageName = "",
29+
[string] $Tag = "",
30+
[switch] $GenerateCdContentDirectory
2931
)
3032

3133
#---------------------------------[Read configuration]------------------------------------------------
@@ -42,164 +44,198 @@ if (!$ModulePackageName) {
4244
Write-Host "ERROR - Make sure you pass in the -ModulePackageName parameter. e.g. .\\Create-SitecoreModule-DockerAssetImage.ps1 -ModulePackageName 'YOUR PACKAGE NAME'" -ForegroundColor Red
4345
Write-Host "`n"
4446
Write-Host "================================================================================================================================="
47+
Break
4548
}
46-
else {
47-
Write-Host "================================================================================================================================="
48-
Write-Host "`n"
49-
Write-Host "START - [Sitecore Azure Toolkit download]"
50-
Write-Host "`n"
5149

52-
$satDirecory = $PSScriptRoot + "\SAT"
50+
Write-Host "================================================================================================================================="
51+
Write-Host "`n"
52+
Write-Host "START - [Sitecore Azure Toolkit download]"
53+
Write-Host "`n"
5354

54-
If (!(Test-Path($satDirecory))) {
55-
New-Item -ItemType Directory -Force -Path $satDirecory
56-
}
55+
$satDirecory = $PSScriptRoot + "\SAT"
5756

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+
}
6760

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"
6867
Write-Host "`n"
68+
Write-Host "SUCCESS - Downloaded the $satPackageName file from dev.sitecore.net" -ForegroundColor Green
69+
}
6970

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
7181
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
7385
Write-Host "`n"
86+
}
7487

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
83216
}
84217

85-
Write-Host "=================================================================================================================================="
218+
Write-Host "========================================================================================================================"
86219
Write-Host "`n"
87-
Write-Host "START - [Convert Sitecore Module to .scwdp]"
220+
Write-Host "START - [Building Docker Image] -" $Tag.ToLower()
88221
Write-Host "`n"
89222

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() .
101225

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"
200231
}
201232

233+
Write-Host "`n"
234+
Write-Host "=================================================================================================================================="
235+
Write-Host "`n"
236+
202237
Show-Stop
238+
Set-Location -Path $PSScriptRoot
203239

204240
# Cleaning up the modules
205241
Get-Module | Remove-Module

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ This repository contains a script to handle the auto creation of a Docker Asset
66
- Add the Sitecore module package to Package folder under root
77
- Then invoke the script as shown in example below to convert it into scwdp (used for Azure PaaS) as well as extract the scwdp into a Module folder used for generating the docker image
88
```powershell
9-
.\Create-SitecoreModule-DockerAssetImage.ps1 -ModulePackageName "Brightcove.Media.Framework-10.0.zip"
9+
.\Create-SitecoreModule-DockerAssetImage.ps1 -ModulePackageName "Sitecore.PowerShell.Extensions-6.3.zip" -Tag "sitecorepowershell/sitecore-powershell-extensions:6.3-1809" -GenerateCdContentDirectory
1010
```
11+
12+
Or use the shorthand aliases:
13+
```powershell
14+
.\Create-SitecoreModule-DockerAssetImage.ps1 -M "Sitecore.PowerShell.Extensions-6.3.zip" -T "sitecorepowershell/sitecore-powershell-extensions:6.3-1809" -G
15+
```
16+
1117
- The folder name is generated based on the ModulePackageName provided while invoking the script and appends the current datetime stamp in `ModulePackageName_yyyyMMdd_HHmmss` format
1218
- Run the docker file under Module folder to generate the image. The script only extracts it for CM role. For other roles, you have to manually create role specific docker files
1319
- Once the image is generated, push it to your container registry to share it with other devs in your team or devops for AKS deployment
@@ -16,7 +22,8 @@ This repository contains a script to handle the auto creation of a Docker Asset
1622

1723
# Contributors
1824

19-
Robbert Hock - Twitter: @kayeeNL, GitHub: https://github.com/KayeeNL
20-
Anton Tishchenko - Twitter: @ativn, GitHub: https://github.com/Antonytm
21-
Christopher Huemmer - Twitter: @chrishmmr, GitHub: https://github.com/chris-hmmr
22-
Venkata Phani Abburi - Twitter: @phani_abburi, GitHub: https://github.com/phaniav
25+
- Robbert Hock - Twitter: @kayeeNL, GitHub: https://github.com/KayeeNL
26+
- Anton Tishchenko - Twitter: @ativn, GitHub: https://github.com/Antonytm
27+
- Christopher Huemmer - Twitter: @chrishmmr, GitHub: https://github.com/chris-hmmr
28+
- Venkata Phani Abburi - Twitter: @phani_abburi, GitHub: https://github.com/phaniav
29+
- Kamruz Jaman - Twitter: @jammykam, GitHub: https://github.com/konabos

0 commit comments

Comments
 (0)