Tailwind Logo

Building a Sitecore Headless Development and Testing Environment Part 3 - Installing Modules in Containers - Content Hub Connector

Docker

Published: 2022-08-26

To align the container environment with the server, we'll ensure all necessary modules are available in Docker. The current Docker container already has SXA and Horizon configured, so we'll install any missing components as needed.

モジュールのインストール

The following modules have been installed in the production environment and are missing.

  • Sitecore Headless Rendering 20.0.0
  • Sitecore Connect for Content Hub 5.0
  • Sitecore Management Service 5.0

Please refer to the following pages to get started, except for Sitecore Content Hub, which will be introduced separately and additionally later in this article.

上記のモジュールのインストールの方法ですが、以下のページで紹介をしています。下記のページで Headless Services に関しては SXA を削除していますが、今回は削除せずに追加しておきます。

Start the system once to confirm that the installation is complete.

PowerShell
docker compose up -d

Tenants can be created by right-clicking.

docker07.png

The module installation is now complete.

Installing Sitecore Connect for Content Hub 5.0.0

First, define the version of the connector and the connection strings in the .env file.

Plain Text
CONTENTHUB_VERSION=5.0.0-1809

CMP_ContentHub=
CMP_ServiceBusEntityPathIn=
CMP_ServiceBusSubscription=
CMP_ServiceBusEntityPathOut=
DAM_ContentHub=
DAM_SearchPage=
DAM_ExternalRedirectKey=Sitecore

Then, using the above values, set the values to be used in the container for cd and cm. The following is the difference data, so please set each item for each role.

Dockerfile
  cd:
    build:
      args:
        CONTENTHUB_ASSETS_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-chub-assets:${CONTENTHUB_VERSION}
    environment:
      Sitecore_ConnectionStrings_DAM.ContentHub: ${DAM_ContentHub}
      Sitecore_ConnectionStrings_DAM.SearchPage: ${DAM_SearchPage}
      Sitecore_ConnectionStrings_DAM.ExternalRedirectKey: ${DAM_ExternalRedirectKey}
  cm:
    build:
      args:
        CONTENTHUB_ASSETS_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-chub-assets:${CONTENTHUB_VERSION}
    environment:
      # DEMO TEAM CUSTOMIZATION - Custom integrations
      Sitecore_ConnectionStrings_CMP.ContentHub: ${CMP_ContentHub}
      Sitecore_ConnectionStrings_CMP.ServiceBusEntityPathIn: ${CMP_ServiceBusEntityPathIn}
      Sitecore_ConnectionStrings_CMP.ServiceBusSubscription: ${CMP_ServiceBusSubscription}
      Sitecore_ConnectionStrings_CMP.ServiceBusEntityPathOut: ${CMP_ServiceBusEntityPathOut}
      Sitecore_ConnectionStrings_DAM.ContentHub: ${DAM_ContentHub}
      Sitecore_ConnectionStrings_DAM.SearchPage: ${DAM_SearchPage}
      Sitecore_ConnectionStrings_DAM.ExternalRedirectKey: ${DAM_ExternalRedirectKey}

To run the container, you need to set the values in web.config and connectionstrings.config. For this description, create a folder called Data in cm and cd and a folder called transforms in it. Under that folder, set web.config.cm.xdt.

XML
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location>
    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <!-- CSP -->
          <add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="Content-Security-Policy" value="default-src 'self' 'unsafe-inline' 'unsafe-eval' https://apps.sitecore.net https://*.stylelabs.io https://*.stylelabs.cloud https://*.stylelabsdemo.com https://*.stylelabsqa.com https://*.stylelabsdev.com https://*.sitecoresandbox.cloud https://*.azureedge.net https://stylelabs.eu.auth0.com https://login.windows.net https://login.microsoftonline.com https://*.boxever.com https://*.xmcloudcm.localhost; img-src 'self' data: https://*.stylelabs.io https://*.stylelabs.cloud https://*.stylelabsdemo.com https://*.stylelabsqa.com https://*.stylelabsdev.com https://*.sitecoresandbox.cloud https://*.azureedge.net https://*.gravatar.com https://*.wp.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' 'unsafe-inline' https://fonts.gstatic.com; frame-ancestors 'self' https://*.sitecoredemo.localhost https://*.xmcloudcm.localhost https://*.sitecoredemo.com;"/>
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xdt:Transform="InsertIfMissing">
      <!-- Include binding redirects for CH Connector 5.0.0 on XM -->
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Extensions.Caching.Abstractions')">
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Extensions.Primitives')">
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Azure.ServiceBus')">
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Azure.Amqp')">
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Extensions.Caching.Memory')">
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Remotion.Linq')">
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Insert" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Extensions.Caching.Abstractions')">
        <assemblyIdentity name="Microsoft.Extensions.Caching.Abstractions" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-3.1.14.0" newVersion="3.1.14.0" />
        <codeBase version="2.1.2.0" href="bin/Microsoft.Extensions.Caching.Abstractions.dll" />
        <codeBase version="3.1.5.0" href="bin/Microsoft.Extensions.Caching.Abstractions.dll" />
        <codeBase version="3.1.14.0" href="bin/scch/Microsoft.Extensions.Caching.Abstractions.dll" />
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Insert" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Extensions.Primitives')">
        <assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-3.1.14.0" newVersion="3.1.14.0" />
        <codeBase version="2.1.1.0" href="bin/Microsoft.Extensions.Primitives.dll" />
        <codeBase version="3.1.5.0" href="bin/Microsoft.Extensions.Primitives.dll" />
        <codeBase version="3.1.14.0" href="bin/scch/Microsoft.Extensions.Primitives.dll" />
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Insert" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Azure.ServiceBus')">
        <assemblyIdentity name="Microsoft.Azure.ServiceBus" publicKeyToken="7e34167dcc6d6d8c" />
        <codeBase version="3.1.0.0" href="bin/Microsoft.Azure.ServiceBus.dll" />
        <codeBase version="3.2.1.0" href="bin/Microsoft.Azure.ServiceBus.dll" />
        <codeBase version="4.1.2.0" href="bin/scch/Microsoft.Azure.ServiceBus.dll" />
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Insert" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Azure.Amqp')">
        <assemblyIdentity name="Microsoft.Azure.Amqp" publicKeyToken="31bf3856ad364e35" />
        <codeBase version="2.3.0.0" href="bin/Microsoft.Azure.Amqp.dll" />
        <codeBase version="2.4.0.0" href="bin/scch/Microsoft.Azure.Amqp.dll" />
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Insert" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Extensions.Caching.Memory')">
        <assemblyIdentity name="Microsoft.Extensions.Caching.Memory" publicKeyToken="adb9793829ddae60" />
        <codeBase version="2.1.2.0" href="bin/Microsoft.Extensions.Caching.Memory.dll" />
        <codeBase version="3.1.5.0" href="bin/Microsoft.Extensions.Caching.Memory.dll" />
        <codeBase version="3.1.14.0" href="bin/scch/Microsoft.Extensions.Caching.Memory.dll" />
      </dependentAssembly>
      <dependentAssembly xdt:Transform="Insert" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Remotion.Linq')">
        <assemblyIdentity name="Remotion.Linq" publicKeyToken="fee00910d6e5f53b"/>
        <codeBase version="2.2.0.0" href="bin/scch/Remotion.Linq.dll"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Then create a folder App_Config and under that create a file ConnectionStrings.config.connectors.xdt with the following code

XML
<connectionStrings configBuilders="SitecoreConnectionStringsBuilder" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <add name="CMP.ServiceBusEntityPathIn" connectionString="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
  <add name="CMP.ServiceBusEntityPathOut" connectionString="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
  <add name="CMP.ServiceBusSubscription" connectionString="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
  <add name="CMP.ContentHub" connectionString="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
  <add name="DAM.ContentHub" connectionString="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
  <add name="DAM.SearchPage" connectionString="" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
  <add name="DAM.ExternalRedirectKey" connectionString="Sitecore" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
</connectionStrings>

With respect to the above, cd's should be placed in the same manner below.

When you are ready, make the changes to the Dockerfile regarding `cm` and `cd`.

Dockerfile
ARG CONTENTHUB_ASSETS_IMAGE

FROM ${CONTENTHUB_ASSETS_IMAGE} AS ch_assets

# Add SCCH module 5.0.0
COPY --from=ch_assets \module\cm\content .\

# Copy CM Resource
COPY .\Data\ .\

# Perform transforms
RUN (Get-ChildItem -Path 'C:\\inetpub\\wwwroot\\transforms\\web*.xdt' -Recurse ) | `
    ForEach-Object { & 'C:\\tools\\scripts\\Invoke-XdtTransform.ps1' -Path 'C:\\inetpub\\wwwroot\\web.config' -XdtPath $_.FullName `
    -XdtDllPath 'C:\\tools\\bin\\Microsoft.Web.XmlTransform.dll'; };

RUN (Get-ChildItem -Path 'C:\\inetpub\\wwwroot\\transforms\\app_config\\ConnectionStrings*.xdt' -Recurse ) | `
    ForEach-Object { & 'C:\\tools\\scripts\\Invoke-XdtTransform.ps1' -Path 'C:\\inetpub\\wwwroot\\app_config\\ConnectionStrings.config' -XdtPath $_.FullName `
    -XdtDllPath 'C:\\tools\\bin\\Microsoft.Web.XmlTransform.dll'; };

You are now ready to go. Rebuild and run the container by setting up a connection string to the Sitecore Content Hub in the .env file. Instructions on how to create the connection string are provided in the section on installing the module on the server.

Additional configuration on the Sitecore Content Hub side needs to be performed. We need to add a CM server for this demo to the Content Hub instance that we will be working with. The procedure is as follows

  • Open Management Tools
  • Open Settings
  • Select the CORSConfiguration section
  • Add https://cm.sitecoredemo.localhost to save
docker09.png

上記の準備が全て完了したところで、以下のように実行します。

PowerShell
docker compose build
docker compose up -d

Open the Rich Text section to see more items to connect to the DAM, and click on them to see that you can select assets from the Sitecore Content Hub.

docker08.png

Summary

In the last issue, we created a custom container, and in this issue, we installed modules so that we can run the same environment as the server we prepared in the first issue using Docker containers. In the next issue, we will implement the procedure to make the administration screen Japanese.

Tags