Showing posts with label containers. Show all posts
Showing posts with label containers. Show all posts

Wednesday, 1 March 2023

When Disabling xDB Isn't Enough

If you read the documentation on using CMS-only mode to run Sitecore without xDB you'd be forgiven for thinking that a config patch such as this is the simple end of the story:

<configuration>
    <sitecore>
        <settings>
            <setting name="Xdb.Enabled" value="false" />
            <setting name="Xdb.Tracking.Enabled" value="false" />
        </settings>
    </sitecore>
</configuration>

Unfortunately as someone on Slack recently discovered, this doesn't help if you're trying to run Sitecore (XP container images, but in CMS-only mode without the xConnect instances) in containers. 

The issue is fairly obvious when you notice CM is not starting and take a look at an example of the logs

920 08:52:34 ERROR Health check Sitecore.XConnect.Client.WebApi.CollectionWebApiClient completed after 0.0038ms with status Unhealthy and 'Error during CollectionWebApiClient initialization: An error occurred while sending the request.'

1920 08:52:35 ERROR Health check Sitecore.XConnect.Client.WebApi.ConfigurationWebApiClient completed after 0.0054ms with status Unhealthy and 'Error during ConfigurationWebApiClient initialization: An error occurred while sending the request.'

1920 08:52:36 ERROR Health check Sitecore.XConnect.Client.WebApi.SearchWebApiClient completed after 0.0068ms with status Unhealthy and 'Error during SearchWebApiClient initialization: An error occurred while sending the request.'

Yes, there are in fact health checks on CM and CD which check the status of xConnect, and completely ignore the config settings I mentioned above.

Not to worry, there are a couple of options at this point:

  1. Use a config patch to remove the health checks (the easier option)
  2. Update and override the health checks so that they respect the Xdb.Enabled setting

Config patch

Here's an easy patch you can apply which should remove these from your Sitecore configuration and complete the disabling of xDB:

Updating the code

The "proper" way, I feel, would be to update the code to respect the Xdb.Enabled setting. This is what the setting is indicating, and what the documentation explains that it is for.

To take XConnectCollectionHealthCheckServicesConfigurator as an example:

public class XConnectCollectionHealthCheckServicesConfigurator : Sitecore.XConnect.Client.Configuration.HealthCheckServicesConfigurators.XConnectCollectionHealthCheckServicesConfigurator
{
  protected override IHealthCheck CreateCommonWebApiHealthCheck(IServiceProvider provider)
  {
    if (Sitecore.Configuration.Settings.GetBoolSetting("Xdb.Enabled", true))
      return base.CreateCommonWebApiHealthCheck(provider);
    else
      return new SuccessHealthCheck();
  }
}

public class SuccessHealthCheck : IHealthCheck
{
  public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
  {
    return Task.FromResult(HealthCheckResult.Healthy());
  }
}

We add our settings check, and - because there does not seem to be any easy out-of-the-box way to return a successful health check - we also need to create a class for that. Repeat for all 3 health checks, and you're good to go.

Enjoy running your Sitecore topology nice and lean!

Sunday, 19 February 2023

Setting up a Sitecore Developer Laptop in 2023

So with the start of the new year, and new company, comes the fun part - a purchase of a new laptop. Exciting! I finally get to play with Windows 11 (Pro), and not be restricted by work security.

Long gone are the days of SIF-based installs, with SQL/Solr running as Windows services (and likely many instances of them, if you were working on multiple versions of Sitecore). These days everything can be done on containers and VS Code (yes, even back-end dev).  

With the release of (some) ltsc2022 images over the last week, we can finally use process isolation on Windows 11! Yes it's in preview, but at least your computer won't have a heart attack from lack of resources!

So because it was all so easy, I thought I'd quickly note down the few things I needed to install to get going. As a bonus I've included some configuration that might catch you out, or you may have forgotten if you've done it before.

Windows features

  1. Containers / HyperV
  2. IIS (optional, if you want to do a proper install at some point)


Software

  1. VS Code for most dev, plus extensions:
    1. Azure (Account / Functions /  App Service / Cache / Kubernetes Service / Pipelines / Resources / Static Web Apps / Storage)
    2. Docker
    3. Git History
    4. GraphQL (Language Feature Support / Syntax Highlighting)
    5. IntelliCode
    6. PowerShell
    7. Prettier - Code Formatter
    8. Scriban
    9. XML Tools
    10. YAML

  2. Visual Studio (probably optional, since VS Code can do everything these days!)
    1. TDS (optional, only if your clients use it)

  3. Node
    1. Sitecore JSS CLI

  4. Docker Desktop
  5. Git

  6. Make life easier: 7Zip / SQL Server Management Studio
  7. Testing APIs: Postman
  8. Decompiling: ILSpy / DotPeek
  9. Storage access: Filezilla & Azure Storage Explorer
  10. Remote access: Microsoft Remote Desktop and Client VPNs

Configuration

Visual Studio:


 

Docker settings:

Turn off docker-compose v2 (for now, until support is added by the Sitecore team)


Set the following Docker settings:

"features": {
  "buildkit": false
}

So only a dozen or so tools, plus a little setup and configuration. Pretty great if you ask me!
If there's anything I'm missing that you use to be productive I'd love to hear it. Leave a comment and I'll take a look (and hopefully make my life easier in the process).