mirror of
https://gitea.com/gitea/act_runner.git
synced 2025-06-13 10:07:14 +02:00
chore(proto): Add ping request.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@ -1,12 +1,34 @@
|
||||
package cmd
|
||||
|
||||
import "github.com/kelseyhightower/envconfig"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
type (
|
||||
// Config provides the system configuration.
|
||||
Config struct {
|
||||
Debug bool `envconfig:"GITEA_DEBUG"`
|
||||
Trace bool `envconfig:"GITEA_TRACE"`
|
||||
|
||||
Client struct {
|
||||
Address string `ignored:"true"`
|
||||
Proto string `envconfig:"GITEA_RPC_PROTO" default:"http"`
|
||||
Host string `envconfig:"GITEA_RPC_HOST" required:"true"`
|
||||
Secret string `envconfig:"GITEA_RPC_SECRET" required:"true"`
|
||||
SkipVerify bool `envconfig:"GITEA_RPC_SKIP_VERIFY"`
|
||||
}
|
||||
|
||||
Runner struct {
|
||||
Name string `envconfig:"GITEA_RUNNER_NAME"`
|
||||
Capacity int `envconfig:"GITEA_RUNNER_CAPACITY" default:"2"`
|
||||
Procs int64 `envconfig:"GITEA_RUNNER_MAX_PROCS"`
|
||||
Environ map[string]string `envconfig:"GITEA_RUNNER_ENVIRON"`
|
||||
EnvFile string `envconfig:"GITEA_RUNNER_ENV_FILE"`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@ -14,5 +36,30 @@ type (
|
||||
func fromEnviron() (Config, error) {
|
||||
cfg := Config{}
|
||||
err := envconfig.Process("", &cfg)
|
||||
|
||||
// runner config
|
||||
if cfg.Runner.Environ == nil {
|
||||
cfg.Runner.Environ = map[string]string{}
|
||||
}
|
||||
if cfg.Runner.Name == "" {
|
||||
cfg.Runner.Name, _ = os.Hostname()
|
||||
}
|
||||
|
||||
cfg.Client.Address = fmt.Sprintf(
|
||||
"%s://%s",
|
||||
cfg.Client.Proto,
|
||||
cfg.Client.Host,
|
||||
)
|
||||
|
||||
if file := cfg.Runner.EnvFile; file != "" {
|
||||
envs, err := godotenv.Read(file)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
for k, v := range envs {
|
||||
cfg.Runner.Environ[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return cfg, err
|
||||
}
|
||||
|
29
cmd/damon.go
29
cmd/damon.go
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.com/gitea/act_runner/client"
|
||||
"gitea.com/gitea/act_runner/engine"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
@ -164,7 +165,33 @@ func runDaemon(ctx context.Context, input *Input) func(cmd *cobra.Command, args
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
} else {
|
||||
log.Debugln("successfully pinged the docker daemon")
|
||||
log.Infoln("successfully pinged the docker daemon")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
cli := client.New(
|
||||
cfg.Client.Address,
|
||||
cfg.Client.Secret,
|
||||
cfg.Client.SkipVerify,
|
||||
)
|
||||
|
||||
for {
|
||||
err := cli.Ping(ctx, cfg.Runner.Name)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
log.WithError(err).
|
||||
Errorln("cannot ping the remote server")
|
||||
time.Sleep(time.Second)
|
||||
} else {
|
||||
log.Infoln("successfully pinged the remote server")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user