diff --git a/cmd/drone-agent/main.go b/cmd/drone-agent/main.go index ae883d66..7036d0a6 100644 --- a/cmd/drone-agent/main.go +++ b/cmd/drone-agent/main.go @@ -56,7 +56,8 @@ func main() { log.Infof("Pulled and running build %s / %d", w.Repo.FullName, w.Commit.Sequence) - runner_ := runner.Runner{&updater{}} + updater := &updater{} + runner_ := runner.Runner{Updater: updater} err = runner_.Run(w) if err != nil { log.Errorln(err) diff --git a/pkg/store/mock/mock.go b/pkg/store/mock/mock.go index 6493124d..b8ea9329 100644 --- a/pkg/store/mock/mock.go +++ b/pkg/store/mock/mock.go @@ -352,3 +352,18 @@ func (m *Store) DelBlob(path string) error { return r0 } +func (m *Store) Agent(_a0 *common.Commit) (string, error) { + ret := m.Called(_a0) + + r0 := ret.Get(0).(string) + r1 := ret.Error(1) + + return r0, r1 +} +func (m *Store) SetAgent(_a0 *common.Commit, _a1 string) error { + ret := m.Called(_a0, _a1) + + r0 := ret.Error(0) + + return r0 +} diff --git a/pkg/store/plugin/build.go b/pkg/store/plugin/build.go deleted file mode 100644 index f652eb1c..00000000 --- a/pkg/store/plugin/build.go +++ /dev/null @@ -1,121 +0,0 @@ -package plugin - -import ( - "time" - - common "github.com/drone/drone/pkg/types" -) - -type GetBuildReq struct { - Repo string - Build int -} - -type GetBuildResp struct { - Build *common.Build -} - -func (c *Client) GetBuild(repo string, build int) (*common.Build, error) { - req := &GetBuildReq{repo, build} - res := &GetBuildResp{} - err := c.Call("Datastore.GetBuild", req, res) - return res.Build, err -} - -type GetBuildListReq struct { - Repo string -} - -type GetBuildListResp struct { - Builds []*common.Build -} - -func (c *Client) GetBuildList(repo string) ([]*common.Build, error) { - req := &GetBuildListReq{repo} - res := &GetBuildListResp{} - err := c.Call("Datastore.GetBuildList", req, res) - return res.Builds, err -} - -type GetBuildLastReq struct { - Repo string -} - -type GetBuildLastResp struct { - Build *common.Build -} - -func (c *Client) GetBuildLast(repo string) (*common.Build, error) { - req := &GetBuildLastReq{repo} - res := &GetBuildLastResp{} - err := c.Call("Datastore.GetBuildLast", req, res) - return res.Build, err -} - -type GetBuildStatusReq struct { - Repo string - Build int - Status string -} - -type GetBuildStatusResp struct { - Status *common.Status -} - -func (c *Client) GetBuildStatus(repo string, build int, status string) (*common.Status, error) { - req := &GetBuildStatusReq{repo, build, status} - res := &GetBuildStatusResp{} - err := c.Call("Datastore.GetBuildStatus", req, res) - return res.Status, err -} - -type GetBuildStatusListReq struct { - Repo string - Build int -} - -type GetBuildStatusListResp struct { - Statuses []*common.Status -} - -func (c *Client) GetBuildStatusList(repo string, build int) ([]*common.Status, error) { - req := &GetBuildStatusListReq{repo, build} - res := &GetBuildStatusListResp{} - err := c.Call("Datastore.GetBuildStatusList", req, res) - return res.Statuses, err -} - -type InsertBuildReq struct { - Repo string - Build *common.Build -} - -func (c *Client) InsertBuild(repo string, build *common.Build) error { - build.Created = time.Now().UTC().Unix() - build.Updated = time.Now().UTC().Unix() - // TODO need to capture the sequential build number that is generated - req := &InsertBuildReq{repo, build} - return c.Call("Datastore.InsertBuild", req, nil) -} - -type InsertBuildStatusReq struct { - Repo string - Build int - Status *common.Status -} - -func (c *Client) InsertBuildStatus(repo string, build int, status *common.Status) error { - req := &InsertBuildStatusReq{repo, build, status} - return c.Call("Datastore.InsertBuildStatus", req, nil) -} - -type UpdateBuildReq struct { - Repo string - Build *common.Build -} - -func (c *Client) UpdateBuild(repo string, build *common.Build) error { - build.Updated = time.Now().UTC().Unix() - req := &InsertBuildReq{repo, build} - return c.Call("Datastore.UpdateBuild", req, nil) -} diff --git a/pkg/store/plugin/client.go b/pkg/store/plugin/client.go deleted file mode 100644 index cb6109ca..00000000 --- a/pkg/store/plugin/client.go +++ /dev/null @@ -1,23 +0,0 @@ -package plugin - -import ( - "net" - "net/rpc" -) - -type Client struct { - *rpc.Client -} - -// New returns a new, remote datastore backend that connects -// via tcp and exchanges data using Go's RPC mechanism. -func New(address string) (*Client, error) { - conn, err := net.Dial("tcp", address) - if err != nil { - return nil, err - } - client := &Client{ - rpc.NewClient(conn), - } - return client, nil -} diff --git a/pkg/store/plugin/repo.go b/pkg/store/plugin/repo.go deleted file mode 100644 index 1d21b5a0..00000000 --- a/pkg/store/plugin/repo.go +++ /dev/null @@ -1,102 +0,0 @@ -package plugin - -import ( - "time" - - common "github.com/drone/drone/pkg/types" -) - -type GetRepoReq struct { - Repo string -} - -type GetRepoResp struct { - Repo *common.Repo -} - -func (c *Client) GetRepo(repo string) (*common.Repo, error) { - req := &GetRepoReq{repo} - res := &GetRepoResp{} - err := c.Call("Datastore.GetRepo", req, res) - return res.Repo, err -} - -type GetRepoParamsReq struct { - Repo string -} - -type GetRepoParamsResp struct { - Params map[string]string -} - -func (c *Client) GetRepoParams(repo string) (map[string]string, error) { - req := &GetRepoParamsReq{repo} - res := &GetRepoParamsResp{} - err := c.Call("Datastore.GetRepoParams", req, res) - return res.Params, err -} - -type GetRepoKeysReq struct { - Repo string -} - -type GetRepoKeysResp struct { - Keys *common.Keypair -} - -func (c *Client) GetRepoKeys(repo string) (*common.Keypair, error) { - req := &GetRepoKeysReq{repo} - res := &GetRepoKeysResp{} - err := c.Call("Datastore.GetRepoKeys", req, res) - return res.Keys, err -} - -type UpdateRepoReq struct { - Repo *common.Repo -} - -func (c *Client) UpdateRepo(repo *common.Repo) error { - repo.Updated = time.Now().UTC().Unix() - req := &UpdateRepoReq{repo} - return c.Call("Datastore.UpdateRepo", req, nil) -} - -type InsertRepoReq struct { - User *common.User - Repo *common.Repo -} - -func (c *Client) InsertRepo(user *common.User, repo *common.Repo) error { - repo.Created = time.Now().UTC().Unix() - repo.Updated = time.Now().UTC().Unix() - req := &InsertRepoReq{user, repo} - return c.Call("Datastore.InsertRepo", req, nil) -} - -type UpsertRepoParamsReq struct { - Repo string -} - -func (c *Client) UpsertRepoParams(repo string, params map[string]string) error { - req := &UpsertRepoParamsReq{repo} - return c.Call("Datastore.UpsertRepoParams", req, nil) -} - -type UpsertRepoKeysReq struct { - Repo string - Keys *common.Keypair -} - -func (c *Client) UpsertRepoKeys(repo string, keypair *common.Keypair) error { - req := &UpsertRepoKeysReq{repo, keypair} - return c.Call("Datastore.UpsertRepoKeys", req, nil) -} - -type DeleteRepoReq struct { - Repo *common.Repo -} - -func (c *Client) DeleteRepo(repo *common.Repo) error { - req := &DeleteRepoReq{repo} - return c.Call("Datastore.DeleteRepo", req, nil) -} diff --git a/pkg/store/plugin/task.go b/pkg/store/plugin/task.go deleted file mode 100644 index 9be149f2..00000000 --- a/pkg/store/plugin/task.go +++ /dev/null @@ -1,78 +0,0 @@ -package plugin - -import ( - common "github.com/drone/drone/pkg/types" -) - -type GetTaskReq struct { - Repo string - Build int - Task int -} - -type GetTaskResp struct { - Task *common.Task -} - -func (c *Client) GetTask(repo string, build int, task int) (*common.Task, error) { - req := &GetTaskReq{repo, build, task} - res := &GetTaskResp{} - err := c.Call("Datastore.GetTask", req, res) - return res.Task, err -} - -type GetTaskLogsReq struct { - Repo string - Build int - Task int -} - -type GetTaskLogsResp struct { - Logs []byte -} - -func (c *Client) GetTaskLogs(repo string, build int, task int) ([]byte, error) { - req := &GetTaskLogsReq{repo, build, task} - res := &GetTaskLogsResp{} - err := c.Call("Datastore.GetTaskLogs", req, res) - return res.Logs, err -} - -type GetTaskListReq struct { - Repo string - Build int -} - -type GetTaskListResp struct { - Tasks []*common.Task -} - -func (c *Client) GetTaskList(repo string, build int) ([]*common.Task, error) { - req := &GetTaskListReq{repo, build} - res := &GetTaskListResp{} - err := c.Call("Datastore.GetTaskList", req, res) - return res.Tasks, err -} - -type UpsertTaskReq struct { - Repo string - Build int - Task *common.Task -} - -func (c *Client) UpsertTask(repo string, build int, task *common.Task) error { - req := &UpsertTaskReq{repo, build, task} - return c.Call("Datastore.UpsertTask", req, nil) -} - -type UpsertTaskLogsReq struct { - Repo string - Build int - Task int - Logs []byte -} - -func (c *Client) UpsertTaskLogs(repo string, build int, task int, log []byte) error { - req := &UpsertTaskLogsReq{repo, build, task, log} - return c.Call("Datastore.UpsertTaskLogs", req, nil) -} diff --git a/pkg/store/plugin/token.go b/pkg/store/plugin/token.go deleted file mode 100644 index 4b65ed1d..00000000 --- a/pkg/store/plugin/token.go +++ /dev/null @@ -1,38 +0,0 @@ -package plugin - -import ( - common "github.com/drone/drone/pkg/types" -) - -type GetTokenReq struct { - Sha string -} - -type GetTokenResp struct { - Token *common.Token -} - -func (c *Client) GetToken(sha string) (*common.Token, error) { - req := &GetTokenReq{sha} - res := &GetTokenResp{} - err := c.Call("Datastore.GetToken", req, res) - return res.Token, err -} - -type InsertTokenReq struct { - Token *common.Token -} - -func (c *Client) InsertToken(token *common.Token) error { - req := &InsertTokenReq{token} - return c.Call("Datastore.InsertToken", req, nil) -} - -type DeleteTokenReq struct { - Token *common.Token -} - -func (c *Client) DeleteToken(token *common.Token) error { - req := &DeleteTokenReq{token} - return c.Call("Datastore.DeleteToken", req, nil) -} diff --git a/pkg/store/plugin/user.go b/pkg/store/plugin/user.go deleted file mode 100644 index 37fe4b92..00000000 --- a/pkg/store/plugin/user.go +++ /dev/null @@ -1,102 +0,0 @@ -package plugin - -import ( - "time" - - common "github.com/drone/drone/pkg/types" -) - -type GetUserReq struct { - Login string -} - -type GetUserResp struct { - User *common.User -} - -func (c *Client) GetUser(login string) (*common.User, error) { - req := &GetUserReq{login} - res := &GetUserResp{} - err := c.Call("Datastore.GetUser", req, res) - return res.User, err -} - -type GetUserTokensReq struct { - Login string -} - -type GetUserTokensResp struct { - Tokens []*common.Token -} - -func (c *Client) GetUserTokens(login string) ([]*common.Token, error) { - req := &GetUserTokensReq{login} - res := &GetUserTokensResp{} - err := c.Call("Datastore.GetUserTokens", req, res) - return res.Tokens, err -} - -type GetUserReposReq struct { - Login string -} - -type GetUserReposResp struct { - Repos []*common.Repo -} - -func (c *Client) GetUserRepos(login string) ([]*common.Repo, error) { - req := &GetUserReposReq{login} - res := &GetUserReposResp{} - err := c.Call("Datastore.GetUserRepos", req, res) - return res.Repos, err -} - -type GetUserCountResp struct { - Count int -} - -func (c *Client) GetUserCount() (int, error) { - res := &GetUserCountResp{} - err := c.Call("Datastore.GetUserCount", nil, res) - return res.Count, err -} - -type GetUserListResp struct { - Users []*common.User -} - -func (c *Client) GetUserList() ([]*common.User, error) { - res := &GetUserListResp{} - err := c.Call("Datastore.GetUserList", nil, res) - return res.Users, err -} - -type UpdateUserReq struct { - User *common.User -} - -func (c *Client) UpdateUser(user *common.User) error { - user.Updated = time.Now().UTC().Unix() - req := &UpdateUserReq{user} - return c.Call("Datastore.UpdateUser", req, nil) -} - -type InsertUserReq struct { - User *common.User -} - -func (c *Client) InsertUser(user *common.User) error { - user.Created = time.Now().UTC().Unix() - user.Updated = time.Now().UTC().Unix() - req := &InsertUserReq{user} - return c.Call("Datastore.InsertUser", req, nil) -} - -type DeleteUserReq struct { - User *common.User -} - -func (c *Client) DeleteUser(user *common.User) error { - req := &DeleteUserReq{user} - return c.Call("Datastore.DeleteUser", req, nil) -}