Azure / Azure/azure-functions-host
Provide a way to disable FileSystemWatcher to make docker images work on Apple M1
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
#### What problem would the feature you're requesting solve? Please describe.
Linux Amd64 images running on Apple M1 (ARM64) do not support file system watching due to limitations of the emulator.
This makes it impossible to run any function apps on M1 right now, and I literally have to find Intel based Mac for this.
* `mcr.microsoft.com/azure-functions` docker images only have AMD64 images, no ARM64 (see screenshot below)
* There does not seem to be a way to disable file system watcher. Looking at the code it's always enabled except if we run from package and actually configure everything for it correctly.

Here is my Docker file:
```
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish "MyFunction.csproj" --output /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4.0-dotnet-isolated6.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
```
And here is the crash:
```
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
fail: Host.Startup[515]
A host error has occurred during startup operation 'da4bd788-8ccc-46e0-8fe6-d263c1c97ed8'.
System.IO.IOException: Function not implemented
at System.IO.FileSystemWatcher.StartRaisingEvents()
at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()
at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
at Microsoft.Azure.WebJobs.Script.IO.AutoRecoveringFileSystemWatcher.InitializeWatcher() in /src/azure-functions-host/src/WebJobs.Script/IO/AutoRecoveringFileSystemWatcher.cs:line 64
at Microsoft.Azure.WebJobs.Script.IO.AutoRecoveringFileSystemWatcher..ctor(String path, String filter, Boolean includeSubdirectories, WatcherChangeTypes changeTypes, ILoggerFactory loggerFactory) in /src/azure-functions-host/src/WebJobs.Script/IO/AutoRecoveringFileSystemWatcher.cs:line 43
at Microsoft.Azure.WebJobs.Script.WebHost.FileMonitoringService.InitializeSecondaryFileWatchers() in /src/azure-functions-host/src/WebJobs.Script.WebHost/FileMonitoringService.cs:line 192
at Microsoft.Azure.WebJobs.Script.Utility.ExecuteAfterColdStartDelay(IEnvironment environment, Action targetAction, CancellationToken cancellationToken) in /src/azure-functions-host/src/WebJobs.Script/Utility.cs:line 749
at Microsoft.Azure.WebJobs.Script.WebHost.FileMonitoringService.InitializeFileWatchers() in /src/azure-functions-host/src/WebJobs.Script.WebHost/FileMonitoringService.cs:line 172
at Microsoft.Azure.WebJobs.Script.WebHost.FileMonitoringService.StartAsync(CancellationToken cancellationToken) in /src/azure-functions-host/src/WebJobs.Script.WebHost/FileMonitoringService.cs:line 93
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Azure.WebJobs.Script.WebHost.WebJobsScriptHostService.UnsynchronizedStartHostAsync(ScriptHostStartupOperation activeOperation, Int32 attemptCount, JobHostStartupMode startupMode) in /src/azure-functions-host/src/WebJobs.Script.WebHost/WebJobsScriptHostService.cs:line 309
info: Host.Startup[0]
Job host stopped
```
#### Describe the solution you'd like
1. Provide a way to disable file watcher completely via `host.json` and env variable.
2. Proide images for ARM64, e.g either using separate tags or by having a multi-arch images.
#### Describe alternatives you've considered
* The only alternative I see is to buy and Intel based machine, and Apple of course no longer make those :)
Contributor guide
Research direction
Start with WebJobs.Script/IO/AutoRecoveringFileSystemWatcher.cs and WebJobs.Script.WebHost/FileMonitoringService.cs, where the crash trace shows watcher startup. Review the supplied Dockerfile and the host.json and environment-variable configuration paths, then determine how the requested watcher switch and ARM64 or multi-arch image support would be verified. Done means the watcher can be disabled through the requested configuration and the image runs on Apple M1 without this startup failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, docker
- Domain
- backend, devops, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100