mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
remote agent now working and tested
This commit is contained in:
parent
7aedd78015
commit
e09f02db9e
5 changed files with 28 additions and 19 deletions
|
@ -59,7 +59,7 @@
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<pre id="term" ng-if="task && task.state !== 'pending'">{{ logs }}</pre>
|
<pre id="term"></pre>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,14 @@ func (u *updater) SetCommit(user *common.User, r *common.Repo, c *common.Commit)
|
||||||
// log err
|
// 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)
|
msg, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -59,6 +67,14 @@ func (u *updater) SetBuild(r *common.Repo, c *common.Commit, b *common.Build) er
|
||||||
return err
|
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)
|
msg, err := json.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -50,6 +51,7 @@ func GetRepoEvents(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStream(c *gin.Context) {
|
func GetStream(c *gin.Context) {
|
||||||
|
conf := ToSettings(c)
|
||||||
store := ToDatastore(c)
|
store := ToDatastore(c)
|
||||||
repo := ToRepo(c)
|
repo := ToRepo(c)
|
||||||
runner := ToRunner(c)
|
runner := ToRunner(c)
|
||||||
|
@ -71,12 +73,17 @@ func GetStream(c *gin.Context) {
|
||||||
|
|
||||||
var rc io.ReadCloser
|
var rc io.ReadCloser
|
||||||
|
|
||||||
addr, err := store.Agent(commit)
|
|
||||||
// if the commit is being executed by an agent
|
// if the commit is being executed by an agent
|
||||||
// we'll proxy the build output directly to the
|
// we'll proxy the build output directly to the
|
||||||
// remote Docker client, through the agent.
|
// remote Docker client, through the agent.
|
||||||
if err == nil {
|
if conf.Agents != nil && conf.Agents.Secret != "" {
|
||||||
resp, err := http.Get("http://" + addr)
|
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 {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.Fail(500, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewAgentstore(db *sql.DB) *Agentstore {
|
||||||
|
|
||||||
// Agent returns an agent by ID.
|
// Agent returns an agent by ID.
|
||||||
func (db *Agentstore) Agent(commit *common.Commit) (string, error) {
|
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)
|
var err = meddler.QueryRow(db, agent, rebind(agentQuery), commit.ID)
|
||||||
return agent.Addr, err
|
return agent.Addr, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"`
|
|
||||||
}
|
|
Loading…
Reference in a new issue