Refactor environment variables to configuration and registration (#90)

Close #21.

Refactor environment variables to configuration file (config.yaml) and registration file (.runner).

The old environment variables are still supported, but warning logs will be printed.

Like:

```text
$ GITEA_DEBUG=true ./act_runner -c config.yaml daemon
INFO[0000] Starting runner daemon
WARN[0000] env GITEA_DEBUG has been ignored because config file is used

$ GITEA_DEBUG=true ./act_runner daemon
INFO[0000] Starting runner daemon
WARN[0000] env GITEA_DEBUG will be deprecated, please use config file instead
```

Reviewed-on: https://gitea.com/gitea/act_runner/pulls/90
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Jason Song
2023-04-02 22:41:48 +08:00
parent 8eea12dd78
commit 7e7096e60b
20 changed files with 393 additions and 280 deletions

View File

@ -10,22 +10,23 @@ import (
"time"
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
"gitea.com/gitea/act_runner/client"
"github.com/bufbuild/connect-go"
log "github.com/sirupsen/logrus"
"gitea.com/gitea/act_runner/client"
"gitea.com/gitea/act_runner/config"
)
var ErrDataLock = errors.New("Data Lock Error")
func New(cli client.Client, dispatch func(context.Context, *runnerv1.Task) error, workerNum int) *Poller {
func New(cli client.Client, dispatch func(context.Context, *runnerv1.Task) error, cfg *config.Config) *Poller {
return &Poller{
Client: cli,
Dispatch: dispatch,
routineGroup: newRoutineGroup(),
metric: &metric{},
workerNum: workerNum,
ready: make(chan struct{}, 1),
cfg: cfg,
}
}
@ -37,13 +38,13 @@ type Poller struct {
routineGroup *routineGroup
metric *metric
ready chan struct{}
workerNum int
cfg *config.Config
}
func (p *Poller) schedule() {
p.Lock()
defer p.Unlock()
if int(p.metric.BusyWorkers()) >= p.workerNum {
if int(p.metric.BusyWorkers()) >= p.cfg.Runner.Capacity {
return
}
@ -151,7 +152,7 @@ func (p *Poller) dispatchTask(ctx context.Context, task *runnerv1.Task) error {
}
}()
runCtx, cancel := context.WithTimeout(ctx, time.Hour)
runCtx, cancel := context.WithTimeout(ctx, p.cfg.Runner.Timeout)
defer cancel()
return p.Dispatch(runCtx, task)