You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-06-03 16:35:37 +02:00
Support one-shot agent execution mode (#6150)
This supports the use case of having the agent itself be ephemeral, which may be useful in various situations, including use of the local backend. Co-authored-by: Max Anurin <theanurin@gmail.com> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
+26
-6
@@ -90,7 +90,14 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
||||
hostname, _ = os.Hostname()
|
||||
}
|
||||
|
||||
counter.Polling = c.Int("max-workflows")
|
||||
maxWorkflows := c.Int("max-workflows")
|
||||
singleWorkflow := c.Bool("single-workflow")
|
||||
if singleWorkflow && maxWorkflows > 1 {
|
||||
log.Warn().Msgf("max-workflows forced from %d to 1 due to agent running single workflow mode.", maxWorkflows)
|
||||
maxWorkflows = 1
|
||||
}
|
||||
|
||||
counter.Polling = maxWorkflows
|
||||
counter.Running = 0
|
||||
|
||||
if c.Bool("healthcheck") {
|
||||
@@ -201,8 +208,6 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
||||
}
|
||||
log.Debug().Msgf("loaded %s backend engine", backendEngine.Name())
|
||||
|
||||
maxWorkflows := c.Int("max-workflows")
|
||||
|
||||
customLabels := make(map[string]string)
|
||||
if err := stringSliceAddToMap(c.StringSlice("labels"), customLabels); err != nil {
|
||||
return err
|
||||
@@ -298,6 +303,11 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
||||
|
||||
log.Debug().Msg("polling new workflow")
|
||||
if err := runner.Run(agentCtx, shutdownCtx); err != nil {
|
||||
if singleWorkflow {
|
||||
log.Error().Err(err).Msg("runner done with error")
|
||||
ctxCancel(nil)
|
||||
return nil
|
||||
}
|
||||
log.Error().Err(err).Msg("runner error, retrying...")
|
||||
// Check if context is canceled
|
||||
if agentCtx.Err() != nil {
|
||||
@@ -311,13 +321,23 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
||||
// Continue to next iteration
|
||||
}
|
||||
}
|
||||
|
||||
if singleWorkflow {
|
||||
log.Info().Msg("shutdown single workflow runner")
|
||||
ctxCancel(nil)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
log.Info().Msgf(
|
||||
"starting Woodpecker agent with version '%s' and backend '%s' using platform '%s' running up to %d pipelines in parallel",
|
||||
version.String(), backendEngine.Name(), engInfo.Platform, maxWorkflows)
|
||||
log.Info().
|
||||
Str("version", version.String()).
|
||||
Str("backend", backendEngine.Name()).
|
||||
Str("platform", engInfo.Platform).
|
||||
Int("parallel workflows", maxWorkflows).
|
||||
Bool("single workflow", singleWorkflow).
|
||||
Msg("starting Woodpecker agent")
|
||||
|
||||
return serviceWaitingGroup.Wait()
|
||||
}
|
||||
|
||||
@@ -77,6 +77,12 @@ var flags = []cli.Flag{
|
||||
Usage: "agent parallel workflows",
|
||||
Value: 1,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_AGENT_SINGLE_WORKFLOW"),
|
||||
Name: "single-workflow",
|
||||
Usage: "exit the agent after first workflow",
|
||||
Value: false,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_HEALTHCHECK"),
|
||||
Name: "healthcheck",
|
||||
|
||||
Reference in New Issue
Block a user