Working Locally with Sitecore XM Cloud: Connecting, Managing, and Serializing Items
In the previous blog, we walked through the step-by-step local installation of Sitecore XM Cloud. In this post, we’ll take the next step by exploring how to connect cloud and local environments setup by:
- Configuring
item serialization
- Connecting
to an XM Cloud environment
- Connecting
to your local environment
- Pull
serialized items from XM Cloud into your local repository
- Push
serialized items into the local environment
This workflow is essential because a local XM Cloud
instance is a vanilla instance with no items. To work effectively, you’ll need
to bring down items from your cloud environment. With Sitecore Serialization,
you can sync items between cloud and local setups, ensuring your local
development mirrors what exists in the cloud.
Configure item Serialization
The local installation includes the file at the below path for
rendering host serialization
authoring/items/next-starter.module.json
For local development, you need a new serialization configuration, follow below steps to achieve that:
1. Navigate to the authoring/items
path
2. Create a subfolder named with
your site name like mysite
authoring/items/mysite
3. Create a new serialization
module file inside this folder like
mysite.module.json.
4. Copy the content from the
existing serialization module file next-starter.module.json into your new file
as a starting point.
5. Update the name or namespace
value to match with your site name.
6. Modify the items section to
include
- Placeholder settings
- Templates created during
deployment
- Content items (tenants, sites,
pages)
- Media items
7. Save the file.
Connect to an XM Cloud Environment
Before pulling or pushing items, you need to connect your
local project with your XM Cloud organization.
1. Authorize your device:
dotnet sitecore cloud login
It opens a browser popup for device confirmation like below
After confirming, it will ask for sign in with your XM Cloud credentials
Provide the credentials and follow the directions, on success it will show below screen.
Successful authentication stores a token in .sitecore/user.json file
2. List all projects in your organization:
dotnet sitecore cloud project list
It shows all the projects as below, Copy the Project ID for the project you’re working with
3. List environments for the selected project:
dotnet sitecore cloud environment list --project-id <project-id>
4. Connect to an environment (e.g., dev).
dotnet sitecore cloud environment connect -id <environment-id> --allow-write true
It will show the message like connections to the
environment and updates .sitecore/user.json with the selected environment
details
Connect Your Local Environment
To connect your local instance to XM Cloud, we need to
identify the local environment and add that to the user.json file by
running below command
dotnet sitecore connect --ref xmcloud --cm
https://xmcloudcm.localhost --allow-write true -n local
Your .sitecore/user.json now includes a local endpoint
configuration as below.
Pull Serialized Items from XM Cloud
With both environments connected, you can now pull items
from the cloud into your local source code repository using below command
dotnet sitecore ser pull -n "dev"
The command output shows what items have been serialized.
The command serializes items into the src/items folder.
Depending on your configuration, you’ll see subfolders like:
- content-root
- media
- templates
Push Serialized Items into Local Environment
As we have pulled the serialized items that were created in
your remote XM Cloud environment, now we can push them to the local XM instance
using below command
dotnet sitecore ser push -n "local"
Now visit your local instance (http://xmcloudcm.localhost)
and verify that templates, content, and media items appear as expected.
By following these steps, you can now connect a local XM
Cloud instance to the cloud, pull serialized items, and push them locally. This
ensures your development environment mirrors the cloud environment, making it
easier to build, test, and deploy changes with confidence.
Hope this helps!
Comments
Post a Comment