mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-20 08:51:01 +00:00
Merge pull request #2125 from bradrydzewski/master
Pass agent hostname to server and persist
This commit is contained in:
commit
61fa5ff08d
3 changed files with 33 additions and 1 deletions
|
@ -6,11 +6,13 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/cncd/pipeline/pipeline"
|
||||
"github.com/cncd/pipeline/pipeline/backend"
|
||||
|
@ -31,6 +33,11 @@ func loop(c *cli.Context) error {
|
|||
},
|
||||
}
|
||||
|
||||
hostname := c.String("hostname")
|
||||
if len(hostname) == 0 {
|
||||
hostname, _ = os.Hostname()
|
||||
}
|
||||
|
||||
// TODO pass version information to grpc server
|
||||
// TODO authenticate to grpc server
|
||||
|
||||
|
@ -44,6 +51,7 @@ func loop(c *cli.Context) error {
|
|||
password: c.String("password"),
|
||||
}),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -52,7 +60,10 @@ func loop(c *cli.Context) error {
|
|||
client := rpc.NewGrpcClient(conn)
|
||||
|
||||
sigterm := abool.New()
|
||||
ctx := context.Background()
|
||||
ctx := metadata.NewOutgoingContext(
|
||||
context.Background(),
|
||||
metadata.Pairs("hostname", hostname),
|
||||
)
|
||||
ctx = interrupt.WithContextFunc(ctx, func() {
|
||||
println("ctrl+c received, terminating process")
|
||||
sigterm.Set()
|
||||
|
|
|
@ -39,6 +39,10 @@ func main() {
|
|||
Name: "debug",
|
||||
Usage: "start the agent in debug mode",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "DRONE_HOSTNAME,HOSTNAME",
|
||||
Name: "hostname",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "DRONE_PLATFORM",
|
||||
Name: "platform",
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
|
||||
oldcontext "golang.org/x/net/context"
|
||||
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/cncd/logging"
|
||||
"github.com/cncd/pipeline/pipeline/rpc"
|
||||
|
@ -207,6 +209,14 @@ func (s *RPC) Upload(c context.Context, id string, file *rpc.File) error {
|
|||
return err
|
||||
}
|
||||
|
||||
metadata, ok := metadata.FromContext(c)
|
||||
if ok {
|
||||
hostname, ok := metadata["hostname"]
|
||||
if ok && len(hostname) != 0 {
|
||||
proc.Machine = hostname[0]
|
||||
}
|
||||
}
|
||||
|
||||
if file.Mime == "application/json+logs" {
|
||||
return s.store.LogSave(
|
||||
proc,
|
||||
|
@ -238,6 +248,13 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
|
|||
log.Printf("error: cannot find proc with id %d: %s", procID, err)
|
||||
return err
|
||||
}
|
||||
metadata, ok := metadata.FromContext(c)
|
||||
if ok {
|
||||
hostname, ok := metadata["hostname"]
|
||||
if ok && len(hostname) != 0 {
|
||||
proc.Machine = hostname[0]
|
||||
}
|
||||
}
|
||||
|
||||
build, err := s.store.GetBuild(proc.BuildID)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue