man-group / dapr-sidekick-dotnet

Dapr Sidekick for .NET - a lightweight lifetime management component for Dapr
Apache License 2.0
175 stars 21 forks source link

Secret store local file, relative file pathing #58

Open joelsteventurner opened 1 year ago

joelsteventurner commented 1 year ago

In the Dapr Secret store local file examples they tend to use relative file paths to the secrets file, which doesn't seem to work when using SideKick. I keep getting a fatal error , can't find secrets file.

I suspect the fix for this would be to make the working directory for the application consuming the yaml files based on the application you are building rather than the Dapr infrastructure directories.

Any suggestions?

IliasP91 commented 11 months ago

Okay I have a little update. I managed to write a working solution using the existing released version of sidekick.

If you notice i build a new file path for the daprd.exe and set CopyProcessFile to true The reason is that sidekick starts the managed process in the location of the dapr cli installation and sets its working directory to the same directory. For that reason relative paths dont work in components as its not within our project, however if we copy it like this, its located in the correct place so everything works out.

A better solution would be an option to allow us set/override the working directory. I will raise a PR for that but in the short term this works great.

var builder = WebApplication.CreateBuilder(args);
var environment = builder.Environment;
var configuration = builder.Configuration;

// Manage local dapr sidecar
if (environment.IsDevelopment())
{
    var sidecarOptions = new DaprSidecarOptions
    {
        AppId = "my-service",
        AppPort = 5000,
        // Replace the following with ResourcesDirectory = Path.Combine(Environment.ContentRootPath, "Dapr/Components"), on the next release
        ComponentsDirectory = "./Dapr/Components",
        CustomArguments = $"--resources-path {Path.Combine(environment.ContentRootPath, "Dapr/Components")}",

        // Currently there's no option to override the working directory when the managed daprd process starts
        // so we copy it to the project directory to let the local components use relative paths
        ProcessFile = Path.Combine(environment.ContentRootPath, "daprd.exe"),
        CopyProcessFile = true
    };

    // Add Dapr Sidekick hosted service, it will attach and reuse the already started process above
    builder.Services.AddDaprSidekick(
        configuration,
        c =>
        {
            c.Sidecar = sidecarOptions;
        });
}

...etc
IliasP91 commented 11 months ago

relevant PR https://github.com/man-group/dapr-sidekick-dotnet/pull/59