microsoft / microsoft/aspire

how to support python azure function developers with builder.AddDockerfile()

Open
#9,426 10 comments 0 reactions 0 assignees View on GitHub
area-integrations azure-functions internal-customer-impact
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

i have a hybrid functions dev loop scenario not currently supported as per required
* containerized python cosmos db (emulator) trigger function
* python durable function that needs to write to blob storage emulator
* blazor web app that needs to read what python durable function wrote to blob storage (emulator)
* containerized c# isolated model durable function that needs to share cosmos db emulator with python cosmosdb (emulator) trigger

one cannot use the builder.AddAzureCosmosDB("cosmos-db").RunAsPreviewEmulator() api to share the cosmos emulator among the resources listed above, because the network bridge doesn't seem to appropriately include azure functions builder.AddDockerfile() scenarios

the same respectively applies for using storage emulator aspire api integration to power python functions and c# functions from the same storage emulator

to be clear the issue is that the functions containers each see a different localhost:8081, localhost:10000 etc

the workaround is externally start the associated emulators and inject the host ip into the target environments

a cross cutting concern here is that by using the external emulators one loses the ability to use the associated IResourceBuilder apis such as builder.AddAzureCosmosDB("cosmos-db").AddMoreStuff() to configure assets in the externally running emulators (UNLESS I'M MISSING SOMETHING IN THE DOCS)

### Describe the solution you'd like

what am i saying here as far as i can tell
* azure python function containerized function apps do not seem to be able to reference the storage emulator resource on the default aspire bridge
* aspire environment variables are not injected into orchestrated Dockerfile resources

wouldn't it be nice

### Additional context

python dockerfile resource visible os environment showing inject ip address in AzureWebjobsStorage and no ASPIRE* environment

```
environ({'ASPNET_VERSION': '6.0.36', 'ConnectionStrings__CosmosGlobalLockEndpoint': 'AccountEndpoint=http://cosmos-db:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;Database=LockDB;IgnoreEndpointCertificate=true;DisableServerCertificateValidation=true', 'DOTNET_RUNNING_IN_CONTAINER': 'true', 'FUNCTIONS_WORKER_RUNTIME_VERSION': '3.11', 'ASPNETCORE_URLS': 'http://+:80', 'AzureFunctionsJobHost__Logging__Console__IsEnabled': 'true', 'EMULATOR_ENDPOINT': 'AccountEndpoint=http://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;Database=LockDB;IgnoreEndpointCertificate=true;DisableServerCertificateValidation=true', 'ACCEPT_EULA': 'Y', 'AzureWebJobsStorage': 'DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://192.168.10.123:10000/devstoreaccount1;QueueEndpoint=http://192.168.10.123:10001/devstoreaccount1;TableEndpoint=http://192.168.10.123:10002/devstoreaccount1;', 'ASPNETCORE_CONTENTROOT': '/azure-functions-host', 'HOSTNAME': '45a7338aa998', 'DOTNET_USE_POLLING_FILE_WATCHER': 'true', 'SHLVL': '1', 'HOST_VERSION': '4.1038.400.10', 'LANG': 'C.UTF-8', 'ConnectionStrings__cosmos-db': 'AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;AccountEndpoint=http://cosmos-db:8081', 'PATH': '/home/sechele/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', '_': '/azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost', 'ConnectionStrings__blobs': 'DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://lockstorage:10000/devstoreaccount1;', 'HOME': '/home', 'AzureWebJobsScriptRoot': '/home/site/wwwroot', 'host__localHttpPort': '7072', 'CosmosGlobalLockEndpoint': 'AccountEndpoint=http://cosmos-db:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;Database=LockDB;IgnoreEndpointCertificate=true;DisableServerCertificateValidation=true', 'DOTNET_VERSION': '6.0.36', 'FUNCTIONS_WORKER_RUNTIME': 'python', 'ConnectionStrings__LockDB': 'AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;AccountEndpoint=http://cosmos-db:8081;Database=LockDB', 'PWD': '/', 'FUNCTIONS_WORKER_DIRECTORY': '/azure-functions-host/workers/python', 'FUNCTIONS_APPLICATION_DIRECTORY': '/home/site/wwwroot', 'PYTHON_THREADPOOL_THREAD_COUNT': '1000', 'PYTHONPATH': '/home/site/wwwroot/.python_packages/lib/site-packages:/azure-functions-host/workers/python/3.11/LINUX/X64'})
info: Function.timer_trigger.User[0]
Timer triggered: batch_paused_or_complete
```

python functions dockerfile setup
```
// After adding all resources, run the app...
var container = builder.AddDockerfile("python-funcs", "../HorselessDistributedLocking.Sample.AzureFunctions.PythonOrchestrations", "Dockerfile")
.WithReference(cosmos)
.WithReference(locksDb)
.WithReference(blobStorage)
.WithEnvironment("CosmosGlobalLockEndpoint", $"AccountEndpoint=http://cosmos-db:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;Database=LockDB;IgnoreEndpointCertificate=true;DisableServerCertificateValidation=true")
.WithEnvironment("ConnectionStrings__CosmosGlobalLockEndpoint", $"AccountEndpoint=http://cosmos-db:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;Database=LockDB;IgnoreEndpointCertificate=true;DisableServerCertificateValidation=true")
.WithEnvironment("EMULATOR_ENDPOINT", cosmosConnectionString)
.WithEnvironment("AzureWebJobsStorage", $"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://{ipAdd.ToString()}:10000/devstoreaccount1;QueueEndpoint=http://{ipAdd.ToString()}:10001/devstoreaccount1;TableEndpoint=http://{ipAdd.ToString()}:10002/devstoreaccount1;")
.WaitFor(cosmos)
.WaitFor(blobStorage)
.WithReference(locksDb);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.