diff --git a/agent/updater.go b/agent/updater.go index d207876f3..67afee5a6 100644 --- a/agent/updater.go +++ b/agent/updater.go @@ -42,8 +42,9 @@ func NewClientUpdater(client client.Client) UpdateFunc { } } -func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.WriteCloser) LoggerFunc { +func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.WriteCloser, limit int64) LoggerFunc { var once sync.Once + var size int64 return func(line *build.Line) { // annoying hack to only start streaming once the first line is written once.Do(func() { @@ -55,8 +56,14 @@ func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.Wri }() }) + if size > limit { + return + } + linejson, _ := json.Marshal(line) wc.Write(linejson) wc.Write([]byte{'\n'}) + + size += int64(len(line.Out)) } } diff --git a/drone/agent/agent.go b/drone/agent/agent.go index 904283a33..5481ea358 100644 --- a/drone/agent/agent.go +++ b/drone/agent/agent.go @@ -86,6 +86,18 @@ var AgentCmd = cli.Command{ Name: "debug", Usage: "start the agent in debug mode", }, + cli.DurationFlag{ + EnvVar: "DRONE_TIMEOUT", + Name: "timeout", + Usage: "drone timeout due to log inactivity", + Value: time.Minute * 5, + }, + cli.IntFlag{ + EnvVar: "DRONE_MAX_LOGS", + Name: "max-log-size", + Usage: "drone maximum log size in megabytes", + Value: 5, + }, cli.StringSliceFlag{ EnvVar: "DRONE_PLUGIN_PRIVILEGED", Name: "privileged", @@ -157,9 +169,11 @@ func start(c *cli.Context) { drone: client, docker: docker, config: config{ + timeout: c.Duration("timeout"), namespace: c.String("namespace"), privileged: c.StringSlice("privileged"), pull: c.Bool("pull"), + logs: int64(c.Int("max-log-size")) * 1000000, }, } for { diff --git a/drone/agent/exec.go b/drone/agent/exec.go index 42b54cc97..d514c073f 100644 --- a/drone/agent/exec.go +++ b/drone/agent/exec.go @@ -17,6 +17,8 @@ type config struct { namespace string privileged []string pull bool + logs int64 + timeout time.Duration } type pipeline struct { @@ -46,10 +48,10 @@ func (r *pipeline) run() error { a := agent.Agent{ Update: agent.NewClientUpdater(r.drone), - Logger: agent.NewClientLogger(r.drone, w.Job.ID, rc, wc), + Logger: agent.NewClientLogger(r.drone, w.Job.ID, rc, wc, r.config.logs), Engine: engine, - Timeout: time.Minute * 15, - Platform: r.config.platform, + Timeout: r.config.timeout, + Platform: "linux/amd64", Namespace: r.config.namespace, Escalate: r.config.privileged, Pull: r.config.pull,