service-fabric icon indicating copy to clipboard operation
service-fabric copied to clipboard

Environment variable replacement using tokens like VSTS\Powershell

Open guibirow opened this issue 7 years ago • 1 comments

I've mentioned it on this issue microsoft/service-fabric-issues#776, but I am opening it as a formal feature request.

I have faced some challenges where I needed to pass environment variables to guest executable or containers, and in most cases, these values were already defined in the host machine.

An example I can give is a Guest Executable, with closed source, that expect a Environment Variable called PORT to be set, so it knows which port to open at startup.

Would not be a problem for fixed ports, like 80, 8080, and so on, but in cases we use dynamic ports provided by service fabric, we would have to create a custom startup script to set these variables.

Instead of executing from a batch file, a rough example is something like this:

In your ServiceManifest.xml:

  <CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <ExeHost>
        <Program>start.bat</Program>
        <WorkingFolder>CodePackage</WorkingFolder>
      </ExeHost>
    </EntryPoint>
  </CodePackage>

On the same folder (code) of your node.exe, you create the start.bat file with following contents:

set PORT=%Fabric_Endpoint_GuestEndpoint%
node start.js

Would be very easy if we could do just this from the manifest:

<EnvironmentOverrides CodePackageRef="Code">
  <EnvironmentVariable Name="PORT" Value="$Env:Fabric_Endpoint_GuestEndpoint" />
</EnvironmentOverrides>

guibirow avatar Jun 27 '18 17:06 guibirow

Common examples I can give is passing connection strings, passwords and other settings already set on environment variables defined in the host, instead of requesting these parameters at deployment or configuration files.

guibirow avatar Jun 29 '18 09:06 guibirow