Creating an assets image for Sitecore module from SCS serialization package

Jack Spektor
3 min readOct 22, 2024

--

Hello

Today I’ll share a quick guide how to create custom Docker assets image for Sitecore modules

Why do you need custom Sitecore asset image?

If you used SXA, DEF or other Sitecore modules before you’d notice how you can easily add new module into your Dockerfile just by copying the assets

But what if you have your own custom reusable code that you’d like to share between your projects, or maybe share with the community?

Before Docker you’d create a Sitecore package, but now you’d like to package it as Docker image.

This would allow your shared code to be reusable, dependencies to be versioned and also improves Docker build speed thanks to build cache.

Now how can we do something like that?

Step 1: Create new image in Docker compose

The image property would contain the name of the custom Docker image, and url of its location on container registry.

If you don’t have container registry, but want to share your image to community — Github provides the free registry storage for your open-source projects.

You just need to login to Github registry on your PC with your token and specify the image url as ghcr.io/[your-username]/[image-name]

Note that we are using nanoserver as base image as it takes least amount of disk size, but it can actually be any Docker image as a base.

 custom-cm-assets: 
image: ${CUSTOMASSETS_IMAGE}
build:
context: ./docker/build/custom-cm-assets
args:
PARENT_IMAGE: mcr.microsoft.com/windows/nanoserver:ltsc2022
deploy:
replicas: 0

Step 2: Prepare Dockerfile and files for your Docker image

In your Docker build folder you’d have custom Dockerfile for your image, as well as files that you’d like to be included into the image.

In particular you’d like to include:

  • DLLs, configs and data files required for any custom code you’d like to include into the module
  • .dat files that would contain baked-in Sitecore items
ARG PARENT_IMAGE

FROM ${PARENT_IMAGE}

# Serialized items as IAR
ADD ./App_Data C:/module/cm/content/

# Custom DLLs
ADD ./bin C:/module/cm/content/

# Custom config patches and other...
ADD ./App_Config C:/module/cm/content/

The second part would require some additional step to generate that .dat files from your SCS serialized items.

Step 3: Generate IAR .dat files

Kamruz provides a great guide on generating IAR files in this blogpost.

Thanks to Sitecore CLI we can generate .dat file and output it to our Docker context folder.

Here is an example for SCS (though Unicorn or TDS are also possible to convert to IAR format).

dotnet sitecore itemres create -o docker/build/custom-cm-assets/App_Data/items/master/custommodule --overwrite

As an output you should get .dat IAR file in your Docker context folder

Step 4: Final step — using the asset image in your CM/CD Dockerfile

Finally now we can use the image anywhere by simply referencing assets image and copying it’s files in your Dockerfile

FROM ${CUSTOMASSETS_IMAGE} as custom-cm-assets

COPY --from=custom-cm-assets C:\module\cm\content C:\inetpub\wwwroot

Happy coding!

--

--

Jack Spektor
Jack Spektor

Written by Jack Spektor

Sitecore MVP 2018–2020, Sitecore Developer in AKQA, traveler and lover of life. jackspektor.com

No responses yet