mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-06-05 08:58:50 +00:00
Merge branch 'master' into add-container-labels
This commit is contained in:
commit
bd93982010
12 changed files with 148 additions and 18 deletions
|
@ -167,7 +167,7 @@ func (a *Agent) prep(w *queue.Work) (*yaml.Config, error) {
|
||||||
transform.ImageVolume(conf, []string{a.Local + ":" + conf.Workspace.Path})
|
transform.ImageVolume(conf, []string{a.Local + ":" + conf.Workspace.Path})
|
||||||
}
|
}
|
||||||
|
|
||||||
transform.Pod(conf)
|
transform.Pod(conf, a.Platform)
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,8 +222,8 @@ func (c *client) BuildQueue() ([]*model.Feed, error) {
|
||||||
func (c *client) BuildStart(owner, name string, num int, params map[string]string) (*model.Build, error) {
|
func (c *client) BuildStart(owner, name string, num int, params map[string]string) (*model.Build, error) {
|
||||||
out := new(model.Build)
|
out := new(model.Build)
|
||||||
val := parseToQueryParams(params)
|
val := parseToQueryParams(params)
|
||||||
uri := fmt.Sprintf(pathBuild+"?"+val.Encode(), c.base, owner, name, num)
|
uri := fmt.Sprintf(pathBuild, c.base, owner, name, num)
|
||||||
err := c.post(uri, nil, out)
|
err := c.post(uri+"?"+val.Encode(), nil, out)
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,8 +240,8 @@ func (c *client) BuildFork(owner, name string, num int, params map[string]string
|
||||||
out := new(model.Build)
|
out := new(model.Build)
|
||||||
val := parseToQueryParams(params)
|
val := parseToQueryParams(params)
|
||||||
val.Set("fork", "true")
|
val.Set("fork", "true")
|
||||||
uri := fmt.Sprintf(pathBuild+"?"+val.Encode(), c.base, owner, name, num)
|
uri := fmt.Sprintf(pathBuild, c.base, owner, name, num)
|
||||||
err := c.post(uri, nil, out)
|
err := c.post(uri+"?"+val.Encode(), nil, out)
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,8 +259,8 @@ func (c *client) Deploy(owner, name string, num int, env string, params map[stri
|
||||||
val.Set("fork", "true")
|
val.Set("fork", "true")
|
||||||
val.Set("event", "deployment")
|
val.Set("event", "deployment")
|
||||||
val.Set("deploy_to", env)
|
val.Set("deploy_to", env)
|
||||||
uri := fmt.Sprintf(pathBuild+"?"+val.Encode(), c.base, owner, name, num)
|
uri := fmt.Sprintf(pathBuild, c.base, owner, name, num)
|
||||||
err := c.post(uri, nil, out)
|
err := c.post(uri+"?"+val.Encode(), nil, out)
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ var orgSecretAddCmd = cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func orgSecretAdd(c *cli.Context) error {
|
func orgSecretAdd(c *cli.Context) error {
|
||||||
if len(c.Args().Tail()) != 3 {
|
if len(c.Args()) != 3 {
|
||||||
cli.ShowSubcommandHelp(c)
|
cli.ShowSubcommandHelp(c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ var orgSecretListCmd = cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func orgSecretList(c *cli.Context) error {
|
func orgSecretList(c *cli.Context) error {
|
||||||
if len(c.Args().Tail()) != 1 {
|
if len(c.Args()) != 1 {
|
||||||
cli.ShowSubcommandHelp(c)
|
cli.ShowSubcommandHelp(c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ var orgSecretRemoveCmd = cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func orgSecretRemove(c *cli.Context) error {
|
func orgSecretRemove(c *cli.Context) error {
|
||||||
if len(c.Args().Tail()) != 2 {
|
if len(c.Args()) != 2 {
|
||||||
cli.ShowSubcommandHelp(c)
|
cli.ShowSubcommandHelp(c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,8 +149,18 @@ func (c *Config) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status is not supported by the bitbucketserver driver.
|
// Status is not supported by the bitbucketserver driver.
|
||||||
func (*Config) Status(*model.User, *model.Repo, *model.Build, string) error {
|
func (c *Config) Status(u *model.User,r *model.Repo,b *model.Build,link string) error {
|
||||||
return nil
|
status := internal.BuildStatus{
|
||||||
|
State: convertStatus(b.Status),
|
||||||
|
Desc: convertDesc(b.Status),
|
||||||
|
Name: fmt.Sprintf("Drone #%d - %s", b.Number, b.Branch),
|
||||||
|
Key: "Drone",
|
||||||
|
Url: link,
|
||||||
|
}
|
||||||
|
|
||||||
|
client := internal.NewClientWithToken(c.URL, c.Consumer, u.Token)
|
||||||
|
|
||||||
|
return client.CreateStatus(b.Commit, &status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) {
|
func (c *Config) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||||
|
|
|
@ -13,6 +13,48 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
const (
|
||||||
|
statusPending = "INPROGRESS"
|
||||||
|
statusSuccess = "SUCCESSFUL"
|
||||||
|
statusFailure = "FAILED"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
descPending = "this build is pending"
|
||||||
|
descSuccess = "the build was successful"
|
||||||
|
descFailure = "the build failed"
|
||||||
|
descError = "oops, something went wrong"
|
||||||
|
)
|
||||||
|
|
||||||
|
// convertStatus is a helper function used to convert a Drone status to a
|
||||||
|
// Bitbucket commit status.
|
||||||
|
func convertStatus(status string) string {
|
||||||
|
switch status {
|
||||||
|
case model.StatusPending, model.StatusRunning:
|
||||||
|
return statusPending
|
||||||
|
case model.StatusSuccess:
|
||||||
|
return statusSuccess
|
||||||
|
default:
|
||||||
|
return statusFailure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertDesc is a helper function used to convert a Drone status to a
|
||||||
|
// Bitbucket status description.
|
||||||
|
func convertDesc(status string) string {
|
||||||
|
switch status {
|
||||||
|
case model.StatusPending, model.StatusRunning:
|
||||||
|
return descPending
|
||||||
|
case model.StatusSuccess:
|
||||||
|
return descSuccess
|
||||||
|
case model.StatusFailure:
|
||||||
|
return descFailure
|
||||||
|
default:
|
||||||
|
return descError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// convertRepo is a helper function used to convert a Bitbucket server repository
|
// convertRepo is a helper function used to convert a Bitbucket server repository
|
||||||
// structure to the common Drone repository structure.
|
// structure to the common Drone repository structure.
|
||||||
func convertRepo(from *internal.Repo) *model.Repo {
|
func convertRepo(from *internal.Repo) *model.Repo {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/mrjones/oauth"
|
"github.com/mrjones/oauth"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -20,6 +21,7 @@ const (
|
||||||
pathSource = "%s/projects/%s/repos/%s/browse/%s?at=%s&raw"
|
pathSource = "%s/projects/%s/repos/%s/browse/%s?at=%s&raw"
|
||||||
hookName = "com.atlassian.stash.plugin.stash-web-post-receive-hooks-plugin:postReceiveHook"
|
hookName = "com.atlassian.stash.plugin.stash-web-post-receive-hooks-plugin:postReceiveHook"
|
||||||
pathHookEnabled = "%s/rest/api/1.0/projects/%s/repos/%s/settings/hooks/%s/enabled"
|
pathHookEnabled = "%s/rest/api/1.0/projects/%s/repos/%s/settings/hooks/%s/enabled"
|
||||||
|
pathStatus = "%s/rest/build-status/1.0/commits/%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -151,11 +153,18 @@ func (c *Client) CreateHook(owner string, name string, callBackLink string) erro
|
||||||
return c.doPut(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName), hookBytes)
|
return c.doPut(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName), hookBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) CreateStatus(revision string, status *BuildStatus) error {
|
||||||
|
uri := fmt.Sprintf(pathStatus, c.base, revision)
|
||||||
|
return c.doPost(uri, status)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) DeleteHook(owner string, name string, link string) error {
|
func (c *Client) DeleteHook(owner string, name string, link string) error {
|
||||||
//TODO: eventially should only delete the link callback
|
//TODO: eventially should only delete the link callback
|
||||||
return c.doDelete(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName))
|
return c.doDelete(fmt.Sprintf(pathHookEnabled, c.base, owner, name, hookName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: make these as as general do with the action
|
||||||
|
|
||||||
//Helper function to help create the hook
|
//Helper function to help create the hook
|
||||||
func (c *Client) doPut(url string, body []byte) error {
|
func (c *Client) doPut(url string, body []byte) error {
|
||||||
request, err := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
request, err := http.NewRequest("PUT", url, bytes.NewBuffer(body))
|
||||||
|
@ -166,9 +175,34 @@ func (c *Client) doPut(url string, body []byte) error {
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Helper function to help create the hook
|
||||||
|
func (c *Client) doPost(url string, status *BuildStatus) error {
|
||||||
|
// write it to the body of the request.
|
||||||
|
var buf io.ReadWriter
|
||||||
|
if status != nil {
|
||||||
|
buf = new(bytes.Buffer)
|
||||||
|
err := json.NewEncoder(buf).Encode(status)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request, err := http.NewRequest("POST", url, buf)
|
||||||
|
request.Header.Add("Content-Type", "application/json")
|
||||||
|
response, err := c.client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Helper function to do delete on the hook
|
//Helper function to do delete on the hook
|
||||||
func (c *Client) doDelete(url string) error {
|
func (c *Client) doDelete(url string) error {
|
||||||
request, err := http.NewRequest("DELETE", url, nil)
|
request, err := http.NewRequest("DELETE", url, nil)
|
||||||
|
|
|
@ -24,6 +24,14 @@ type SelfRefLink struct {
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BuildStatus struct {
|
||||||
|
State string `json:"state"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
Desc string `json:"description,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
Forkable bool `json:"forkable"`
|
Forkable bool `json:"forkable"`
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
|
|
|
@ -67,6 +67,9 @@ func New(opts Opts) (remote.Remote, error) {
|
||||||
remote.URL = strings.TrimSuffix(opts.URL, "/")
|
remote.URL = strings.TrimSuffix(opts.URL, "/")
|
||||||
remote.API = remote.URL + "/api/v3/"
|
remote.API = remote.URL + "/api/v3/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hack to enable oauth2 access in older GHE
|
||||||
|
oauth2.RegisterBrokenAuthHeaderProvider(remote.URL)
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ func toScript(commands []string) string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
escaped := fmt.Sprintf("%q", command)
|
escaped := fmt.Sprintf("%q", command)
|
||||||
escaped = strings.Replace(command, "$", `$\`, -1)
|
escaped = strings.Replace(escaped, "$", `\$`, -1)
|
||||||
buf.WriteString(fmt.Sprintf(
|
buf.WriteString(fmt.Sprintf(
|
||||||
traceScript,
|
traceScript,
|
||||||
escaped,
|
escaped,
|
||||||
|
|
|
@ -9,21 +9,54 @@ import (
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ambassador struct {
|
||||||
|
image string
|
||||||
|
entrypoint []string
|
||||||
|
command []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// default linux amd64 ambassador
|
||||||
|
var defaultAmbassador = ambassador{
|
||||||
|
image: "busybox:latest",
|
||||||
|
entrypoint: []string{"/bin/sleep"},
|
||||||
|
command: []string{"86400"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup ambassador configuration by architecture and os
|
||||||
|
var lookupAmbassador = map[string]ambassador{
|
||||||
|
"linux/amd64": {
|
||||||
|
image: "busybox:latest",
|
||||||
|
entrypoint: []string{"/bin/sleep"},
|
||||||
|
command: []string{"86400"},
|
||||||
|
},
|
||||||
|
"linux/arm": {
|
||||||
|
image: "armhf/alpine:latest",
|
||||||
|
entrypoint: []string{"/bin/sleep"},
|
||||||
|
command: []string{"86400"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Pod transforms the containers in the Yaml to use Pod networking, where every
|
// Pod transforms the containers in the Yaml to use Pod networking, where every
|
||||||
// container shares the localhost connection.
|
// container shares the localhost connection.
|
||||||
func Pod(c *yaml.Config) error {
|
func Pod(c *yaml.Config, platform string) error {
|
||||||
|
|
||||||
rand := base64.RawURLEncoding.EncodeToString(
|
rand := base64.RawURLEncoding.EncodeToString(
|
||||||
securecookie.GenerateRandomKey(8),
|
securecookie.GenerateRandomKey(8),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// choose the ambassador configuration based on os and architecture
|
||||||
|
conf, ok := lookupAmbassador[platform]
|
||||||
|
if !ok {
|
||||||
|
conf = defaultAmbassador
|
||||||
|
}
|
||||||
|
|
||||||
ambassador := &yaml.Container{
|
ambassador := &yaml.Container{
|
||||||
ID: fmt.Sprintf("drone_ambassador_%s", rand),
|
ID: fmt.Sprintf("drone_ambassador_%s", rand),
|
||||||
Name: "ambassador",
|
Name: "ambassador",
|
||||||
Image: "busybox:latest",
|
Image: conf.image,
|
||||||
Detached: true,
|
Detached: true,
|
||||||
Entrypoint: []string{"/bin/sleep"},
|
Entrypoint: conf.entrypoint,
|
||||||
Command: []string{"86400"},
|
Command: conf.command,
|
||||||
Volumes: []string{c.Workspace.Path, c.Workspace.Base},
|
Volumes: []string{c.Workspace.Path, c.Workspace.Base},
|
||||||
Environment: map[string]string{},
|
Environment: map[string]string{},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue