Skip to content

Customizing the initialization script

When we work with Docker and Sitecore, especially on a big project, is usual to have a lot of templates, components, and configurations that are serialized but take a lot of time to be ready each time when we up all containers.

So, here are the steps:

  • open the up.ps1 script
  • Add these new parameters
[Parameter(Mandatory = $false)]
[switch]$SkipPopulateSchema,
[Parameter(Mandatory = $false)]
[switch]$SkipRebuildIndexes,
[Parameter(Mandatory = $false)]
[switch]$SkipPushSerialization

once we added these parameters, is time to add the conditions for each action in this way

# Populate Solr managed schemas to avoid errors during item deploy
if (!$SkipPopulateSchema) {
    Write-Host "Populating Solr managed schema..." -ForegroundColor Green
    dotnet sitecore index schema-populate
}

if (!$SkipRebuildIndexes) {
    Write-Host "Rebuilding indexes..." -ForegroundColor Green
    dotnet sitecore index rebuild
}

if (!$SkipPushSerialization) {
    Write-Host "Pushing items to Sitecore..." -ForegroundColor Green
    dotnet sitecore ser push
}

so in this way, we can skip these steps, because when we work on a project with a lot of content usually these processes take a lot of time when we up our local environment.

finally when we call up.ps1 script with these parameters should be like this:

.\up.ps1 -SkipPopulateSchema -SkipRebuildIndexes -SkipPushSerialization

and that’s it.

PD: when you are creating new content, templates, and components for the first time, you will need to serialize your content using the following command:

dotnet sitecore ser pull

because if your run again up.ps1 script without these new parameters, you’ll lose all the stuff created.

Happy Coding!! 😉

Ramiro Batallas

Principal Backend Engineer at Oshyn Inc.

With over 15 years of working as a .Net Software Developer, implementing applications with MCV, SQL, Sitecore, Episerver, and using methodologies like UML, CMMI, and Scrum. Furthermore, as a team player, I can be described as a self-motivator possessing excellent analytical, communication, problem-solving solving and decision-making.