SXA-Enable your deployment topology using Powershell Script
What is the context?
The end-result of this is the infamous Ensure/Sync default content paths error (at the 184th step... huh!) while trying to install Sitecore Commerce. What this means is, you can't install Sitecore Commerce on top of just the XP0 installation.
SIA to the rescue:
This is where Sitecore Install Assistant (SIA) helps. You have the option to install SXA albeit as an optional module. I just wanted to look under-the-hood of setup.exe.config (used by SIA) in order to see the possibility of installing SXA through Powershell. So, when I checked the SIA setup.exe.config file, which comes with Sitecore 10.0.0 rev. 004346 (Setup XP0 Developer Workstation rev. 1.2.0-r64).zip this is what it has:
In other words, you need to inject a separate json file that will do the tasks related to SXA/SPE installation for you. So, this blog article is about the same.
Why Powershell?
When it comes to a continuous process, scripts are better off. In case of SIA, there is a need for human intervention in the installation or deployment process. So, its necessary to have a solution that is script-based for all scenarios.
Concepts first:
Before we get into the details, we need to understand the concept of how Powershell and JSON collaborate generally in Sitecore. Here is a high-level diagram for the same:
So, I decided to call each of the JSON files above as worker JSON files.
Sections in a JSON:
For instance, if you open the spe.json file, it has the following sections:
a. Parameters: Data gets passed between JSON files through parameters
b. Variables: These are for internal usage (within the json file), parameters could be manipulated/concatenated and passed to the tasks thereafter
c. Tasks: The tasks listed in this section get executed one after another. Here is a snapshot of tasks within spe.json:
With this background, let's proceed. Let's define the master and worker files for this scenario:
Master File:
SXA-SingleDeveloper.json
Worker Files:
spe.json
sxa-solr.json
sxa-xp0.json
A few points to ponder:
1. Don't modify the worker or master files since we just need to ensure they get the proper parameter values at runtime
2. XP0-SingleDeveloperwithSXA.ps1: This is a separate Powershell Script for XP0 + SXA installation
3. XP0-SingleDeveloperwithSXA.json: This is the corresponding JSON file that will act as a mapping layer to pass parameters from master to the worker JSON files
Changes to XP0-SingleDeveloperwithSXA.ps1 file:
Note that this powershell script is a copy of XP0-SingleDeveloper.ps1 but accepts two extra parameters I added:
- SPEPackage
- SXAPackage
These parameters need to be passed as part of $singleDeveloperParams:
In the above step, we just make the two new parameters part of a bundle that gets passed during execution of different tasks part of worker JSON files.
Changes to XP0-SingleDeveloperwithSXA.json file: This file has all the contents of XP0-SingleDeveloper.json file alongwith the following changes:
1. I appended the new SXASingleDeveloper.json to the includes list:
3. I also added the mappings needed by the Worker file params based on what gets passed from the XP0-SingleDeveloperwithSXA.ps1 (yes, the powershell script) file. Here is a snapshot of some of the parameters in XP0-SingleDeveloperwithSXA.json:
Note that the most important aspect is the Reference field (above). This field contains the field name from where the parameter value will flow in. Note that XP0-SingleDeveloperwithSXA.ps1 will use the parameters defined in XP0-SingleDeveloperwithSXA.json. While the PS script will have the actual values, the json file will just have defaults. So, that is the reason the file names are used interchangeably.
How to install?
Here are my scripts for a site named xco10sc.dev.local. Make changes relevant to your setup (just in the powershell script). You don't need to touch the mappings for this scenario anymore. Note that these files should be placed along with the contents of Sitecore 10.0.0 rev. 004346 (Setup XP0 Developer Workstation rev. 1.2.0-r64).zip. You don't need to touch the $SXAPackage, $SPEPackage variables in the PS Script since the packages are in the same location as these files:
That's it. Fire the PS command line in Administrator mode, traverse to the location where you have unzipped the above file. Then, execute XP0-SingleDeveloperwithSXA.ps1. You should see 114 steps instead of 92 steps. If all needed mappings are present, correct values will flow from the PS script to the individual tasks in the json files and SXA must be installed. You can check the same in the backend:
Final note: This approach can be used for other topologies / scenarios wherein you have to include or exclude necessary / unnecessary json files passing necessary params. This way you can even run cutdown list of tasks.
Now, you are all set to install Commerce without the help of SIA!
Comments
Post a Comment