Skip to content

Commit

Permalink
Merge pull request #23 from Ben-m-s/develop
Browse files Browse the repository at this point in the history
New build process and folder renaming among other changes
  • Loading branch information
jeanfrancoislarente committed Oct 19, 2018
2 parents 07aa80c + a0d6661 commit da0b08f
Show file tree
Hide file tree
Showing 156 changed files with 4,329 additions and 722 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
sitecore/*/*.zip
license.xml
*-Local.ps1
Files/
Files/
*.zip
Assets/
ExternalAssets/
.vs/
48 changes: 48 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
**CREDITS**

Below is a list of people which contributions in the community have be helpful for this repository to progress.

**Per Bering**: One of the first promoters of Docker for Sitecore. He is a major contributor to this repository, and actively helps peers with Docker related matters on different channels.
https://github.com/sitecore/docker-images
https://github.com/Sitecore/docker-demo
https://github.com/pbering/SitecoreContainers
https://github.com/sitecoreops/sitecore-images
https://github.com/pbering/sitecore-nine-docker
https://github.com/pbering/SockerVS2017
https://github.com/pbering/solrwin

**Joost Meijles (Aviva Solutions)**: His contributions in GitHub have been a source of inspiration. He is also active in community discussions about using Docker with Sitecore.
https://github.com/avivasolutionsnl/sitecore-commerce-docker
https://github.com/joostmeijles/sitecore-commerce-docker
https://github.com/avivasolutionsnl/sitecore-docker
https://github.com/sitecoreops/sitecore-images


**Benjamin Moles Segovia (ClearPeople)**: He is a major contributor on the two official Sitecore's Docker related repositories on GitHub.
https://github.com/Ben-m-s/Bendev.Assets.Management
https://github.com/sitecore/docker-images
https://github.com/Sitecore/docker-demo

**Jonne Kats**: His contributions in GitHub have been a source of inspiration.
https://github.com/avivasolutionsnl/sitecore-commerce-docker
https://github.com/avivasolutionsnl/sitecore-docker

**Richard Brisley**: His repository was very useful to create the first XPSingle version.
https://bitbucket.org/sagittarius_rbrisley/sitecore-commerce-docker-xp0.git

**Mikkel Valentin Sørensen**: He contributed to the repository that was used as seed of the current Sitecore/docker-images repository.
https://github.com/sitecoreops/sitecore-images

**Jeremy Davis**: His PowerShell script to install SOLR was used in the Sitecore Docker images.
https://gist.github.com/jermdavis/8d8a79f680505f1074153f02f70b9105

**Kam Figy**: His PowerShell script to setup SSL was used in the Sitecore Docker images.
https://gist.github.com/kamsar/c3c8322c1ec40eac64c7dd546e5124de#file-anexample-ps1

**Warren Frame**: Code used to prioritise docker images in the build process, based on their dependencies between each other
https://github.com/RamblingCookieMonster/PSDepend/

**Gabe Streza**: His PowerShell script to validate Sitecore pre-requisites was used during some developments.
http://www.sitecoregabe.com/2018/04/sitecore-9-machine-prerequisites-check.html


74 changes: 60 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Repository of Sitecore Docker base images


Build your own Docker images out of every released Sitecore version since 8.2 rev. 170407 (Update 3) - the first version that officially supported Windows Server 2016. You can use this repository *directly* from you own build server and have it build and push images to your own private Docker repository.
Build your own Docker images out of every released Sitecore version since 8.2 rev. 170407 (Update 3) - the first version that officially supported Windows Server 2016. You can use this repository *directly* from your own build server and build and push images to your own private Docker repository.

There are some more background and details in this post: [https://invokecommand.net/posts/automatically-build-and-update-base-images](https://invokecommand.net/posts/automatically-build-and-update-base-images).

Expand All @@ -12,13 +12,21 @@ This repository was created by combining efforts / assets from repos such as [si

## Updates
- [Changed] *Breaking Change* - Replace -SkipPush switch with -PushMode parameter controlling when images get pushed to repository with values of 'Always', 'IfChanged', 'Never'
- [Added] -RemoveInstallationSourceFiles optional switch to delete the sitecore package zip files from the local folder (Does not remove from InstallationSourcePath)
- [Added] -RemoveInstallationSourceFiles optional switch to delete the Sitecore package zip files from the local folder (Does not remove from InstallationSourcePath)
- [Fixed] Added UrlRewrite outbound rule to handle Sitecore redirect after login when container is running on another port than 80 (possible in Windows 10 Insider builds for the upcoming 1803 release in April).
- [Fixed] Solr build errors regarding downloads from github (TLS 1.2 now used).
- [Fixed] Solr build errors regarding downloads from GitHub (TLS 1.2 now used).
- [Added] Specialized Solr image with all Sitecore cores embedded **and** volume support, for Sitecore 9.0.1 (which defaults to use Solr).
- [Added] Specialized SQL Server images with all Sitecore databases embedded **and** volume support, for Sitecore 9.
- [Changed] all Sitecore 9 images now default has connection strings matching the new specialized SQL Server images.
- [Added] XM1 CM and CD role images for Sitecore 9.
### August 2018
- [Changed] *Breaking Change* Replaced Build.ps1 by new module "Sitecore.DockerImages.Management"
- [New] *Breaking Change* Dependency on external module "Bendev.Assets.Management"
- [Changed] *Breaking Change* New folder naming
- [New] XP Single base image
- [New] XP Single image
- [Changed] Containers' layers optimisation
- [Changed] Performance optimisations

## Prerequisites

Expand All @@ -27,29 +35,67 @@ This repository was created by combining efforts / assets from repos such as [si
- Windows 10 or Windows Server 2016 that is up to date and at least the 1709 build.
- Hyper-V installed.
- Latest stable Docker engine and cli.
- The following PowerShell modules installed (to be installed in the same order as shown below):
- "Bendev.Assets.Management": Available on the PowerShell Gallery: https://www.powershellgallery.com/packages/Bendev.Assets.Management/1.0.0.1
- "Sitecore.DockerImages.Management": Available in this repository under "/modules/Sitecore.DockerImages.Management/"

## How to use

Configure your build server to:
### Get ready

1. Trigger a build on changes to this git repository - to get new versions.
1. Trigger once a week - to get base images updated when Microsoft releases patched images.
The build process is performed by the module "Sitecore.DockerImages.Management". This module replaces the old PowerShell script named "Build.ps1".

Before using the "Sitecore.DockerImages.Management" module, it needs to be imported with one of the following instructions:

````PowerShell
# Loading the module from standard PowerShell's modules folder
Import-Module Sitecore.DockerImages.Management -Force -Verbose
# Loading the module directly from the repository's code
Import-Module –Name 'C:\docker\Sitecore\docker-images\modules\Sitecore.DockerImages.Management' -Force -Verbose
````


### Build process

./Build.ps1 should be called like this:
The build process should be triggered as follows:

````PowerShell
# Login
"YOUR DOCKER REPOSITORY PASSWORD" | docker login --username "YOUR DOCKER REPOSITORY USERNAME" --password-stdin
# Build and push
. (Join-Path $PSScriptRoot "Build.ps1") `
-VersionsFilter "*" ` # optional, set to for example "9.0*" to only build 9.0 images
-InstallSourcePath "PATH TO WHERE YOU KEEP ALL SITECORE ZIP FILES AND LICENSE.XML" `
-Organization "YOUR ORG NAME" ` # On Docker Hub it's your username unless you create an organization
-Repository "sitecore" `
-PushMode ` # Optional, Default to 'Never'. Possible values 'Always', 'IfChanged', 'Never'
-RemoveInstallationSourceFiles # Optional switch to delete the sitecore package zip files from the local folder (Does not remove from InstallationSourcePath)
Invoke-SitecoreDockerImageBuild `
-BuildRootPath "c:\\docker\\Sitecore\\docker-images\\sitecore" `
-VersionsFilter ".*\\9\.0\.2 rev\. 180604\\.*sitecore-xpsingle.*\\windowsservercore-ltsc2016$" `
-AssetsSourcePath "c:\\Software\\Sitecore\\Repository\\" `
-AssetsTransformPath "c:\tmp" `
-Registry "YourPrivateRepo.azurecr.io" `
-Isolation 'None' `
-PushMode 'Never'
````

Where:
- **BuildRootPath**: Mandatory. Path to the root folder where all images are defined.
- **VersionsFilter**: Optional. Regular expression used to filter the images to be built based on their full path.
- **AssetsSourcePath**: Mandatory. Path to the folder where the required installation files can be found. The Sitecore license file should also be in this folder
- **AssetsTransformPath**: Optional. Path to the folder where the source assets will be pre-processed before being handled to the Docker build context. If missing the folder indicated with parameter "AssetsSourcePath" will be used instead.
- **Registry**: Mandatory. Name of the private docker registry where the new docker images will belong to
- **Isolation**: Optional. Supported values: 'None' and 'hyperv'. Default: 'hyperv'. It allows to specify the parameter "--isolation" in the [docker build](https://docs.docker.com/engine/reference/commandline/build/#specify-isolation-technology-for-container---isolation) command.
- **PushMode**: Optional. Supported values: 'Always', 'IfChanged', 'Never'. Default: 'Never'. Indicates whether the images must be pushed to the registry after it is built.
- **RemoveInstallationAssetFiles**: Optional. Supported values: true and false, Default: false. Indicates whether installation assets should be removed after building the images.
- **WhatIf**: Optional. Allows to check whether the images' assets exist without performing further actions.

Please notice that the module "Sitecore.DockerImages.Management" has a dependency on the module "Bendev.Assets.Management" and must be installed and imported after the "Bendev.Assets.Management" is installed.

### Build Server

Configure your build server to:

1. Trigger a build on changes to this git repository - to get new versions.
1. Trigger once a week - to get base images updated when Microsoft releases patched images.


## Docker Registry

A Docker registry is a storage and content delivery system, holding named Docker images, available in different tagged versions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
function Get-ImageBuildFolders {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateScript( {Test-Path $_ -PathType 'Container'})]
[string]$BuildRootPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$VersionsFilter,
[Parameter(Mandatory = $true)]
[ValidateScript( {Test-Path $_ -PathType 'Container'})]
[string]$AssetsSourcePath,
[Parameter(Mandatory = $false)]
[ValidateScript( {$_ -eq $null -Or (Test-Path $_ -PathType 'Container')})]
[string]$AssetsTransformPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Registry
)
if ([String]::IsNullOrWhiteSpace($AssetsTransformPath)){
$AssetsTransformPath = $AssetsSourcePath;
}
$versionFolderPaths = Get-ChildItem -Path $BuildRootPath -Filter 'build.json' -Recurse | Select-Object -ExpandProperty Directory | Select-Object -ExpandProperty FullName -Unique | Select-String -Pattern $VersionsFilter
if ($versionFolderPaths){

Get-Item -LiteralPath $versionFolderPaths | Foreach-Object {
$imageFolder = $_
$buildFilePath = Join-Path $imageFolder.FullName "\build.json"

if (Test-Path $buildFilePath -PathType Leaf) {
$data = Get-Content -Path $buildFilePath | ConvertFrom-Json
$assets = [Asset]::ParseArray(@($data.assets))

# Build up tag to use
$repository = $data.repository
$tags = $data.tags
$mainTag = "{0}/{1}:{2}" -f $Registry, $repository, $tags[0]
$baseImage = '<None>'
if ($data.args) {
$args = $data.args
$args.PSobject.Properties | ForEach-Object {
if ($_.value -is [string]) {
$_.value = $_.value.Replace('${Registry}', $Registry)
}
}
$baseImage = $args.PSobject.Properties | ForEach-Object { if ($_.name -match "BASE_IMAGE") {Write-Output $_.value}}
}

$baseImages = Get-ChildItem -Path $imageFolder.FullName -Filter "Dockerfile" | Foreach-Object {
$dockerfilePath = $_.FullName
$fromClauses = Get-Content -Path $dockerfilePath | Where-Object { $_.StartsWith("FROM ") }

$fromClauses | ForEach-Object {
$image = $_

if ($image -like "* as *") {
$image = $image.Substring(0, $image.IndexOf(" as "))
}

if ([string]::IsNullOrEmpty($image)) {
throw ("Invalid dockerfile '{0}', FROM image could not be read." -f $dockerfilePath)
}

#$image = $image.Replace('${BASE_IMAGE}', $baseImage)

Write-Output $image
}
}
$baseImages = $baseImages | Select-Object -Unique | ForEach-Object { Write-Output $_.Replace("FROM ", "").Trim() } | ForEach-Object { Write-Output $_.Replace('${BASE_IMAGE}', $baseImage) }

Write-Output (New-Object PSObject -Property @{
Repository = $repository;
Tags = $tags;
Args = $args;
MainTag = $mainTag;
Memory = $data.memory;
Path = $imageFolder.FullName;
BaseImages = $baseImages;
Assets = $assets;
})
}
else {
throw ("Invalid version folder '{0}', file not found: '{1}'." -f $imageFolder.Name, $buildFilePath)
}
}
}

}
Loading

0 comments on commit da0b08f

Please sign in to comment.