mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 04:10:32 +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"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
"github.com/cncd/pipeline/pipeline"
|
"github.com/cncd/pipeline/pipeline"
|
||||||
"github.com/cncd/pipeline/pipeline/backend"
|
"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 pass version information to grpc server
|
||||||
// TODO authenticate to grpc server
|
// TODO authenticate to grpc server
|
||||||
|
|
||||||
|
@ -44,6 +51,7 @@ func loop(c *cli.Context) error {
|
||||||
password: c.String("password"),
|
password: c.String("password"),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -52,7 +60,10 @@ func loop(c *cli.Context) error {
|
||||||
client := rpc.NewGrpcClient(conn)
|
client := rpc.NewGrpcClient(conn)
|
||||||
|
|
||||||
sigterm := abool.New()
|
sigterm := abool.New()
|
||||||
ctx := context.Background()
|
ctx := metadata.NewOutgoingContext(
|
||||||
|
context.Background(),
|
||||||
|
metadata.Pairs("hostname", hostname),
|
||||||
|
)
|
||||||
ctx = interrupt.WithContextFunc(ctx, func() {
|
ctx = interrupt.WithContextFunc(ctx, func() {
|
||||||
println("ctrl+c received, terminating process")
|
println("ctrl+c received, terminating process")
|
||||||
sigterm.Set()
|
sigterm.Set()
|
||||||
|
|
|
@ -39,6 +39,10 @@ func main() {
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
Usage: "start the agent in debug mode",
|
Usage: "start the agent in debug mode",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
EnvVar: "DRONE_HOSTNAME,HOSTNAME",
|
||||||
|
Name: "hostname",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
EnvVar: "DRONE_PLATFORM",
|
EnvVar: "DRONE_PLATFORM",
|
||||||
Name: "platform",
|
Name: "platform",
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
|
|
||||||
oldcontext "golang.org/x/net/context"
|
oldcontext "golang.org/x/net/context"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/cncd/logging"
|
"github.com/cncd/logging"
|
||||||
"github.com/cncd/pipeline/pipeline/rpc"
|
"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
|
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" {
|
if file.Mime == "application/json+logs" {
|
||||||
return s.store.LogSave(
|
return s.store.LogSave(
|
||||||
proc,
|
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)
|
log.Printf("error: cannot find proc with id %d: %s", procID, err)
|
||||||
return 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)
|
build, err := s.store.GetBuild(proc.BuildID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue