Removing Gulp from your CI Pipeline for Helix style solution with PowerShell

As previously discussed, if you have an Helix style solution, and you want to replace Gulp with PowerShell this script can come quite useful…

The principle is not to use Gulp for Build and packaging neither on your local environment (see this other post to see how to do it: https://sitecorecommerce.wordpress.com/2019/11/02/powershell-to-publish-helix-base-solution-with-visualstudio-2019-without-gulp/

neither on your Build server / Azure Pipeline….

as you can imagine PowerShell is your friend 🙂

In my specific example, I have instrumented it with VS 2017 but this script would work with any version of MS Build assuming that all parameters are supported….

BuildAndPublish

The principle is a pretty simple loop through all the project in Feature / Foundation / Project and just calling a simple MSBuild command to publish the project within my Temp folder….  Msbuild will build each project, and publish each project copying the Bin / Views / and configs in the Temp folder keeping your solution structure…

Once you have the temp folder, you can then Zip the package and use to deploy on your Sitecore instance…

 

Copying Unicorn Files With PowerShell for Azure Pipeline within an Helix style solution without GULP

In the case, you have an Helix style solution, you are using Unicorn and you use Azure Dev ops as your build pipeline to publish your solution on Azure PAAS and you want to use Gulp only for styles and scripts manipulations…

you will definitively need this snippet since you probably have already encountered this problem within your Build Pipeline…

The principle is pretty simple, you need to copy your YML files and keep all the folder structure within serialization… within the App_Data/Unicorn folder within a website Temp folder that you will later zip with the rest of Bin and Views so that you can install your changes once the package is deployed across the environment…

This is done within the Gulp – Package task typically, but if you want to get rid of it, I would recommend doing a separate PowerShell Task just to copy Unicorn files…

copyunicorn

The content of the Powershell is pretty simple and copy the files keeping your serialization structure across Feature, Foundation, Project folders…

Disaster Recovery region in Azure for Sitecore 9.x

In case you are worried about an Azure region going down and want to make your Sitecore Azure infrastructure not dependent on a single region, deploying a region for disaster recovery could be an option…

Obviously, depending on the complexity of your website, Sitecore resilience may be the minor problem in case of a region failure and further conversation should be taken to ensure that your infrastructure and data can be available across multiple regions….

As you can imagine, if your site is relying on Sitecore Analytics for personalization features your task won’t be trivial due to the Sitecore architecture, however, is a fair assumption and common practice to have analytics turned off on the DR region…

A typical DR region for Sitecore, would need the following elements:

  • Content Delivery server
  • WebDatabase
  • Redis cache (you could consider switching off if budget is an issue)
  • Search (assuming that is mandatory to have search available in case of DR)

My recommendation to provision a DR region on Azure PAAS would be to use the XM scaled scripts to provision a new environment in your favourite “backup” region and then delete the unrequired resources:

  • Identity server
  • Content Management Server
  • Master Database

The following Powershell script shows how to run the clean up of these resources…

 

Powershell to publish Helix base solution with VisualStudio 2019 without GULP

As most of Sitecore developers I quickly fall in love with Helix base solution approach but when it comes to developer experience Gulp was not feeling like the best match for build and deployment neither on my local machine…

As you have probably experienced, getting Gulp up and running is pretty simple, but as you start adding projects and complexity to your solution the build time increase exponentially and I have seen solutions where the Gulp build task taking more than 20 minutes, compared to 1-2 minutes of a standard Visualstudio build & publish command….

Therefore my idea to use Powershell even to deploy on my local machine for a full build and publish of my solution locally…

The idea is to hook in the full build and publish of all the projects on the publish of the main website project…

In reality, the code to achieve it, it is pretty simple and you can get it to work pretty easy since you need to worry only about three areas:

  1. Clean up of configs
  2. Build and publish of all the projects
  3. Copy configs that did not come after the full publish

As additional steps, you may consider including the Unicorn or TDS synchronisation to replicate what you do within Gulp but personally, I like to run manually all the items synchronisation to keep closer control and have quicker build and publish time…

Few things to do to get it running:

1.  Install prerequisites

IIS Management Script and Tools must be enabled from ‘turn windows features on or off’

preReqPS.JPG

2. Copy the powershells script and powershell config in the website – configuration folder

You need these two files from my Gist: https://gist.github.com/steliodibello/4cb47563ce43b922b943a000ec072853

remember to replace XXX with your project name

3. Amend the main webiste project to invoke the powershell on the after build step

<Target Name=”PublishAll” AfterTargets=”CopyAllFilesToSingleFolderForPackage”>
<Exec Command=”powershell.exe -NonInteractive –ExecutionPolicy Unrestricted -command &quot;&amp; { &amp;’$(SolutionDir)Configuration\PostPublish.ps1′ -solutionPath ‘$(SolutionDir)’ } &quot;” />
</Target>

 

For further reference and similar blogs who have inspired mine, have a look at:

https://www.onceinawhitemoon.net/2019/04/automatically-deploy-all-sitecore-helix-projects/

and

https://whipeter.wordpress.com/2018/09/07/sitecore-helix-build-and-deploy-powershell-script/

Azure PAAS for your Sitecore Dev environment with Power Shell

As I have previously blogged about Sitecore 8.2 on Azure PAAS  I decided that it was arrived the right moment for me to provision my Sitecore Dev environment on an Azure WebApp…

The main reason for doing it is to keep all the environments as similar as possible and deploy my code easily from VisualStudio OnLine and simplify my build & CI pipeline for my Dev environment having a production environment PAAS…

In regard having all the environments as similar as possible,  it could be a bit expensive with a cloud consumption based model…  and you can be tempted, as I have been, to have a much simpler configuration without the Sitecore Analytics in the Dev environment.

DevG.png

My ideal configuration for the Dev environment is as simple as possible to keep the cost down and be able to validate my code, to do that what I really need is just one WebApp to use as CM/CD and the standard SQL databases Master, Core, Web, in addition to this you may consider to keep the Insight Analytics on to monitor the environment and notify if any error occur.

Having played a bit with the Sitecore Azure toolkit and the Sitecore Arm Templates, I realised that any of the scripts was helping me to achieve my ideal Dev environment since all the scripts provision Azure Search and Redis cache provider and so I decided to get hands dirty with PowerShell.

After few attempts to change the scripts, I decided to go for an alternative approach:

  1. Take CM scripts and the CM web deploy packages, pretty standard…
  2. Remove all the Configs that relate to Azure Search in the CM package and repackage the webdeploy and upload on Azure Storage
  3. Make a power shell script to remove: Azure Search, Redis Cache Provider, CD WebApp
  4. Happy days with a cheap Sitecore dev environment running on an Azure WebApp

Changing the CM web deployment package is a trivial task just unzip the CA package and change the configs as you wish, in my case disabling these ones and enabling the equivalent ones for Lucene…

  • Sitecore.ContentSearch.Azure.DefaultIndexConfiguration
  • Sitecore.ContentSearch.Azure.Index.Core
  • Sitecore.ContentSearch.Azure.Index.Master
  • Social/Sitecore.Social.Azure.Index.Master
  • Sitecore.Social.Azure.IndexConfiguration
  • Sitecore.ListManagement.Azure.Index.List
  • Sitecore.ListManagement.Azure.IndexConfiguration
  • Sitecore.Marketing.Azure.Index.Master
  • Sitecore.Marketing.Azure.IndexConfiguration
  • Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Azure.Index.Master
  • Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Azure.IndexConfiguration

In regard the power shell script, it is also very simple since it use just Azure Resource manager commands and it looks like that…

 

$Name = "DevResGroup";

$redisserviceName = "$Name-redis";		
$searchserviceName = "$Name-as";
$cdserviceName =  "$Name-cd";
$cdPlanserviceName =  "$Name-cd-hp";

 #Deleting Redis Cache
Remove-AzureRmRedisCache -Name $redisserviceName -ResourceGroupName $Name
 
 #Get Search service and store it in $resource
$resource = Get-AzureRmResource `
    -ResourceType "Microsoft.Search/searchServices" `
    -ResourceGroupName $Name `
    -ResourceName $searchserviceName `
    -ApiVersion 2015-08-19
	
$resource
	
#Deleting your service will delete all indexes and data in the service
$resource | Remove-AzureRmResource

#Deleting your CD WebApp
Remove-AzureRmWebApp -Name $cdserviceName -ResourceGroupName $Name

#Deleting your CD WebApp Service Plan
Remove-AzureRmAppServicePlan  -Name  $cdPlanserviceName -ResourceGroupName $Name