From e09f02db9e40c46e7db12d0e318d473add0ec756 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 18 May 2015 21:53:34 -0700 Subject: [PATCH] remote agent now working and tested --- cmd/drone-server/static/scripts/views/build.html | 2 +- pkg/runner/builtin/updater.go | 16 ++++++++++++++++ pkg/server/ws.go | 13 ++++++++++--- pkg/store/builtin/agent.go | 2 +- pkg/types/agent.go | 14 -------------- 5 files changed, 28 insertions(+), 19 deletions(-) delete mode 100644 pkg/types/agent.go diff --git a/cmd/drone-server/static/scripts/views/build.html b/cmd/drone-server/static/scripts/views/build.html index c22adda6..ba235066 100644 --- a/cmd/drone-server/static/scripts/views/build.html +++ b/cmd/drone-server/static/scripts/views/build.html @@ -59,7 +59,7 @@
-
{{ logs }}
+

 			
diff --git a/pkg/runner/builtin/updater.go b/pkg/runner/builtin/updater.go index e7f2ba4e..639cdd0a 100644 --- a/pkg/runner/builtin/updater.go +++ b/pkg/runner/builtin/updater.go @@ -40,6 +40,14 @@ func (u *updater) SetCommit(user *common.User, r *common.Repo, c *common.Commit) // log err } + // we need this because builds coming from + // a remote agent won't have the embedded + // build list. we should probably just rethink + // the messaging instead of this hack. + if c.Builds == nil || len(c.Builds) == 0 { + c.Builds, _ = u.store.BuildList(c) + } + msg, err := json.Marshal(c) if err != nil { return err @@ -59,6 +67,14 @@ func (u *updater) SetBuild(r *common.Repo, c *common.Commit, b *common.Build) er return err } + // we need this because builds coming from + // a remote agent won't have the embedded + // build list. we should probably just rethink + // the messaging instead of this hack. + if c.Builds == nil || len(c.Builds) == 0 { + c.Builds, _ = u.store.BuildList(c) + } + msg, err := json.Marshal(c) if err != nil { return err diff --git a/pkg/server/ws.go b/pkg/server/ws.go index 08b4ec86..14e1eae2 100644 --- a/pkg/server/ws.go +++ b/pkg/server/ws.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "io" "net/http" "strconv" @@ -50,6 +51,7 @@ func GetRepoEvents(c *gin.Context) { } func GetStream(c *gin.Context) { + conf := ToSettings(c) store := ToDatastore(c) repo := ToRepo(c) runner := ToRunner(c) @@ -71,12 +73,17 @@ func GetStream(c *gin.Context) { var rc io.ReadCloser - addr, err := store.Agent(commit) // if the commit is being executed by an agent // we'll proxy the build output directly to the // remote Docker client, through the agent. - if err == nil { - resp, err := http.Get("http://" + addr) + if conf.Agents != nil && conf.Agents.Secret != "" { + addr, err := store.Agent(commit) + if err != nil { + c.Fail(500, err) + return + } + url := fmt.Sprintf("http://%s/stream/%d?token=%s", addr, build.ID, conf.Agents.Secret) + resp, err := http.Get(url) if err != nil { c.Fail(500, err) return diff --git a/pkg/store/builtin/agent.go b/pkg/store/builtin/agent.go index 946a640f..202fecf6 100644 --- a/pkg/store/builtin/agent.go +++ b/pkg/store/builtin/agent.go @@ -17,7 +17,7 @@ func NewAgentstore(db *sql.DB) *Agentstore { // Agent returns an agent by ID. func (db *Agentstore) Agent(commit *common.Commit) (string, error) { - var agent = new(common.Agent) + var agent = new(agent) var err = meddler.QueryRow(db, agent, rebind(agentQuery), commit.ID) return agent.Addr, err } diff --git a/pkg/types/agent.go b/pkg/types/agent.go deleted file mode 100644 index 7fd87147..00000000 --- a/pkg/types/agent.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -// Agent represents a worker that has connected -// to the system in order to perform work -type Agent struct { - ID int64 `meddler:"agent_id,pk" json:"id,omitempty"` - Kind string `meddler:"agent_kind" json:"kind,omitempty"` - Addr string `meddler:"agent_addr" json:"address"` - Token string `meddler:"agent_token" json:"token"` - Cert string `meddler:"agent_cert" json:"-"` - Key string `meddler:"agent_key" json:"-"` - Active bool `meddler:"agent_active" json:"is_active"` - IsHealthy bool `meddler:"-" json:"is_healthy,omitempty"` -}