Add generateServiceConfig option for configure command (#2226)

For runners that are already configured but need to add systemd services after the fact, a new command option is added to generate the file only. Once generated, ./svc.sh install and other commands will be available.

This also adds support for falling back to the tenant name in the Actions URL in cases when the GitHub URL is not provided, such as for our hosted larger runners.
This commit is contained in:
Cory Miller
2022-10-26 08:48:23 -04:00
committed by GitHub
parent 3fc993da59
commit b18bda773f
5 changed files with 127 additions and 4 deletions

View File

@@ -234,5 +234,103 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
_runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.Is<TaskAgentPoolType>(p => p == TaskAgentPoolType.Automation)), Times.Exactly(1));
}
}
#if OS_LINUX
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "ConfigurationManagement")]
public async Task ConfigureRunnerServiceFailsOnUnconfiguredRunners()
{
using (TestHostContext tc = CreateTestContext())
{
Tracing trace = tc.GetTrace();
trace.Info("Creating config manager");
IConfigurationManager configManager = new ConfigurationManager();
configManager.Initialize(tc);
trace.Info("Preparing command line arguments");
var command = new CommandSettings(
tc,
new[]
{
"configure",
"--generateServiceConfig",
});
trace.Info("Constructed");
_store.Setup(x => x.IsConfigured()).Returns(false);
trace.Info("Ensuring service generation mode fails when on un-configured runners");
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => configManager.ConfigureAsync(command));
Assert.Contains("requires that the runner is already configured", ex.Message);
}
}
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "ConfigurationManagement")]
public async Task ConfigureRunnerServiceCreatesService()
{
using (TestHostContext tc = CreateTestContext())
{
Tracing trace = tc.GetTrace();
trace.Info("Creating config manager");
IConfigurationManager configManager = new ConfigurationManager();
configManager.Initialize(tc);
trace.Info("Preparing command line arguments");
var command = new CommandSettings(
tc,
new[]
{
"configure",
"--generateServiceConfig",
});
trace.Info("Constructed");
_store.Setup(x => x.IsConfigured()).Returns(true);
trace.Info("Ensuring service generation mode fails when on un-configured runners");
await configManager.ConfigureAsync(command);
_serviceControlManager.Verify(x => x.GenerateScripts(It.IsAny<RunnerSettings>()), Times.Once);
}
}
#endif
#if !OS_LINUX
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "ConfigurationManagement")]
public async Task ConfigureRunnerServiceFailsOnUnsupportedPlatforms()
{
using (TestHostContext tc = CreateTestContext())
{
Tracing trace = tc.GetTrace();
trace.Info("Creating config manager");
IConfigurationManager configManager = new ConfigurationManager();
configManager.Initialize(tc);
trace.Info("Preparing command line arguments");
var command = new CommandSettings(
tc,
new[]
{
"configure",
"--generateServiceConfig",
});
trace.Info("Constructed");
_store.Setup(x => x.IsConfigured()).Returns(true);
trace.Info("Ensuring service generation mode fails on unsupported runner platforms");
var ex = await Assert.ThrowsAsync<NotSupportedException>(() => configManager.ConfigureAsync(command));
Assert.Contains("only supported on Linux", ex.Message);
}
}
#endif
}
}