Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using WithEnvironment after dapr doesn't work #1553

Closed
bit365 opened this issue Jan 5, 2024 · 2 comments · Fixed by #1604
Closed

Using WithEnvironment after dapr doesn't work #1553

bit365 opened this issue Jan 5, 2024 · 2 comments · Fixed by #1604
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication dapr

Comments

@bit365
Copy link

bit365 commented Jan 5, 2024

I need to reference an environment variable in Dapr's component configuration file, but after using the following code, I cannot get the variable in the dapr sidecar.

var apiServiceSidecar = builder.AddProject<Projects.AspireApp_ApiService>("apiservice")
    .WithDaprSidecar(new DaprSidecarOptions
    {
        AppId = "apiservice",
        DaprGrpcPort = 50001,
        DaprHttpPort = 3500,
        ResourcesPaths = ["./components"],
    }).WithEnvironment("testtesttesttesttesttesttest", "testvalue");

For example, the secretstores.local.env component in dapr obtains values ​​from environment variables.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: env-secret-store
spec:
  type: secretstores.local.env
  version: v1
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: mqtt-pubsub
spec:
  type: pubsub.mqtt3
  version: v1
  metadata:
    - name: url
      secretKeyRef:
        name: testtesttesttesttesttesttest
auth:
  secretStore: env-secret-store

Unable to extract value from testtesttesttesttesttesttest

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 5, 2024
@philliphoff
Copy link
Contributor

philliphoff commented Jan 5, 2024

The WithEnvironment() applies to the project resource and not the sidecar. That is, WithEnvironment() returns the original project resource builder; the sidecar is not a resource in its own right. My first thought is that the DaprSidecarOptions should have an Environment property on which to set sidecar-specific variables. This would be similar to how Dapr run files work.

An argument could be made that the sidecar should itself be a resource that is simply referenced by the project resource, in which case it could then use common resource annotations (such as WithEnvironment()). It wasn't modeled that way originally because of the tight 1:1 relationship between a sidecar and a project. If it were a resource, the sidecar could end up referenced by multiple resources, which would be semantically invalid.

@GFlisch
Copy link

GFlisch commented Jan 6, 2024

We need to have this functionality and I agree having the SideCar has a resource will be more consistent. The reason why environment must be supported is to support the https://docs.dapr.io/reference/components-reference/supported-secret-stores/envvar-secret-store/ scenario.

@davidfowl davidfowl added dapr and removed untriaged labels Jan 6, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication dapr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants