How to deploy changes to Sitecore MVP Site while Docker instance is running?

While I started with the Sitecore MVP site, every time I did a change, I would do a compose down, run clean.ps1 and then execute the up.ps1 script. Note that the mvp site runs on asp.net core rendering host. So, this blog article is applicable for all such applications.

But this proved costly since it took a lot of time every time I made a change. Later, started thinking in lines of just pushing the build artifacts or the concerned dll to the deploy folder but since the container was running, there was a file access issue and this blog article covers what I did to improve "deploy-and-check-my-changes" cycle. I also realized that there are a lot of advantages with running docker logs side-by-side as you work with the site since it keeps watching for file changes and provides useful messages.

Probably this Dockerfile settings:


Some background:

Every time you run the up.ps1 script, Mvp.Project.MvpSite.exe gets created in the docker\deploy\mvp-rendering folder with the latest changes and the cd instance is automatically up and running:


After successful execution of up.ps1, I always execute docker-compose logs -f mvp-rendering and have it running in the PS window side-by-side.

Now, I commented the following lines in Startup.cs within Mvp.Project.MvpSite.csproj, 


I just build the Mvp.Project.MvpSite.Rendering.csproj  and this is what I see in my VS output window  (only later I realised that the logs are watching for file changes, if there is a change, fires MSBuild automatically and displays error/success messages):


I have also juxtaposed the \docker\deploy\mvp-rendering folder to show that there is nothing extra I had to do and the latest dll is deployed to the docker folder, it is all understandably Docker file magic:


But, when I check the logs window, I see build errors although VS didn't complain anything:


Now, when I access the home page, I get the following error:

To be sure, I uncomment the concerned lines in startup.cs, perform VS build and when I check the docker logs, I get the same file access error:


 C:\Program Files\dotnet\sdk\6.0.101\Microsoft.Common.CurrentVersion.targets(5100,5): warning MSB3026: Could not copy "C:\solution\src\Project\MvpSite\rendering\obj\container\Debug\netcoreapp3.1\apphost.exe" to "C:\solution\src\Project\MvpSite\rendering/bin/container/Debug\netcoreapp3.1\Mvp.Project.MvpSite.exe". Beginning retry 8 in 1000ms. The process cannot access the file 'C:\solution\src\Project\MvpSite\rendering\bin\container\Debug\netcoreapp3.1\Mvp.Project.MvpSite.exe' because it is being used by another process.  [C:\solution\src\Project\MvpSite\rendering\Mvp.Project.MvpSite.Rendering.csproj]

Since this is a file access issue, I stopped the mvp-rendering Docker container from Docker desktop,  


Wait until the mvp-rendering container is greyed out, when the mvp-rendering container stops, the PS window that runs the log, returns the prompt automatically!

Next, build the Mvp.Project.MvpSite.Rendering.csproj then start the mvp-rendering container,



Check the site after starting the logs in the PS window, everything looks good:

Always wait until the logs return a 200 response for the site to be available:



Comments

Popular Posts