Set up your full-stack SitecoreAI local development environment
When you create a project using the Deploy app and choose the foundation template as the source for the initial deployment, the process adds the foundation template to the source control repository you configured for the initial environment.
You can use the resulting codebase to set up your local development environment based on Docker containers.
Make sure you are using Docker v.2, as explained here.
To use the foundation template, you must have the following software components on your workstation:
-
A valid Sitecore license file.
-
Windows PowerShell.
-
The current long-term support (LTS) version of Node.js.
-
.NET 8 (check your installed version with the
dotnet --versioncommand). -
.NET Framework 4.8 SDK (see the Microsoft procedure for checking .NET Framework versions).
-
Docker for Windows, with Windows Containers enabled.
NoteThe SitecoreAI containerized environment depends on the Docker engine and Docker CLI. While the containerized environment doesn't have any dependency on DockerDesktop, we haven’t officially tested running SitecoreAI locally without it.
We recommend that you consult your IT department and the official Docker documentation for setting up Docker in a Windows environment.
-
Any required components for using Sitecore Containers.
This walkthrough describes how to:
Prepare the environment
Before starting the containers, you must ensure the necessary ports are accessible.
To prepare the environment for running the solution:
-
Open PowerShell with administrator privileges.
-
Check if you have the internet Information Server running on port 443:
RequestResponseGet-Process -Id (Get-NetTCPConnection -LocalPort 443).OwningProcessIf you do, you must stop it:
RequestResponseiisreset /stop -
Check if you have Apache Solr or any other service running on port 8984:
RequestResponseGet-Process -Id (Get-NetTCPConnection -LocalPort 8984).OwningProcessIf you do, you must stop it:
RequestResponseStop-Service -Name "<the name of your service>"Alternatively, if you have started it with Non-Sucking Service Manager, stop it with the following command:
RequestResponsenssm stop "<the name of your service>"
Configure and run the solution
The foundation template contains the software components and scripts to:
-
Update container images.
-
Build the containers.
-
Set up the necessary hosts.
-
Start the containers.
-
Start the Content Management (CM) instance.
-
Install the Sitecore CLI and the necessary plugins.
-
Populate the Solr Managed Schemas.
-
Rebuild indexes.
-
Serialize and push developer-managed items to the instance.
-
Open the CM instance and client app in the browser.
Even if you plan on running multiple content management instances (multiple projects) locally, the hostname of every instance must follow the *.xmcloudcm.localhost pattern for authentication to work correctly. In other words, you can have hostnames such as myproject.xmcloudcm.localhost but not cm.mycompany.localhost.
Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
To set up the template for running locally and start the containers:
-
Open PowerShell with administrator privileges.
-
In your project directory, clone the repository you configured for the project.
-
Using a command-line interface, go to the root of your repository folder.
-
To prepare the Sitecore container environment, run the script
init.ps1from the root directory of the project:RequestResponse./local-containers/scripts/init.ps1 -InitEnv -LicenseXmlPath "<C:\path\to\license.xml>" -AdminPassword "<desired password>"TipIf you are not using the foundation template, you might not have the
init.ps1script in your project. You can copy theinit.ps1script from the starter kit repository. -
If you are using Windows 10, you need to align the container base images with what Windows 10 supports. To do this:
-
In the
init.ps1file, change the$baseOsversion setting toltsc2019. -
In the
.envfile, replace the following variables with these values:RequestResponseTRAEFIK_IMAGE=traefik:v2.5.3-windowsservercore-1809 NODEJS_PARENT_IMAGE=mcr.microsoft.com/windows/nanoserver:1809
-
-
To download the Sitecore Docker images, install and configure the containers and client application, run the following script:
RequestResponse./local-containers/scripts/up.ps1TipIf you are not using the foundation template, you might not have the
up.ps1script in your project. You can copy theup.ps1script from the starter kit repository. -
When prompted, in your browser, log in to the instance and accept the device authorization.
-
If you are a member of multiple organizations, select the organization for the current project.
-
Wait for the startup script to open browser tabs for the rendered site and the Sitecore Launchpad.
If you have to reset the state of your containers, you can run the \docker\clean.ps1 script. It clears all mounted data and the deployed/copied build output. After running the .\docker\clean.ps1 script, you must rebuild search indexes.
Configure item serialization
If you inspect the content tree using the Content Editor tool while the local instance is running, you'll see that the local instance doesn't have any of the items for your new site. This is because the site was originally created in your remote environment, not in the local one, and the local instance doesn’t automatically include those items. You must therefore transfer the site items to your local and remote repositories so that every developer can access them.
You can synchronize items between environments with Sitecore Serialization. The repository already contains the necessary setup for enabling serialization if you are using an official SitecoreAI foundation template. It also includes the authoring/items/next-starter.module.json file that configures the rendering host item serialization. While developing locally, however, you need additional configuration.
To create a new serialization configuration:
-
In the
authoring/items/{SITE_NAME}folder, create a new serialization module file. Give it a meaningful name, for example,mysite.module.json. -
Replace the
namespacevalue with a unique value, such as the site name. For example,MySite. -
Copy the content from the existing serialization module definition as a starting point, and modify the
itemsproperty to include:-
The placeholder settings:
RequestResponse{ "name": "layout", "path": "/sitecore/layout/Placeholder Settings/Project/placeholdersite", "allowedPushOperations": "CreateUpdateAndDelete" } -
The templates created during the deployment process:
RequestResponse{ "name": "templates", "path": "/sitecore/templates/Project/MySite", "allowedPushOperations": "CreateUpdateAndDelete" } -
The content item, which includes tenants and sites:
RequestResponse{ "name": "contentRoot", "path": "/sitecore/content", "allowedPushOperations": "CreateUpdateAndDelete" }CautionThis configuration serializes the entire content tree because it does not have a single-item scope. When content authors start working on items, you must change this configuration to prevent overwriting their work when performing serialization push operations.
-
The media items:
RequestResponse{ "name": "media", "path": "/sitecore/Media Library/Project/MySite", "allowedPushOperations": "CreateUpdateAndDelete" }
You can configure additional paths such as renderings, layouts, settings, and more, after they are created in the instance.
-
-
Save the file.
Authorize within the SitecoreAI organization
Before performing operations against a remote SitecoreAI instance, you must authenticate within your organization.
To authorize the local project in your organization:
-
Run the following command:
RequestResponsedotnet sitecore cloud loginFollow the steps in the user interface to log in and authorize your device. When you finalize the authentication process, the connectivity information is stored in the
.sitecore/user.jsonfile.
Connect a SitecoreAI environment
You can connect to one or more remote environments.
To connect to an environment:
-
Obtain the ID of your project by running the command:
RequestResponsedotnet sitecore cloud project listIdentify the project you are working on and copy the ID.
TipIf you don't have a project, create a project in the Deploy app.
-
Obtain the ID of your environment by running the command:
RequestResponsedotnet sitecore cloud environment list --project-id <project-id>Identify the environment you want to connect to and copy the ID.
-
Run the environment connect command:
RequestResponsedotnet sitecore cloud environment connect -id <environment-id> --allow-write true
The process updates the .sitecore/user.json file with the environment connection configuration if the connection is successful. Assuming you named your environment dev, the .sitecore/user.json file now contains a dev key in the endpoints object:
{
"endpoints": {
"xmCloud": {
...
},
"dev": {
"ref": "XMCloud",
"allowWrite": true,
"host": "<the environment host>",
"variables": {}
}
}
}Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
Connect the local environment
You connect the local environment with the Sitecore CLI connect command.
To connect:
-
In a terminal, go to the root directory of the local project and run the following command:
RequestResponsedotnet sitecore connect --ref xmcloud --cm https://xmcloudcm.localhost --allow-write true -n local
The process updates the .sitecore/user.json file with the local environment connection configuration:
{
"endpoints": {
"xmCloud": {
...
},
"dev": {
...
},
"local": {
"ref": "xmcloudlocal",
"allowWrite": true,
"host": "https://xmcloudcm.localhost",
"variables": {}
}
}
}Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
Pull serialized items from SitecoreAI to your local repository
With authentication/authorization in place and the necessary environment references added to .sitecore/user.json, your local project is ready to perform serialization operations.
To pull serialized items from the remote environment:
-
In the terminal, run the Sitecore serialization
pullcommand, specifying the environment name as configured in the.sitecore/user.jsonfile:RequestResponsedotnet sitecore ser pull -n "dev"The command output shows what items have been serialized.
Based on your serialization configuration, the source code now contains the src/items folder with the subfolders content-root, media, and templates.
Push serialized items into the local environment
Now that you have pulled the serialized items that were created in your remote environment from there into your local repository, you can push them into your local instance.
To push the serialized items into your locally running instance:
-
In the terminal, run the Sitecore serialization
pushcommand, specifying the local environment name as configured in the.sitecore/user.jsonfile:RequestResponsedotnet sitecore ser push -n "local"
When the operation is complete, you can see the new items in your locally running instance. You can now commit and push the serialized items to your remote version control repository.
The command serialization push (ser push) does not publish items. You must manually publish them.
Next steps
With this setup complete, you can start developing your SitecoreAI solution and your front-end application.
As you work, you can use the Sitecore CLI to perform common development tasks such as: