Sitecore / Helix.Examples

Developer-focused examples of implementing the Sitecore Helix practices.
https://sitecore.github.io/Helix.Examples/
Other
81 stars 109 forks source link

dotnet watch in rendering container does not update as another process is locking the *.dll files in question #175

Closed assad-faizi closed 9 months ago

assad-faizi commented 10 months ago

It seems like the dotnet watch command specified in the rendering Dockerfile fails to make the changes to the application due to another process locking the dll that is trying to be updated.

Steps to reproduce

  1. Clone the Sitecore Helix.Examples repo.
  2. Open examples/helix-basic-aspnetcore/BasicCompany solution
  3. run init.ps1
  4. run up.ps1
  5. browse to https://www.basic-company-aspnetcore.localhost/ - ensure home page is visible
  6. Make a change to src/Project/BaseCompany/rendering/Views/Default/Index.cshtml i.e. add <h1>Hello World<h2> below header placeholder (Performed this in VS Code)
  7. Click Save

Expected Behaviour

Actual Behaviour

I came across this thread which suggests the issue is with the nanoserver base images which is lacking the taskkill tool required by dotnet watch. The only workaround is to create custom SDK image based on servercore.

given that the dotnet watch tool is used in the Sitecore examples project I'm wondering how did this work?

nickwesselman commented 9 months ago

I don't think Sitecore maintains this repo anymore. But this issue you are seeing is related to an issue with Docker on Windows and file locks --

https://github.com/moby/moby/issues/42803

assad-faizi commented 9 months ago

Thanks @nickwesselman . I suspected this wasn't actively maintained given there are open issues dating back 4 years ago. I've decided to go down another route.

What I've discovered is that it seems like the dotnet watch works fine with .NET 6 in a windows container when I create a "Hello World" containerised (Windows) console app.

I then further discovered there is a Visual Studio Template called Sitecore Simple Container-based ASP.NET Core Solution (Sitecore) developed by Sitecore which is already .NET 6 and uses dotnet watch

image

It works (ish) - the rendering container spins up successfully. I'm having issues with the sitecore instances not returning as healthy containers:

image

Going to explorer this a bit and will update here.

assad-faizi commented 9 months ago

For those interested in using the Sitecore Simple Container-based ASP.NET Core Solution (Sitecore) Visual Studio Template and experience the same error above, I discovered the root cause. It's to do with the SQL_SA_PASSWORD that is generated in the .env file. When you run .\init -InitEv which initialises the .env file, the SQL password generated doesn't appear to be complex enough (see https://navansitecorenotes.blogspot.com/2020/12/is-docker-compose-up-sensitive-to.html). If you manually set the SQL_SA_PASSWORD to something like PAssw0rd123$, it will work. Or you could modify the init.ps1 from this:

Set-EnvFileVariable "SQL_SA_PASSWORD" -Value (Get-SitecoreRandomString 19 -DisallowSpecial -EnforceComplexity)

to this:

$SqlSaPassword = (Get-SitecoreRandomString 19 -DisallowSpecial -EnforceComplexity) + "$"
Set-EnvFileVariable "SQL_SA_PASSWORD" -Value $SqlSaPassword

Bit of a hack but it works. It seems there needs to be at least one special character. Removing the -DisallowSpecial switch param isn't reliable as it could use a character that isn't supported.

assad-faizi commented 9 months ago

BTW, when using the Sitecore Simple Container-based ASP.NET Core Solution (Sitecore) Visual Studio Template, the dotnet watch works successfully.