Showing posts with label deploy. Show all posts
Showing posts with label deploy. Show all posts

Friday, June 1, 2018

Patching Sitecore web.config on Azure using VSTS WebApp deploy

With Sitecore, it's a best practice to not copy the web.config to your project, but use transformations. This is a really nice idea, but when deploying Sitecore using the ARM templates to Azure and apply your solution on top of it, you cannot edit the web.config. With the solution below I want to show how to apply config transformations on Azure using the VSTS Web App Service Deploy task. The method is kinda easy once you know how to do it.

First, add the code from configtransfrom to your App_Data\tools folder, the binaries and postdeployment command are stored here. Secondly add a web.azure.config to the project, with the build action set to Content. Lastly, update the release definition and add the postdeployment task to the Web App Service Deploy.



The line in the postdeploy.cmd that does the magic is:
"%WEBROOT_PATH%\App_Data\tools\configtransform\SlowCheetah.Xdt.exe" "%WEBROOT_PATH%\web.config" "%WEBROOT_PATH%\web.azure.config" "%WEBROOT_PATH%\web.config"

To see all other available environment variables run 'set' from the kudu console.

Offcourse the source is available on Github: https://github.com/luuksommers/sitecore-azure-configtransform

Happy transforming!
Luuk

Tuesday, July 8, 2014

Automatically deploy services using TFS2010

All credits for this post goes out to: Hrusikesh Panda and Mike Hadlow (see references below).

To deploy Windows services with TFS2010 there are 2 major challenges; seperate the binaries on a per-project basis and automatically stop and start a service without changing the build workflow. Sounds hard? It isn't!

If you don't want any blabla and download the sample solution directly, goto github.

First add the following files to your Solution folder and make sure they will be committed to TFS:
DeployApplication.targets (this is a copy of the WebDeploy targets from Microsoft with an extra change to copy the .config file).
DeployService.targets (this stops the service, copies the files and starts the service, it also contains the location on where to put the files)
safeServiceStart.bat (helper to start a remote service)
safeServiceStop.bat (helper to stop a remote service)
you can simply add these files to the solution items (right click solution and click add existing item).

Edit the DeployService.targets for the right paths on the remote machine. The directory where the service is located should be available for the user running the build using a standard windows share (\\<servername>\<project directory>\<servicename>, the servername is determined during the build and can be configured for each build quality.

Copy the Deploy.targets into the project you want to deploy, unload the project file and edit it with visual studio. Lookup the following line:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
And add this line below:
<Import Project="Deploy.targets" Condition="'$(DeployOnBuild)'=='True'" />
Save the file and reload the project

Once you've reloaded the project, edit the Deploy.targets (just double click on it) and change the service name and service location. Commit all changes to TFS.

The next step is to install the service on the remote machine. (using installutil, or whatever method you like, in the sample we can install a service by running it with the -I command line argument). The automated deployment will only start and stop the service and is not able to install and delete the service. (In my case, the service is running as a domain user, and therefor I prefer to pre-install the service with the right credentials or else you'll have to enter the credentials in the deployment script).

To enable automatic deployment, create a new Build Configuration on your TFS2010 server and set it up with a scheduled trigger (or whatever trigger you want). In the process section add the following MSBuild arguments:
 /p:DeployOnBuild=True /p:DeploymentServerName=\\<server-to-deploy-to>
If you also want to configure transformations (change the .config file during deployment), have a look at SlowCheetah. This works without a problem with this configuration. To make sure SlowCheetah only works during deployment, I've edited the project file again and added AND '$(DeployOnBuild)'=='True' in the following line:
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)') AND '$(DeployOnBuild)'=='True'" Label="SlowCheetah" />

(If you don't see this line, make sure you've installed SlowCheetah extension and added the transformations by right click on a .config file and click add transformations)

References:
http://mrchief.calepin.co/deploying-windows-service-via-msbuild
http://mikehadlow.blogspot.nl/2009/06/tfs-build-publishedwebsites-for-exe-and.html
https://github.com/luuksommers/TFSDeployedService

Happy deploying!

Luuk

Wednesday, September 7, 2011

Automatic deploy multiple websites in a solution using TFS Continious build

On the internet are a lot of resources to be found to automatically deploy websites to your (development) webserver. Here's how I solved that problem:

First of all, make sure your Team Foundation Server Continious build is up and running, and building packages the way you configured is.
Second of all, make sure you can deploy your website using the single click publish using MsDeploy.
Now edit the project file of the project(s) you would like to deploy and add the following tags in the PropertyGroup element:
<DeployTarget>MsDeployPublish</DeployTarget>
<CreatePackageOnPublish>false</CreatePackageOnPublish>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<MSDeployServiceUrl>https://yourwebserver:8172/MsDeploy.axd</MSDeployServiceUrl>
<UserName>YOURDOMAIN\User</UserName>
<Password>yourpassword</Password>
<AllowUntrustedCertificate>true</AllowUntrustedCertificate>
In the PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " element add the application path. By doing this, we can deploy different configuration types to app paths. If you need for example also a different username and password, you can add them in this section too.
<DeployIisAppPath>websites/Website</DeployIisAppPath>
Once we've edited the projects as mentioned above, we can setup the Build:

Voila! You're finished! Now build and watch your site change!

Save the build configuration and start a new build. If everything is correct, the website will be deployed on each build! For references you can look at the site of Vishal Joshi:
http://vishaljoshi.blogspot.com/2010/11/team-build-web-deployment-web-deploy-vs.html
http://vishaljoshi.blogspot.com/2009/11/web-deployment-painkillers-vs-2010-ms.html

and stack overflow:
http://stackoverflow.com/questions/2878385/how-do-you-deploy-a-website-and-database-project-using-tfs-2010