Skip to content

Commit

Permalink
cleanup env vars (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored Sep 17, 2023
1 parent d94e60b commit c536d76
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Runner.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ private static async Task<int> CreateExternalRunner(string binpath, Parameters p
var code = await inv.ExecuteAsync(tmpdir, file, arguments, runnerEnv, true, null, true, CancellationTokenSource.CreateLinkedTokenSource(source.Token, new CancellationTokenSource(60 * 1000).Token).Token);
int execAttempt = 1;
var success = false;
// unset RUNNER_SERVER_CONFIG_ROOT to not appear in jobs created by external runners
runnerEnv.Remove("RUNNER_SERVER_CONFIG_ROOT");
while(true) {
file = runner;
try {
Expand Down
5 changes: 4 additions & 1 deletion src/Runner.Common/HostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public sealed class HostContext : EventListener, IObserver<DiagnosticListener>,
private StartupType _startupType;
private string _perfFile;
private RunnerWebProxy _webProxy = new RunnerWebProxy();
private string configRoot = null;

public event EventHandler Unloading;
public CancellationToken RunnerShutdownToken => _runnerShutdownTokenSource.Token;
Expand All @@ -78,6 +79,8 @@ public HostContext(string hostType, string logFile = null)
// Validate args.
ArgUtil.NotNullOrEmpty(hostType, nameof(hostType));

configRoot = Environment.GetEnvironmentVariable("RUNNER_SERVER_CONFIG_ROOT");

_loadContext = AssemblyLoadContext.GetLoadContext(typeof(HostContext).GetTypeInfo().Assembly);
_loadContext.Unloading += LoadContext_Unloading;

Expand Down Expand Up @@ -265,7 +268,7 @@ public string GetDirectory(WellKnownDirectory directory)
break;

case WellKnownDirectory.ConfigRoot:
path = Environment.GetEnvironmentVariable("RUNNER_SERVER_CONFIG_ROOT") ?? GetDirectory(WellKnownDirectory.Root);
path = configRoot ?? GetDirectory(WellKnownDirectory.Root);
break;

case WellKnownDirectory.Temp:
Expand Down
3 changes: 3 additions & 0 deletions src/Runner.Listener/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public static int Main(string[] args)
Console.WriteLine($"Failed to change Process Group exception");
}
}
// Delete the environment variable, otherwise it is defined inside the job
System.Environment.SetEnvironmentVariable("GHARUN_CHANGE_PROCESS_GROUP", null);

// Add environment variables from .env file
LoadAndSetEnv();

Expand Down
5 changes: 2 additions & 3 deletions src/Runner.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public static void Main(string[] args)
Console.WriteLine($"Failed to change Process Group exception");
}
}
//var b = new ConfigurationBuilder();
//b.AddJsonFile("C:\\Users\\Christopher\\runner\\src\\Runner.Server\\appsettings.Development.json");
//new MessageController(/* new Logger<MessageController>(new LoggerFactory()) */b.Build(), new MemoryCache(new Options())).ConvertYaml("C:/Users/Christopher/runner/src/Runner.Server/test.yml");
// Delete the environment variable, otherwise it is defined inside the job
System.Environment.SetEnvironmentVariable("GHARUN_CHANGE_PROCESS_GROUP", null);
CreateHostBuilder(args).Build().Run();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Runner.Worker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static int Main(string[] args)
{
using (HostContext context = new HostContext("Worker"))
{
// Delete the environment variable, otherwise it is defined inside the job
Environment.SetEnvironmentVariable("RUNNER_SERVER_CONFIG_ROOT", null);
return MainAsync(context, args).GetAwaiter().GetResult();
}
}
Expand Down

0 comments on commit c536d76

Please sign in to comment.