From d329615b8950f9b92287211344532482e4962c3d Mon Sep 17 00:00:00 2001 From: Kirill Sevastyanenko Date: Mon, 6 Apr 2015 11:10:40 -0500 Subject: [PATCH 01/56] Fix small typo in comments --- shared/build/buildfile/buildfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/build/buildfile/buildfile.go b/shared/build/buildfile/buildfile.go index 723ca1af1..e44ceb96c 100644 --- a/shared/build/buildfile/buildfile.go +++ b/shared/build/buildfile/buildfile.go @@ -84,7 +84,7 @@ chmod 0700 $HOME/.ssh echo 'StrictHostKeyChecking no' | tee $HOME/.ssh/config > /dev/null # be sure to exit on error and print out -# our bash commands, so we can which commands +# our bash commands, so we can see which commands # are executing and troubleshoot failures. set -e From b3f6552498803c4fbfd92297432fa66841110df8 Mon Sep 17 00:00:00 2001 From: Kirill Sevastyanenko Date: Mon, 6 Apr 2015 11:15:06 -0500 Subject: [PATCH 02/56] s/Exepected/Expected --- shared/build/buildfile/buildfile_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shared/build/buildfile/buildfile_test.go b/shared/build/buildfile/buildfile_test.go index 080a84f6f..46b4b298e 100644 --- a/shared/build/buildfile/buildfile_test.go +++ b/shared/build/buildfile/buildfile_test.go @@ -9,48 +9,48 @@ func TestWrite(t *testing.T) { var f = New() var got, want = f.String(), base if got != want { - t.Errorf("Exepected New() returned %s, got %s", want, got) + t.Errorf("Expected New() returned %s, got %s", want, got) } f = &Buildfile{} f.WriteCmd("echo hi") got, want = f.String(), "echo '#DRONE:6563686f206869'\necho hi\n" if got != want { - t.Errorf("Exepected WriteCmd returned %s, got %s", want, got) + t.Errorf("Expected WriteCmd returned %s, got %s", want, got) } f = &Buildfile{} f.WriteCmdSilent("echo hi") got, want = f.String(), "echo hi\n" if got != want { - t.Errorf("Exepected WriteCmdSilent returned %s, got %s", want, got) + t.Errorf("Expected WriteCmdSilent returned %s, got %s", want, got) } f = &Buildfile{} f.WriteComment("this is a comment") got, want = f.String(), "#this is a comment\n" if got != want { - t.Errorf("Exepected WriteComment returned %s, got %s", want, got) + t.Errorf("Expected WriteComment returned %s, got %s", want, got) } f = &Buildfile{} f.WriteEnv("FOO", "BAR") got, want = f.String(), "export FOO=\"BAR\"\n" if got != want { - t.Errorf("Exepected WriteEnv returned %s, got %s", want, got) + t.Errorf("Expected WriteEnv returned %s, got %s", want, got) } f = &Buildfile{} f.WriteHost("127.0.0.1") got, want = f.String(), "[ -f /usr/bin/sudo ] || echo \"127.0.0.1\" | tee -a /etc/hosts\n[ -f /usr/bin/sudo ] && echo \"127.0.0.1\" | sudo tee -a /etc/hosts\n" if got != want { - t.Errorf("Exepected WriteHost returned %s, got %s", want, got) + t.Errorf("Expected WriteHost returned %s, got %s", want, got) } f = &Buildfile{} f.WriteFile("$HOME/.ssh/id_rsa", []byte("ssh-rsa AAA..."), 600) got, want = f.String(), "echo 'ssh-rsa AAA...' | tee $HOME/.ssh/id_rsa > /dev/null\nchmod 600 $HOME/.ssh/id_rsa\n" if got != want { - t.Errorf("Exepected WriteFile returned \n%s, \ngot\n%s", want, got) + t.Errorf("Expected WriteFile returned \n%s, \ngot\n%s", want, got) } } From 525d6d132955a3419bd6dc46b5b64a6661b3aee1 Mon Sep 17 00:00:00 2001 From: Henrik Jonsson Date: Wed, 8 Apr 2015 15:18:01 +0200 Subject: [PATCH 03/56] s/heper/helper in helper.go --- plugin/remote/github/helper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin/remote/github/helper.go b/plugin/remote/github/helper.go index 2f05ea0cc..64ffd33b1 100644 --- a/plugin/remote/github/helper.go +++ b/plugin/remote/github/helper.go @@ -34,7 +34,7 @@ func NewClient(uri, token string, skipVerify bool) *github.Client { return c } -// GetUserEmail is a heper function that retrieves the currently +// GetUserEmail is a helper function that retrieves the currently // authenticated user from GitHub + Email address. func GetUserEmail(client *github.Client) (*github.User, error) { user, _, err := client.Users.Get("") @@ -157,7 +157,7 @@ func GetOrgs(client *github.Client) ([]github.Organization, error) { return orgs, nil } -// GetHook is a heper function that retrieves a hook by +// GetHook is a helper function that retrieves a hook by // hostname. To do this, it will retrieve a list of all hooks // and iterate through the list. func GetHook(client *github.Client, owner, name, url string) (*github.Hook, error) { @@ -183,7 +183,7 @@ func DeleteHook(client *github.Client, owner, name, url string) error { return err } -// CreateHook is a heper function that creates a post-commit hook +// CreateHook is a helper function that creates a post-commit hook // for the specified repository. func CreateHook(client *github.Client, owner, name, url string) (*github.Hook, error) { var hook = new(github.Hook) @@ -196,7 +196,7 @@ func CreateHook(client *github.Client, owner, name, url string) (*github.Hook, e return created, err } -// CreateUpdateHook is a heper function that creates a post-commit hook +// CreateUpdateHook is a helper function that creates a post-commit hook // for the specified repository if it does not already exist, otherwise // it updates the existing hook func CreateUpdateHook(client *github.Client, owner, name, url string) (*github.Hook, error) { @@ -214,7 +214,7 @@ func CreateUpdateHook(client *github.Client, owner, name, url string) (*github.H return CreateHook(client, owner, name, url) } -// GetKey is a heper function that retrieves a public Key by +// GetKey is a helper function that retrieves a public Key by // title. To do this, it will retrieve a list of all keys // and iterate through the list. func GetKey(client *github.Client, owner, name, title string) (*github.Key, error) { @@ -275,7 +275,7 @@ func CreateUpdateKey(client *github.Client, owner, name, title, key string) (*gi return CreateKey(client, owner, name, title, key) } -// GetFile is a heper function that retrieves a file from +// GetFile is a helper function that retrieves a file from // GitHub and returns its contents in byte array format. func GetFile(client *github.Client, owner, name, path, ref string) ([]byte, error) { var opts = new(github.RepositoryContentGetOptions) From 8bcb5d9c52df2339dcf1da460e13ca2f1101720c Mon Sep 17 00:00:00 2001 From: Alexey Chernenkov Date: Thu, 9 Apr 2015 21:17:55 +0500 Subject: [PATCH 04/56] Use HipChat notification API ver 2 HipChat API v1 is deprecated, but github.com/andybons/hipchat (used by Drone) does not support v2. So I've implemented v2 using native http.PostForm. --- plugin/notify/hipchat.go | 77 +++++++++++++++++++++++++---------- plugin/notify/hipchat_test.go | 44 +++++++++----------- 2 files changed, 75 insertions(+), 46 deletions(-) diff --git a/plugin/notify/hipchat.go b/plugin/notify/hipchat.go index d1d7f1406..d1c70d76a 100644 --- a/plugin/notify/hipchat.go +++ b/plugin/notify/hipchat.go @@ -2,8 +2,10 @@ package notify import ( "fmt" + "net/http" + "net/url" + "strconv" - "github.com/andybons/hipchat" "github.com/drone/drone/shared/model" ) @@ -21,12 +23,8 @@ type Hipchat struct { Failure bool `yaml:"on_failure,omitempty"` } -type HipchatClient interface { - PostMessage(req hipchat.MessageRequest) error -} - func (h *Hipchat) Send(context *model.Request) error { - client := &hipchat.Client{AuthToken: h.Token} + client := new(HipchatSimpleHTTPClient) return h.SendWithClient(client, context) } @@ -39,7 +37,6 @@ func (h *Hipchat) SendWithClient(client HipchatClient, context *model.Request) e case context.Commit.Status == "Failure" && h.Failure: return h.sendFailure(client, context) } - return nil } @@ -51,29 +48,65 @@ func (h *Hipchat) buildLink(context *model.Request) string { func (h *Hipchat) sendStarted(client HipchatClient, context *model.Request) error { msg := fmt.Sprintf(startedMessage, h.buildLink(context), context.Commit.Branch, context.Commit.Author, context.Commit.Message) - return h.send(client, hipchat.ColorYellow, hipchat.FormatHTML, msg, false) + req := HipchatMessageRequest{ + RoomId: h.Room, + AuthToken: h.Token, + Color: "yellow", + Message: msg, + Notify: false, + } + return client.PostMessage(req) } func (h *Hipchat) sendFailure(client HipchatClient, context *model.Request) error { msg := fmt.Sprintf(failureMessage, h.buildLink(context), context.Commit.Branch, context.Commit.Author) - return h.send(client, hipchat.ColorRed, hipchat.FormatHTML, msg, true) + req := HipchatMessageRequest{ + RoomId: h.Room, + AuthToken: h.Token, + Color: "red", + Message: msg, + Notify: true, + } + return client.PostMessage(req) } func (h *Hipchat) sendSuccess(client HipchatClient, context *model.Request) error { msg := fmt.Sprintf(successMessage, h.buildLink(context), context.Commit.Branch, context.Commit.Author) - return h.send(client, hipchat.ColorGreen, hipchat.FormatHTML, msg, false) -} - -// helper function to send Hipchat requests -func (h *Hipchat) send(client HipchatClient, color, format, message string, notify bool) error { - req := hipchat.MessageRequest{ - RoomId: h.Room, - From: "Drone", - Message: message, - Color: color, - MessageFormat: format, - Notify: notify, + req := HipchatMessageRequest{ + RoomId: h.Room, + AuthToken: h.Token, + Color: "green", + Message: msg, + Notify: false, } - return client.PostMessage(req) } + +// HipChat client + +type HipchatClient interface { + PostMessage(req HipchatMessageRequest) error +} + +type HipchatMessageRequest struct { + RoomId string + Color string + Message string + Notify bool + AuthToken string +} + +type HipchatSimpleHTTPClient struct{} + +func (*HipchatSimpleHTTPClient) PostMessage(req HipchatMessageRequest) error { + hipchat_uri := fmt.Sprintf("https://api.hipchat.com/v2/room/%s/notification", req.RoomId) + _, err := http.PostForm(hipchat_uri, + url.Values{ + "color": {req.Color}, + "message": {req.Message}, + "notify": {strconv.FormatBool(req.Notify)}, + "message_format": {"html"}, + "auth_token": {req.AuthToken}, + }) + return err +} diff --git a/plugin/notify/hipchat_test.go b/plugin/notify/hipchat_test.go index 5f3e809d4..e9a8cc7e1 100644 --- a/plugin/notify/hipchat_test.go +++ b/plugin/notify/hipchat_test.go @@ -3,15 +3,14 @@ package notify import ( "testing" - "github.com/andybons/hipchat" "github.com/drone/drone/shared/model" ) type MockHipchatClient struct { - Request hipchat.MessageRequest + Request HipchatMessageRequest } -func (c *MockHipchatClient) PostMessage(req hipchat.MessageRequest) error { +func (c *MockHipchatClient) PostMessage(req HipchatMessageRequest) error { c.Request = req return nil } @@ -49,13 +48,12 @@ func Test_SendStarted(t *testing.T) { request.Commit.Status = "Started" subject.SendWithClient(client, request) - expected := hipchat.MessageRequest{ - RoomId: "SampleRoom", - From: "Drone", - Message: "Building owner/repo#abc (example) by Test User
- Test Commit", - Color: hipchat.ColorYellow, - MessageFormat: hipchat.FormatHTML, - Notify: false, + expected := HipchatMessageRequest{ + RoomId: "SampleRoom", + AuthToken: "foo", + Color: "yellow", + Message: "Building owner/repo#abc (example) by Test User
- Test Commit", + Notify: false, } if client.Request != expected { @@ -67,13 +65,12 @@ func Test_SendSuccess(t *testing.T) { request.Commit.Status = "Success" subject.SendWithClient(client, request) - expected := hipchat.MessageRequest{ - RoomId: "SampleRoom", - From: "Drone", - Message: "Success owner/repo#abc (example) by Test User", - Color: hipchat.ColorGreen, - MessageFormat: hipchat.FormatHTML, - Notify: false, + expected := HipchatMessageRequest{ + RoomId: "SampleRoom", + AuthToken: "foo", + Color: "green", + Message: "Success owner/repo#abc (example) by Test User", + Notify: false, } if client.Request != expected { @@ -85,13 +82,12 @@ func Test_SendFailure(t *testing.T) { request.Commit.Status = "Failure" subject.SendWithClient(client, request) - expected := hipchat.MessageRequest{ - RoomId: "SampleRoom", - From: "Drone", - Message: "Failed owner/repo#abc (example) by Test User", - Color: hipchat.ColorRed, - MessageFormat: hipchat.FormatHTML, - Notify: true, + expected := HipchatMessageRequest{ + RoomId: "SampleRoom", + AuthToken: "foo", + Color: "red", + Message: "Failed owner/repo#abc (example) by Test User", + Notify: true, } if client.Request != expected { From 9bc3a25a5e63ee52396d9fbfd6820c32f2cbf5f3 Mon Sep 17 00:00:00 2001 From: Alexey Chernenkov Date: Thu, 9 Apr 2015 17:12:01 +0500 Subject: [PATCH 05/56] Fix dependency: github.com/docker/docker/utils was moved to pkg/jsonmessage --- shared/build/docker/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/build/docker/client.go b/shared/build/docker/client.go index 678059b90..6dd33213e 100644 --- a/shared/build/docker/client.go +++ b/shared/build/docker/client.go @@ -15,9 +15,9 @@ import ( "strings" "time" + "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/term" - "github.com/docker/docker/utils" ) const ( @@ -353,7 +353,7 @@ func (c *Client) stream(method, path string, in io.Reader, out io.Writer, header // it may not make sense to put this code here, but it works for // us at the moment, and I don't feel like refactoring - return utils.DisplayJSONMessagesStream(resp.Body, out, terminalFd, isTerminal) + return jsonmessage.DisplayJSONMessagesStream(resp.Body, out, terminalFd, isTerminal) } // otherwise plain text if _, err := io.Copy(out, resp.Body); err != nil { From d9f855e5b675858d6deb124a1172997b5f340684 Mon Sep 17 00:00:00 2001 From: Alexey Chernenkov Date: Tue, 14 Apr 2015 12:07:04 +0500 Subject: [PATCH 06/56] Try to build with the latest Docker sources --- .drone.yml | 1 - Makefile | 4 ---- 2 files changed, 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 182432e57..bc0d0d606 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,7 +11,6 @@ script: - sudo apt-get -y install git zip libsqlite3-dev sqlite3 rpm 1> /dev/null 2> /dev/null - gem install fpm - rbenv rehash - - make docker - make deps - make test - make test_postgres diff --git a/Makefile b/Makefile index fe35faefe..16bc2a181 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,6 @@ deps: go get github.com/GeertJohan/go.rice/rice go get -t -v ./... -docker: - mkdir -p $$GOPATH/src/github.com/docker/docker - git clone --depth=1 --branch=v1.5.0 git://github.com/docker/docker.git $$GOPATH/src/github.com/docker/docker - test: @test -z "$(shell find . -name '*.go' | xargs gofmt -l)" || (echo "Need to run 'go fmt ./...'"; exit 1) go vet ./... From 009e8a1dceac6c661fe603c38f15f11294cceffd Mon Sep 17 00:00:00 2001 From: Vaidas Jablonskis Date: Fri, 17 Apr 2015 16:21:09 +0100 Subject: [PATCH 07/56] publish/docker: login should happen early This fixes an issue where base image which drone is using to build an image for publishing comes from a private repo. --- plugin/publish/docker.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/plugin/publish/docker.go b/plugin/publish/docker.go index 3ab7bdb88..3e9548a43 100644 --- a/plugin/publish/docker.go +++ b/plugin/publish/docker.go @@ -66,6 +66,21 @@ func (d *Docker) Write(f *buildfile.Buildfile) { d.DockerVersion + ".tgz |sudo tar zxf - -C /") } + // Export docker host once + f.WriteCmd("export DOCKER_HOST=" + d.DockerHost) + + // Login? + if d.RegistryLogin == true { + // If email is unspecified, pass in -e ' ' to avoid having + // registry URL interpreted as email, which will fail cryptically. + emailOpt := "' '" + if d.Email != "" { + emailOpt = d.Email + } + f.WriteCmdSilent(fmt.Sprintf("docker login -u %s -p %s -e %s %s", + d.Username, d.Password, emailOpt, d.RegistryLoginUrl)) + } + dockerPath := "." if len(d.Dockerfile) != 0 { dockerPath = fmt.Sprintf("- < %s", d.Dockerfile) @@ -86,24 +101,9 @@ func (d *Docker) Write(f *buildfile.Buildfile) { // There is always at least 1 tag buildImageTag := d.Tags[0] - // Export docker host once - f.WriteCmd("export DOCKER_HOST=" + d.DockerHost) - // Build the image f.WriteCmd(fmt.Sprintf("docker build --pull -t %s:%s %s", d.ImageName, buildImageTag, dockerPath)) - // Login? - if d.RegistryLogin == true { - // If email is unspecified, pass in -e ' ' to avoid having - // registry URL interpreted as email, which will fail cryptically. - emailOpt := "' '" - if d.Email != "" { - emailOpt = d.Email - } - f.WriteCmdSilent(fmt.Sprintf("docker login -u %s -p %s -e %s %s", - d.Username, d.Password, emailOpt, d.RegistryLoginUrl)) - } - // Tag and push all tags for _, tag := range d.Tags { if tag != buildImageTag { From 4b3eaec70c530d705b52016c82fc445a255b872c Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Sat, 25 Apr 2015 02:19:28 +0300 Subject: [PATCH 08/56] Since 7.10 token life unlimited --- plugin/remote/gitlab/gitlab.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index 984eed6b9..69b50b34f 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -268,7 +268,7 @@ func (r *Gitlab) OpenRegistration() bool { func (r *Gitlab) GetToken(user *model.User) (*model.Token, error) { expiry := time.Unix(user.TokenExpiry, 0) - if expiry.Sub(time.Now()) > (60 * time.Second) { + if user.TokenExpiry == 0 || expiry.Sub(time.Now()) > (60*time.Second) { return nil, nil } From 29b44015fd4d3d8589be33beabb1a55b23115e55 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Wed, 29 Apr 2015 03:05:16 +0300 Subject: [PATCH 09/56] Fix token problems at first login --- plugin/remote/gitlab/gitlab.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index 69b50b34f..f2e8834ce 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -268,7 +268,8 @@ func (r *Gitlab) OpenRegistration() bool { func (r *Gitlab) GetToken(user *model.User) (*model.Token, error) { expiry := time.Unix(user.TokenExpiry, 0) - if user.TokenExpiry == 0 || expiry.Sub(time.Now()) > (60*time.Second) { + if user.TokenExpiry == 0 && len(user.Access) != 0 || + expiry.Sub(time.Now()) > (60*time.Second) { return nil, nil } From 3ef752464c44ee20ad752990c1da10df331d9b72 Mon Sep 17 00:00:00 2001 From: Ian Neubert Date: Wed, 29 Apr 2015 09:16:05 -0700 Subject: [PATCH 10/56] Dockerfile: Set default database driver and source This will allow a default install to make use of the /var/lib/drone volume without having to set this manually. --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 0ec503c61..d42e98f47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,5 +13,7 @@ RUN apt-get -y install zip libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null RUN make docker deps build embed install EXPOSE 80 +ENV DRONE_DATABASE_DATASOURCE /var/lib/drone/drone.sqlite +ENV DRONE_DATABASE_DRIVER sqlite3 VOLUME ["/var/lib/drone"] ENTRYPOINT ["/usr/local/bin/droned"] From 5ad3ba5b8748f22750faed8574ff009bbc818ea6 Mon Sep 17 00:00:00 2001 From: Ke Zhu Date: Thu, 7 May 2015 15:25:00 -0400 Subject: [PATCH 11/56] correct README for github enterprise --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4632e1447..b4733563c 100644 --- a/README.md +++ b/README.md @@ -225,12 +225,18 @@ Homepage URL: http://localhost:8000/ ``` -Authorization callback URL: +Authorization callback URL for github.com: ``` http://localhost:8000/api/auth/github.com ``` +Authorization callback URL for GitHub Enterprise: + +``` +http://localhost:8000/api/auth/enterprise.github.com +``` + ## Build Configuration You will need to include a `.drone.yml` file in the root of your repository in order to From a5928aa57ebab74bb5edcd84a4ef55c27235065a Mon Sep 17 00:00:00 2001 From: "David M. Carr" Date: Thu, 14 May 2015 10:45:50 -0400 Subject: [PATCH 12/56] Add server parameter to hipchat configuration (#950) This allows compatibility with HipChat Server, the self-hosted version of the HipChat service. --- plugin/notify/hipchat.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin/notify/hipchat.go b/plugin/notify/hipchat.go index d1c70d76a..10591dadf 100644 --- a/plugin/notify/hipchat.go +++ b/plugin/notify/hipchat.go @@ -13,9 +13,11 @@ const ( startedMessage = "Building %s (%s) by %s
- %s" successMessage = "Success %s (%s) by %s" failureMessage = "Failed %s (%s) by %s" + defaultServer = "api.hipchat.com" ) type Hipchat struct { + Server string `yaml:"server,omitempty"` Room string `yaml:"room,omitempty"` Token string `yaml:"token,omitempty"` Started bool `yaml:"on_started,omitempty"` @@ -49,6 +51,7 @@ func (h *Hipchat) buildLink(context *model.Request) string { func (h *Hipchat) sendStarted(client HipchatClient, context *model.Request) error { msg := fmt.Sprintf(startedMessage, h.buildLink(context), context.Commit.Branch, context.Commit.Author, context.Commit.Message) req := HipchatMessageRequest{ + Server: h.Server, RoomId: h.Room, AuthToken: h.Token, Color: "yellow", @@ -61,6 +64,7 @@ func (h *Hipchat) sendStarted(client HipchatClient, context *model.Request) erro func (h *Hipchat) sendFailure(client HipchatClient, context *model.Request) error { msg := fmt.Sprintf(failureMessage, h.buildLink(context), context.Commit.Branch, context.Commit.Author) req := HipchatMessageRequest{ + Server: h.Server, RoomId: h.Room, AuthToken: h.Token, Color: "red", @@ -73,6 +77,7 @@ func (h *Hipchat) sendFailure(client HipchatClient, context *model.Request) erro func (h *Hipchat) sendSuccess(client HipchatClient, context *model.Request) error { msg := fmt.Sprintf(successMessage, h.buildLink(context), context.Commit.Branch, context.Commit.Author) req := HipchatMessageRequest{ + Server: h.Server, RoomId: h.Room, AuthToken: h.Token, Color: "green", @@ -89,6 +94,7 @@ type HipchatClient interface { } type HipchatMessageRequest struct { + Server string RoomId string Color string Message string @@ -99,7 +105,13 @@ type HipchatMessageRequest struct { type HipchatSimpleHTTPClient struct{} func (*HipchatSimpleHTTPClient) PostMessage(req HipchatMessageRequest) error { - hipchat_uri := fmt.Sprintf("https://api.hipchat.com/v2/room/%s/notification", req.RoomId) + var server string + if len(req.Server) > 0 { + server = req.Server + } else { + server = defaultServer + } + hipchat_uri := fmt.Sprintf("https://%s/v2/room/%s/notification", server, req.RoomId) _, err := http.PostForm(hipchat_uri, url.Values{ "color": {req.Color}, From 41a47bcb73f3b2c6bdb31e89a9ddf8fda13758b5 Mon Sep 17 00:00:00 2001 From: "David M. Carr" Date: Thu, 14 May 2015 11:49:55 -0400 Subject: [PATCH 13/56] Fix minor typo in remote.go --- plugin/remote/remote.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/remote/remote.go b/plugin/remote/remote.go index 862e8c15d..dd6c5acaa 100644 --- a/plugin/remote/remote.go +++ b/plugin/remote/remote.go @@ -7,7 +7,7 @@ import ( ) type Remote interface { - // Authorize handles authentication with thrid party remote systems, + // Authorize handles authentication with third party remote systems, // such as github or bitbucket, and returns user data. Authorize(w http.ResponseWriter, r *http.Request) (*model.Login, error) From 608377e17c0c61a5d87561fd65d5044c44c988f5 Mon Sep 17 00:00:00 2001 From: masarakki Date: Wed, 13 May 2015 00:37:20 +0900 Subject: [PATCH 14/56] enable to specify image with hostname --- shared/build/util.go | 5 ++++- shared/build/util_test.go | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/shared/build/util.go b/shared/build/util.go index 3829e99ea..e4b206706 100644 --- a/shared/build/util.go +++ b/shared/build/util.go @@ -68,7 +68,10 @@ func parseImageName(image string) (owner, name, tag string) { } parts := strings.Split(name, "/") - if len(parts) == 2 { + if len := len(parts); len == 3 { + owner = fmt.Sprintf("%s/%s", parts[0], parts[1]) + name = parts[2] + } else if len == 2 { owner = parts[0] name = parts[1] } diff --git a/shared/build/util_test.go b/shared/build/util_test.go index ae19b154c..7d5f8b6d2 100644 --- a/shared/build/util_test.go +++ b/shared/build/util_test.go @@ -15,6 +15,8 @@ func TestParseImageName(t *testing.T) { {"johnsmith", "redis", "latest", "johnsmith/redis"}, // image name with no owner specified {"bradrydzewski", "redis", "2.8", "redis:2.8"}, + // image name with hostname + {"docker.example.com/johnsmith", "redis", "latest", "docker.example.com/johnsmith/redis"}, // image name with ownly name specified {"bradrydzewski", "redis2", "latest", "redis2"}, // image name that is a known alias From 7d0175459977df104d14d8ec4defea4f99e5a846 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 4 Jun 2015 11:49:06 -0700 Subject: [PATCH 15/56] Upgrade dpkg in build image --- .drone.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index bc0d0d606..23e53c87c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,8 +7,7 @@ env: script: - sudo add-apt-repository ppa:git-core/ppa 1> /dev/null 2> /dev/null - sudo apt-get update 1> /dev/null 2> /dev/null - - sudo apt-get update 1> /dev/null 2> /dev/null - - sudo apt-get -y install git zip libsqlite3-dev sqlite3 rpm 1> /dev/null 2> /dev/null + - sudo apt-get -y install git zip libsqlite3-dev sqlite3 rpm dpkg 1> /dev/null 2> /dev/null - gem install fpm - rbenv rehash - make deps From d101ef3ed6e973b039c3fd5ccdec378b0fa8684c Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 7 Jun 2015 17:44:26 -0700 Subject: [PATCH 16/56] enable 0.4 yaml syntax for build --- .drone.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.drone.yml b/.drone.yml index 23e53c87c..13c4ea5e6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -41,3 +41,18 @@ publish: recursive: true when: owner: drone + + + + +# new build script for 0.4 branch + +build: + image: golang:1.4.2 + environment: + - GOPATH=/drone + commands: + - apt-get update 1> /dev/null 2> /dev/null + - apt-get -y install libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null + - make deps + - make test From d683418e8f1f261274d3c37c1b88680448fbccdd Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 7 Jun 2015 17:47:07 -0700 Subject: [PATCH 17/56] fetch go vet and go cover in yaml --- .drone.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.drone.yml b/.drone.yml index 13c4ea5e6..ddae90ac5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -54,5 +54,7 @@ build: commands: - apt-get update 1> /dev/null 2> /dev/null - apt-get -y install libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null + - go get golang.org/x/tools/cmd/vet + - go get golang.org/x/tools/cmd/cover - make deps - make test From cb28bcff376908d7362bce9f8b909ec267cbfa8b Mon Sep 17 00:00:00 2001 From: bdd Date: Mon, 8 Jun 2015 09:18:22 -0400 Subject: [PATCH 18/56] Lint pool.go Second value can be omitted from range. Loop is equivalent. --- server/worker/pool/pool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/worker/pool/pool.go b/server/worker/pool/pool.go index e2f3d91f6..070557468 100644 --- a/server/worker/pool/pool.go +++ b/server/worker/pool/pool.go @@ -64,7 +64,7 @@ func (p *Pool) List() []worker.Worker { defer p.Unlock() var workers []worker.Worker - for w, _ := range p.workers { + for w := range p.workers { workers = append(workers, w) } return workers From e087f820c2d7bde8e469cdd78204da8ad9bce289 Mon Sep 17 00:00:00 2001 From: Kevin Shen Date: Mon, 8 Jun 2015 11:43:21 -0700 Subject: [PATCH 19/56] shared/build/images.go: add go1.4 tag --- shared/build/images.go | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/build/images.go b/shared/build/images.go index bcd409fcb..4f0b7a1e4 100644 --- a/shared/build/images.go +++ b/shared/build/images.go @@ -198,6 +198,7 @@ var builders = map[string]*image{ "go1.1": {Tag: "bradrydzewski/go:1.1"}, "go1.2": {Tag: "bradrydzewski/go:1.2"}, "go1.3": {Tag: "bradrydzewski/go:1.3"}, + "go1.4": {Tag: "bradrydzewski/go:1.4"}, // Haskell build images "haskell": {Tag: "bradrydzewski/haskell:7.4"}, From 89942c6f95dacf782900c3853c0eff0dc186bb8f Mon Sep 17 00:00:00 2001 From: Bugagazavr Date: Tue, 9 Jun 2015 23:10:35 +0300 Subject: [PATCH 20/56] Fix self-signed certificates --- plugin/remote/gitlab/gitlab.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index f2e8834ce..314bb9998 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -56,7 +56,13 @@ func (r *Gitlab) Authorize(res http.ResponseWriter, req *http.Request) (*model.L return nil, fmt.Errorf("Error matching state in OAuth2 redirect") } - var trans = &oauth.Transport{Config: config} + var trans = &oauth.Transport{ + Config: config, + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: &tls.Config{InsecureSkipVerify: r.SkipVerify}, + }, + } var token, err = trans.Exchange(code) if err != nil { return nil, fmt.Errorf("Error exchanging token. %s", err) From 52c8622f59abad84a3cb28a1a70a71b23187d644 Mon Sep 17 00:00:00 2001 From: Ludovic Fauvet Date: Fri, 19 Jun 2015 16:58:49 +0200 Subject: [PATCH 21/56] slack: implement on_change --- plugin/notify/slack.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin/notify/slack.go b/plugin/notify/slack.go index 2aa175be4..1f65210ff 100644 --- a/plugin/notify/slack.go +++ b/plugin/notify/slack.go @@ -24,16 +24,21 @@ type Slack struct { Started bool `yaml:"on_started,omitempty"` Success bool `yaml:"on_success,omitempty"` Failure bool `yaml:"on_failure,omitempty"` + Change bool `yaml:"on_change,omitempty"` } func (s *Slack) Send(context *model.Request) error { switch { case context.Commit.Status == "Started" && s.Started: return s.sendStarted(context) - case context.Commit.Status == "Success" && s.Success: - return s.sendSuccess(context) - case context.Commit.Status == "Failure" && s.Failure: - return s.sendFailure(context) + case context.Commit.Status == "Success": + if s.Success || (s.Change && context.Prior.Status != context.Commit.Status) { + return s.sendSuccess(context) + } + case context.Commit.Status == "Failure": + if s.Failure || (s.Change && context.Prior.Status != context.Commit.Status) { + return s.sendFailure(context) + } } return nil From 28eb92be9ee5af345a7431c4fa79875e0cab9f03 Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Sat, 20 Jun 2015 21:34:46 +0900 Subject: [PATCH 22/56] Correct VolumesFrom definition Fixes #1068 . --- shared/build/docker/structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/build/docker/structs.go b/shared/build/docker/structs.go index d30282f9c..0d3388999 100644 --- a/shared/build/docker/structs.go +++ b/shared/build/docker/structs.go @@ -133,7 +133,7 @@ type Config struct { Dns []string Image string // Name of the image as it was passed by the operator (eg. could be symbolic) Volumes map[string]struct{} - VolumesFrom string + VolumesFrom []string WorkingDir string Entrypoint []string NetworkDisabled bool From 0a028e3bd293bceb56b4177f77d07ba2ab582193 Mon Sep 17 00:00:00 2001 From: David Windell Date: Tue, 23 Jun 2015 21:59:45 +0100 Subject: [PATCH 23/56] Remove docker target from Dockerfile Fixes failing builds --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0ec503c61..95d563c95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ WORKDIR /gopath/src/github.com/drone/drone RUN apt-get update RUN apt-get -y install zip libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null -RUN make docker deps build embed install +RUN make deps build embed install EXPOSE 80 VOLUME ["/var/lib/drone"] From 20693cd38d13ffab2e391a467582b0cc98140bfb Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 2 Jul 2015 14:50:17 -0700 Subject: [PATCH 24/56] Enable pseudo tty setting --- shared/build/script/docker.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shared/build/script/docker.go b/shared/build/script/docker.go index 185c293e0..c06e9e4d2 100644 --- a/shared/build/script/docker.go +++ b/shared/build/script/docker.go @@ -14,6 +14,9 @@ type Docker struct { // Hostname (also known as `--hostname` option) // Could be set only if Docker is running in privileged mode Hostname *string `yaml:"hostname,omitempty"` + + // Allocate a pseudo-TTY (also known as `--tty` option) + TTY bool `yaml:"tty,omitempty"` } // DockerNetworkMode returns DefaultNetworkMode @@ -37,3 +40,12 @@ func DockerHostname(d *Docker) string { } return *d.Hostname } + +// DockerTty returns true if the build +// should allocate a pseudo tty +func DockerTty(d *Docker) string { + if d == nil { + return false + } + return d.TTY +} From fc0d37f881b90aa9db1138369b6388acdbde517a Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 2 Jul 2015 15:10:34 -0700 Subject: [PATCH 25/56] added tty flag --- shared/build/build.go | 1 + shared/build/script/docker.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/shared/build/build.go b/shared/build/build.go index cb2f60fa6..0a0265ab4 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -322,6 +322,7 @@ func (b *Builder) run() error { AttachStdin: false, AttachStdout: true, AttachStderr: true, + Tty: script.DockerTty(b.Build.Docker), } // configure if Docker should run in privileged mode diff --git a/shared/build/script/docker.go b/shared/build/script/docker.go index c06e9e4d2..a61967922 100644 --- a/shared/build/script/docker.go +++ b/shared/build/script/docker.go @@ -43,7 +43,7 @@ func DockerHostname(d *Docker) string { // DockerTty returns true if the build // should allocate a pseudo tty -func DockerTty(d *Docker) string { +func DockerTty(d *Docker) bool { if d == nil { return false } From defd4fbb771c8489f879c164b1860eda57dda2fd Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 5 Jul 2015 22:06:54 -0300 Subject: [PATCH 26/56] small typo fix --- server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.go b/server/main.go index bd5e0bca6..d45b2d39b 100644 --- a/server/main.go +++ b/server/main.go @@ -34,7 +34,7 @@ import ( ) const ( - DockerTLSWarning = `WARINING: Docker TLS cert or key not given, this may cause a build errors` + DockerTLSWarning = `WARNING: Docker TLS cert or key not given, this may cause a build errors` ) var ( From cf578b31cc217682b0bd1447566833e486d3844a Mon Sep 17 00:00:00 2001 From: Ke Zhu Date: Tue, 14 Jul 2015 16:38:10 -0400 Subject: [PATCH 27/56] move privileged to yaml file --- shared/build/build.go | 2 +- shared/build/build_test.go | 22 +++++++++++----------- shared/build/script/docker.go | 13 +++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/shared/build/build.go b/shared/build/build.go index 0a0265ab4..b37f032dc 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -327,7 +327,7 @@ func (b *Builder) run() error { // configure if Docker should run in privileged mode host := docker.HostConfig{ - Privileged: (b.Privileged && len(b.Repo.PR) == 0), + Privileged: (b.Privileged && script.DockerPrivileged(b.Build.Docker)), } if host.Privileged { diff --git a/shared/build/build_test.go b/shared/build/build_test.go index 636fff442..b00d464e6 100644 --- a/shared/build/build_test.go +++ b/shared/build/build_test.go @@ -412,21 +412,21 @@ func TestRunPrivileged(t *testing.T) { t.Errorf("Expected container NOT started in Privileged mode") } - // now lets set priviliged mode + // now lets try to enable priviliged mode b.Privileged = true b.run() - if conf.Privileged != true { - t.Errorf("Expected container IS started in Privileged mode") - } - - // now lets set priviliged mode but for a pull request - b.Privileged = true - b.Repo.PR = "55" - b.run() - if conf.Privileged != false { - t.Errorf("Expected container NOT started in Privileged mode when PR") + t.Errorf("Expected container NOT started in Privileged mode when no setup in build script") + } + + // now lets set priviliged mode in build script + b.Privileged = true + b.Build = &script.Build{Docker: &script.Docker{Privileged: true}} + b.run() + + if conf.Privileged != true { + t.Errorf("Expected container IS started in Privileged mode when setup privileged mode in build script") } } diff --git a/shared/build/script/docker.go b/shared/build/script/docker.go index a61967922..d2a9ad665 100644 --- a/shared/build/script/docker.go +++ b/shared/build/script/docker.go @@ -17,6 +17,10 @@ type Docker struct { // Allocate a pseudo-TTY (also known as `--tty` option) TTY bool `yaml:"tty,omitempty"` + + // Privileged means enabling all devices on the host in container + // (also known as `--privileged=true` option) + Privileged bool `yaml:"privileged,omitempty"` } // DockerNetworkMode returns DefaultNetworkMode @@ -49,3 +53,12 @@ func DockerTty(d *Docker) bool { } return d.TTY } + +// DockerPrivileged returns true if the build +// should have privileged mode +func DockerPrivileged(d *Docker) bool { + if d == nil { + return false + } + return d.Privileged +} From 0ef85cbabc6667cf25a19ff7c769dabc0c42330f Mon Sep 17 00:00:00 2001 From: Ke Zhu Date: Thu, 16 Jul 2015 10:42:34 -0400 Subject: [PATCH 28/56] trusts builds from private repo and non-PR --- server/worker/docker/docker.go | 35 ++++++++++++++--------------- shared/build/build.go | 2 +- shared/build/build_test.go | 40 ++++++++++++++++++++++++---------- shared/build/repo/repo.go | 8 +++++++ shared/build/repo/repo_test.go | 20 +++++++++++++++++ shared/build/script/docker.go | 15 +------------ 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/server/worker/docker/docker.go b/server/worker/docker/docker.go index 4f497fcee..b2eda0c74 100644 --- a/server/worker/docker/docker.go +++ b/server/worker/docker/docker.go @@ -102,15 +102,6 @@ func (d *Docker) Do(c context.Context, r *worker.Work) { log.Printf("Error parsing YAML for %s/%s, Err: %s", r.Repo.Owner, r.Repo.Name, err.Error()) } - // append private parameters to the environment - // variable section of the .drone.yml file, iff - // this is not a pull request (for security purposes) - if params != nil && (r.Repo.Private || len(r.Commit.PullRequest) == 0) { - for k, v := range params { - script.Env = append(script.Env, k+"="+v) - } - } - // TODO: handle error better? buildNumber, err := datastore.GetBuildNumber(c, r.Commit) if err != nil { @@ -121,13 +112,23 @@ func (d *Docker) Do(c context.Context, r *worker.Work) { path := r.Repo.Host + "/" + r.Repo.Owner + "/" + r.Repo.Name repo := &repo.Repo{ - Name: path, - Path: r.Repo.CloneURL, - Branch: r.Commit.Branch, - Commit: r.Commit.Sha, - PR: r.Commit.PullRequest, - Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)), - Depth: git.GitDepth(script.Git), + Name: path, + Path: r.Repo.CloneURL, + Branch: r.Commit.Branch, + Commit: r.Commit.Sha, + PR: r.Commit.PullRequest, + Private: r.Repo.Private, + Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)), + Depth: git.GitDepth(script.Git), + } + + // append private parameters to the environment + // variable section of the .drone.yml file, if + // this is trusted + if params != nil && repo.IsTrusted() { + for k, v := range params { + script.Env = append(script.Env, k+"="+v) + } } priorCommit, _ := datastore.GetCommitPrior(c, r.Commit) @@ -152,7 +153,7 @@ func (d *Docker) Do(c context.Context, r *worker.Work) { builder.Timeout = time.Duration(r.Repo.Timeout) * time.Second builder.Privileged = r.Repo.Privileged - if r.Repo.Private || len(r.Commit.PullRequest) == 0 { + if repo.IsTrusted() { builder.Key = []byte(r.Repo.PrivateKey) } diff --git a/shared/build/build.go b/shared/build/build.go index b37f032dc..37433c6af 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -327,7 +327,7 @@ func (b *Builder) run() error { // configure if Docker should run in privileged mode host := docker.HostConfig{ - Privileged: (b.Privileged && script.DockerPrivileged(b.Build.Docker)), + Privileged: (b.Privileged && b.Repo.IsTrusted()), } if host.Privileged { diff --git a/shared/build/build_test.go b/shared/build/build_test.go index b00d464e6..cc9bcf152 100644 --- a/shared/build/build_test.go +++ b/shared/build/build_test.go @@ -412,21 +412,39 @@ func TestRunPrivileged(t *testing.T) { t.Errorf("Expected container NOT started in Privileged mode") } - // now lets try to enable priviliged mode + // now lets set priviliged mode b.Privileged = true b.run() - if conf.Privileged != false { - t.Errorf("Expected container NOT started in Privileged mode when no setup in build script") - } - - // now lets set priviliged mode in build script - b.Privileged = true - b.Build = &script.Build{Docker: &script.Docker{Privileged: true}} - b.run() - if conf.Privileged != true { - t.Errorf("Expected container IS started in Privileged mode when setup privileged mode in build script") + t.Errorf("Expected container IS started in Privileged mode") + } + + // now lets set priviliged mode but for a pull request + b.Privileged = true + b.Repo.PR = "55" + b.run() + + if conf.Privileged != false { + t.Errorf("Expected container NOT started in Privileged mode when PR") + } + + // now lets set priviliged mode for a pull request from public repo + b.Privileged = true + b.Repo.Private = false + b.run() + + if conf.Privileged != false { + t.Errorf("Expected container NOT started in Privileged mode when PR from public repo") + } + + // now lets set priviliged mode for a pull request from private repo + b.Privileged = true + b.Repo.Private = true + b.run() + + if conf.Privileged != true { + t.Errorf("Expected container started in Privileged mode when PR from private repo") } } diff --git a/shared/build/repo/repo.go b/shared/build/repo/repo.go index 82973efa1..01daa073c 100644 --- a/shared/build/repo/repo.go +++ b/shared/build/repo/repo.go @@ -33,6 +33,9 @@ type Repo struct { // checkout when the Repository is cloned. PR string + // Private specifies if a git repo is private or not + Private bool + // (optional) The filesystem path that the repository // will be cloned into (or copied to) inside the // host system (Docker Container). @@ -125,3 +128,8 @@ func (r *Repo) Commands() []string { return cmds } + +// IsTrusted returns if a repo is trusted to run under privileged mode +func (r *Repo) IsTrusted() bool { + return r.Private || len(r.PR) == 0 +} diff --git a/shared/build/repo/repo_test.go b/shared/build/repo/repo_test.go index b8f4d54ef..972cd30af 100644 --- a/shared/build/repo/repo_test.go +++ b/shared/build/repo/repo_test.go @@ -52,3 +52,23 @@ func TestIsGit(t *testing.T) { } } } + +func TestIsTrusted(t *testing.T) { + repos := []struct { + private bool + PR string + trusted bool + }{ + {true, "1", true}, + {false, "1", false}, + {true, "", true}, + {false, "", true}, + } + + for _, r := range repos { + repo := Repo{Private: r.private, PR: r.PR} + if trusted := repo.IsTrusted(); trusted != r.trusted { + t.Errorf("IsTrusted was %v, expected %v", trusted, r.trusted) + } + } +} diff --git a/shared/build/script/docker.go b/shared/build/script/docker.go index d2a9ad665..329d5ab60 100644 --- a/shared/build/script/docker.go +++ b/shared/build/script/docker.go @@ -17,10 +17,6 @@ type Docker struct { // Allocate a pseudo-TTY (also known as `--tty` option) TTY bool `yaml:"tty,omitempty"` - - // Privileged means enabling all devices on the host in container - // (also known as `--privileged=true` option) - Privileged bool `yaml:"privileged,omitempty"` } // DockerNetworkMode returns DefaultNetworkMode @@ -34,7 +30,7 @@ func DockerNetworkMode(d *Docker) string { return *d.NetworkMode } -// DockerNetworkMode returns empty string +// DockerHostname returns empty string // when Docker.NetworkMode is empty. // DockerNetworkMode returns Docker.NetworkMode // when it is not empty. @@ -53,12 +49,3 @@ func DockerTty(d *Docker) bool { } return d.TTY } - -// DockerPrivileged returns true if the build -// should have privileged mode -func DockerPrivileged(d *Docker) bool { - if d == nil { - return false - } - return d.Privileged -} From 420131d3fa9f233978dc9fcbecbb14bb7f272a9a Mon Sep 17 00:00:00 2001 From: Richard Julien Date: Sun, 19 Jul 2015 01:19:32 +0200 Subject: [PATCH 29/56] Force worker directory to use slash. Needed to use Drone on windows --- server/worker/docker/docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/worker/docker/docker.go b/server/worker/docker/docker.go index b2eda0c74..b428dc8ff 100644 --- a/server/worker/docker/docker.go +++ b/server/worker/docker/docker.go @@ -118,7 +118,7 @@ func (d *Docker) Do(c context.Context, r *worker.Work) { Commit: r.Commit.Sha, PR: r.Commit.PullRequest, Private: r.Repo.Private, - Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)), + Dir: filepath.ToSlash(filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path))), Depth: git.GitDepth(script.Git), } From 697fa8bf79997acf19ae87ffb6238bd5ab88bece Mon Sep 17 00:00:00 2001 From: Richard Julien Date: Sun, 19 Jul 2015 10:44:53 +0200 Subject: [PATCH 30/56] Ignore IDEA files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6c837086d..af9770b10 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ cli/cli client/client server/server packaging/root/usr/local +.idea/ +*.iml From a561896af19f95a481ac9fbc08ddc1a8391c7d2b Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Sun, 19 Jul 2015 10:51:24 -0500 Subject: [PATCH 31/56] Change docker version to v1.12 from invalid v1.9 --- shared/build/build_test.go | 56 +++++++++++++++++------------------ shared/build/docker/client.go | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/shared/build/build_test.go b/shared/build/build_test.go index cc9bcf152..2367202a5 100644 --- a/shared/build/build_test.go +++ b/shared/build/build_test.go @@ -55,14 +55,14 @@ func TestSetup(t *testing.T) { // Handles a request to inspect the Go 1.2 image // This will return a dummy image ID, so that the system knows // the build image exists, and doens't need to be downloaded. - mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) { body := `[{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }]` w.Write([]byte(body)) }) // Handles a request to create the build image, with the build // script injected. This will return a dummy stream. - mux.HandleFunc("/v1.9/build", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/build", func(w http.ResponseWriter, r *http.Request) { body := `{"stream":"Step 1..."}` w.Write([]byte(body)) }) @@ -71,7 +71,7 @@ func TestSetup(t *testing.T) { // that we are doing a "wildcard" url match here, since the name of // the image will be random. This will return a dummy image ID // to confirm the build image was created successfully. - mux.HandleFunc("/v1.9/images/", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/", func(w http.ResponseWriter, r *http.Request) { body := `{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }` w.Write([]byte(body)) }) @@ -122,7 +122,7 @@ func TestSetupErrorPullImage(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) }) @@ -134,12 +134,12 @@ func TestSetupErrorRunDaemonPorts(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { data := []byte(`{"config": { "ExposedPorts": { "6379/tcp": {}}}}`) w.Write(data) }) - mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/create", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -164,21 +164,21 @@ func TestSetupErrorServiceInspect(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { data := []byte(`{"config": { "ExposedPorts": { "6379/tcp": {}}}}`) w.Write(data) }) - mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/create", func(w http.ResponseWriter, r *http.Request) { body := `{ "Id":"e90e34656806", "Warnings":[] }` w.Write([]byte(body)) }) - mux.HandleFunc("/v1.9/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) }) - mux.HandleFunc("/v1.9/containers/e90e34656806/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/e90e34656806/json", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -202,11 +202,11 @@ func TestSetupErrorImagePull(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/mysql:5.5/json", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) }) - mux.HandleFunc("/v1.9/images/create?fromImage=bradrydzewski/mysql&tag=5.5", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/create?fromImage=bradrydzewski/mysql&tag=5.5", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -230,7 +230,7 @@ func TestSetupErrorUpdate(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/create", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/create", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -254,12 +254,12 @@ func TestSetupErrorBuild(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) { body := `[{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }]` w.Write([]byte(body)) }) - mux.HandleFunc("/v1.9/build", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/build", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -284,17 +284,17 @@ func TestSetupErrorBuildInspect(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/bradrydzewski/go:1.2/json", func(w http.ResponseWriter, r *http.Request) { body := `[{ "id": "7bf9ce0ffb7236ca68da0f9fed0e1682053b393db3c724ff3c5a4e8c0793b34c" }]` w.Write([]byte(body)) }) - mux.HandleFunc("/v1.9/build", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/build", func(w http.ResponseWriter, r *http.Request) { body := `{"stream":"Step 1..."}` w.Write([]byte(body)) }) - mux.HandleFunc("/v1.9/images/", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -325,27 +325,27 @@ func TestTeardown(t *testing.T) { imageRemoved = false ) - mux.HandleFunc("/v1.9/containers/7bf9ce0ffb/stop", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/7bf9ce0ffb/stop", func(w http.ResponseWriter, r *http.Request) { containerStopped = true w.WriteHeader(http.StatusOK) }) - mux.HandleFunc("/v1.9/containers/7bf9ce0ffb", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/7bf9ce0ffb", func(w http.ResponseWriter, r *http.Request) { containerRemoved = true w.WriteHeader(http.StatusOK) }) - mux.HandleFunc("/v1.9/containers/ec62dcc736/stop", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/ec62dcc736/stop", func(w http.ResponseWriter, r *http.Request) { serviceStopped = true w.WriteHeader(http.StatusOK) }) - mux.HandleFunc("/v1.9/containers/ec62dcc736", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/ec62dcc736", func(w http.ResponseWriter, r *http.Request) { serviceRemoved = true w.WriteHeader(http.StatusOK) }) - mux.HandleFunc("/v1.9/images/c3ab8ff137", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/images/c3ab8ff137", func(w http.ResponseWriter, r *http.Request) { imageRemoved = true w.Write([]byte(`[{"Untagged":"c3ab8ff137"},{"Deleted":"c3ab8ff137"}]`)) }) @@ -389,12 +389,12 @@ func TestRunPrivileged(t *testing.T) { var conf = docker.HostConfig{} - mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/create", func(w http.ResponseWriter, r *http.Request) { body := `{ "Id":"e90e34656806", "Warnings":[] }` w.Write([]byte(body)) }) - mux.HandleFunc("/v1.9/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) { json.NewDecoder(r.Body).Decode(&conf) w.WriteHeader(http.StatusBadRequest) }) @@ -452,7 +452,7 @@ func TestRunErrorCreate(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/create", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) }) @@ -477,13 +477,13 @@ func TestRunErrorStart(t *testing.T) { containerStarted = false ) - mux.HandleFunc("/v1.9/containers/create", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/create", func(w http.ResponseWriter, r *http.Request) { containerCreated = true body := `{ "Id":"e90e34656806", "Warnings":[] }` w.Write([]byte(body)) }) - mux.HandleFunc("/v1.9/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/v1.12/containers/e90e34656806/start", func(w http.ResponseWriter, r *http.Request) { containerStarted = true w.WriteHeader(http.StatusBadRequest) }) diff --git a/shared/build/docker/client.go b/shared/build/docker/client.go index 6dd33213e..8dd1b0d12 100644 --- a/shared/build/docker/client.go +++ b/shared/build/docker/client.go @@ -21,7 +21,7 @@ import ( ) const ( - APIVERSION = 1.9 + APIVERSION = 1.12 DEFAULTHTTPPORT = 2375 DEFAULTUNIXSOCKET = "/var/run/docker.sock" DEFAULTPROTOCOL = "unix" From ada0c19259649e512270b0fa650ebc22e6f40b3c Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 22 Jul 2015 12:59:21 -0700 Subject: [PATCH 32/56] adding logging to hook --- server/handler/hook.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/handler/hook.go b/server/handler/hook.go index 1b46ceb20..f2f2860a4 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -35,6 +35,7 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { // parse the hook payload hook, err := remote.ParseHook(r) if err != nil { + log.Printf("Unable to parse hook. %s\n", err) w.WriteHeader(http.StatusBadRequest) return } @@ -84,6 +85,7 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { user.TokenExpiry = user_token.Expiry datastore.PutUser(ctx, user) } else if err != nil { + log.Printf("Unable to refresh token. %s\n", err) w.WriteHeader(http.StatusBadRequest) return } @@ -91,6 +93,7 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { // featch the .drone.yml file from the database yml, err := remote.GetScript(user, repo, hook) if err != nil { + log.Printf("Unable to fetch .drone.yml file. %s\n", err) w.WriteHeader(http.StatusBadRequest) return } @@ -118,12 +121,14 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { // inserts the commit into the database if err := datastore.PostCommit(ctx, &commit); err != nil { + log.Printf("Unable to persist commit. %s\n", err) w.WriteHeader(http.StatusBadRequest) return } owner, err := datastore.GetUser(ctx, repo.UserID) if err != nil { + log.Printf("Unable to retrieve repository owner. %s.\n", err) w.WriteHeader(http.StatusBadRequest) return } From a612493f58548596812e180ca4b1f8fbb0e08b22 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 22 Jul 2015 13:12:37 -0700 Subject: [PATCH 33/56] Include Sha / Branch in hook logs --- server/handler/hook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handler/hook.go b/server/handler/hook.go index f2f2860a4..8ac4d4c13 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -121,7 +121,7 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { // inserts the commit into the database if err := datastore.PostCommit(ctx, &commit); err != nil { - log.Printf("Unable to persist commit. %s\n", err) + log.Printf("Unable to persist commit %s@%s. %s\n", commit.Sha, commit.Branch, err) w.WriteHeader(http.StatusBadRequest) return } From c9b8e011f5208791e653f6fe1b04d5c02fe00c03 Mon Sep 17 00:00:00 2001 From: bdd Date: Mon, 8 Jun 2015 09:18:22 -0400 Subject: [PATCH 34/56] Lint pool.go Second value can be omitted from range. Loop is equivalent. --- server/worker/pool/pool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/worker/pool/pool.go b/server/worker/pool/pool.go index e2f3d91f6..070557468 100644 --- a/server/worker/pool/pool.go +++ b/server/worker/pool/pool.go @@ -64,7 +64,7 @@ func (p *Pool) List() []worker.Worker { defer p.Unlock() var workers []worker.Worker - for w, _ := range p.workers { + for w := range p.workers { workers = append(workers, w) } return workers From eb1af7162cdfb939ef3b45a494a29498bf6e2ed3 Mon Sep 17 00:00:00 2001 From: David Windell Date: Tue, 23 Jun 2015 21:59:45 +0100 Subject: [PATCH 35/56] Remove docker target from Dockerfile Fixes failing builds --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0ec503c61..95d563c95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ WORKDIR /gopath/src/github.com/drone/drone RUN apt-get update RUN apt-get -y install zip libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null -RUN make docker deps build embed install +RUN make deps build embed install EXPOSE 80 VOLUME ["/var/lib/drone"] From e39b89957d64bc82184182c965bba0ca74ac8dda Mon Sep 17 00:00:00 2001 From: Kohei Suzuki Date: Sat, 20 Jun 2015 21:34:46 +0900 Subject: [PATCH 36/56] Correct VolumesFrom definition Fixes #1068 . --- shared/build/docker/structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/build/docker/structs.go b/shared/build/docker/structs.go index d30282f9c..0d3388999 100644 --- a/shared/build/docker/structs.go +++ b/shared/build/docker/structs.go @@ -133,7 +133,7 @@ type Config struct { Dns []string Image string // Name of the image as it was passed by the operator (eg. could be symbolic) Volumes map[string]struct{} - VolumesFrom string + VolumesFrom []string WorkingDir string Entrypoint []string NetworkDisabled bool From c13685c9a3cd4f594a32ceae3b6dffaf419c6059 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 2 Jul 2015 14:50:17 -0700 Subject: [PATCH 37/56] Enable pseudo tty setting --- shared/build/script/docker.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shared/build/script/docker.go b/shared/build/script/docker.go index 185c293e0..c06e9e4d2 100644 --- a/shared/build/script/docker.go +++ b/shared/build/script/docker.go @@ -14,6 +14,9 @@ type Docker struct { // Hostname (also known as `--hostname` option) // Could be set only if Docker is running in privileged mode Hostname *string `yaml:"hostname,omitempty"` + + // Allocate a pseudo-TTY (also known as `--tty` option) + TTY bool `yaml:"tty,omitempty"` } // DockerNetworkMode returns DefaultNetworkMode @@ -37,3 +40,12 @@ func DockerHostname(d *Docker) string { } return *d.Hostname } + +// DockerTty returns true if the build +// should allocate a pseudo tty +func DockerTty(d *Docker) string { + if d == nil { + return false + } + return d.TTY +} From 80e8b01f243dbc9913c417eb6dcbd4eaee9dceea Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 2 Jul 2015 15:10:34 -0700 Subject: [PATCH 38/56] added tty flag --- shared/build/build.go | 1 + shared/build/script/docker.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/shared/build/build.go b/shared/build/build.go index cb2f60fa6..0a0265ab4 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -322,6 +322,7 @@ func (b *Builder) run() error { AttachStdin: false, AttachStdout: true, AttachStderr: true, + Tty: script.DockerTty(b.Build.Docker), } // configure if Docker should run in privileged mode diff --git a/shared/build/script/docker.go b/shared/build/script/docker.go index c06e9e4d2..a61967922 100644 --- a/shared/build/script/docker.go +++ b/shared/build/script/docker.go @@ -43,7 +43,7 @@ func DockerHostname(d *Docker) string { // DockerTty returns true if the build // should allocate a pseudo tty -func DockerTty(d *Docker) string { +func DockerTty(d *Docker) bool { if d == nil { return false } From 4bcf83bcd0e6dcd84ad5ab661f11527ffef74cc8 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 5 Jul 2015 22:06:54 -0300 Subject: [PATCH 39/56] small typo fix --- server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.go b/server/main.go index bd5e0bca6..d45b2d39b 100644 --- a/server/main.go +++ b/server/main.go @@ -34,7 +34,7 @@ import ( ) const ( - DockerTLSWarning = `WARINING: Docker TLS cert or key not given, this may cause a build errors` + DockerTLSWarning = `WARNING: Docker TLS cert or key not given, this may cause a build errors` ) var ( From b5ce379941e21cd8983e2f9547d5ca52c3bb8f3a Mon Sep 17 00:00:00 2001 From: Dwayne Jones Date: Thu, 30 Jul 2015 16:58:33 -0400 Subject: [PATCH 40/56] Start of plugin --- plugin/deploy/deployment.go | 5 ++++ plugin/deploy/marathon/marathon.go | 39 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 plugin/deploy/marathon/marathon.go diff --git a/plugin/deploy/deployment.go b/plugin/deploy/deployment.go index 198c71a27..20c19c09f 100644 --- a/plugin/deploy/deployment.go +++ b/plugin/deploy/deployment.go @@ -8,6 +8,7 @@ import ( "github.com/drone/drone/plugin/deploy/deis" "github.com/drone/drone/plugin/deploy/git" "github.com/drone/drone/plugin/deploy/heroku" + "github.com/drone/drone/plugin/deploy/marathon" "github.com/drone/drone/plugin/deploy/modulus" "github.com/drone/drone/plugin/deploy/nodejitsu" "github.com/drone/drone/plugin/deploy/tsuru" @@ -26,6 +27,7 @@ type Deploy struct { SSH *SSH `yaml:"ssh,omitempty"` Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` Bash *Bash `yaml:"bash,omitempty"` + Marathon *marathon.Marathon `yaml:"marathon,omitempty"` } func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) { @@ -57,6 +59,9 @@ func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) { if d.Bash != nil && match(d.Bash.GetCondition(), r) { d.Bash.Write(f) } + if d.Marathon != nil && match(d.Marathon.GetCondition(), r) { + d.Marathon.Write(f) + } } func match(c *condition.Condition, r *repo.Repo) bool { diff --git a/plugin/deploy/marathon/marathon.go b/plugin/deploy/marathon/marathon.go new file mode 100644 index 000000000..b55000a68 --- /dev/null +++ b/plugin/deploy/marathon/marathon.go @@ -0,0 +1,39 @@ +package marathon + +import ( + "fmt" + + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +type Marathon struct { + //Hostname for the Marathon Master + Host string `yaml:"host,omitempty"` + + // The app config for marathon + //https://mesosphere.github.io/marathon/docs/rest-api.html#post-v2-apps + // Examples: + // /path/to/file + // /path/to/*.txt + // /path/to/*/*.txt + // /path/to/** + ConfigFile string `yaml:"config_file,omitempty"` + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (m *Marathon) Write(f *buildfile.Buildfile) { + // debugging purposes so we can see if / where something is failing + f.WriteCmdSilent("echo 'deploying to Marathon ...'") + + post := fmt.Sprintf( + "curl -X POST -d @%s http://%s/v2/apps --header \"Content-Type:application/json\"", + m.ConfigFile, + m.Host, + ) + f.WriteCmdSilent(post) +} + +func (m *Marathon) GetCondition() *condition.Condition { + return m.Condition +} From bf6c855810e657421cb5f46943e5e96085c5c16e Mon Sep 17 00:00:00 2001 From: Wei Zhao Date: Mon, 3 Aug 2015 19:03:26 +0800 Subject: [PATCH 41/56] Fix typo "fetch" --- server/handler/hook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handler/hook.go b/server/handler/hook.go index 1b46ceb20..28b39a9a8 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -88,7 +88,7 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { return } - // featch the .drone.yml file from the database + // fetch the .drone.yml file from the database yml, err := remote.GetScript(user, repo, hook) if err != nil { w.WriteHeader(http.StatusBadRequest) From 83d78f683052ed526192a2b32a2c95f280ec6626 Mon Sep 17 00:00:00 2001 From: Bugagazavr Date: Mon, 10 Aug 2015 10:20:58 +0300 Subject: [PATCH 42/56] Probe for push tag events --- plugin/remote/gitlab/gitlab.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index 314bb9998..cf2686c0b 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -184,7 +184,7 @@ func (r *Gitlab) Activate(user *model.User, repo *model.Repo, link string) error link += "?owner=" + repo.Owner + "&name=" + repo.Name // add the hook - return client.AddProjectHook(path, link, true, false, true) + return client.AddProjectHook(path, link, true, false, true, false) } // Deactivate removes a repository by removing all the post-commit hooks From f21d503d2c1483dcde4b9f4aa7a030fbdc40bd58 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 12 Aug 2015 11:52:21 +0200 Subject: [PATCH 43/56] =?UTF-8?q?Allow=20any=20case/seq=20to=20be=20used?= =?UTF-8?q?=20for=20=E2=80=9C[CI=20SKIP]=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eg. [ci skip] [skipci] [skip ci] [CI SKIP] --- server/handler/hook.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/handler/hook.go b/server/handler/hook.go index 8ac4d4c13..a79fb4653 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -3,6 +3,7 @@ package handler import ( "log" "net/http" + "regexp" "strings" "github.com/drone/drone/plugin/remote" @@ -43,7 +44,8 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { // in some cases we have neither a hook nor error. An example // would be GitHub sending a ping request to the URL, in which // case we'll just exit quiely with an 'OK' - if hook == nil || strings.Contains(hook.Message, "[CI SKIP]") { + shouldSkip, _ := regexp.MatchString(`\[(?i:ci *skip|skip *ci)\]`, hook.Message) + if hook == nil || shouldSkip { w.WriteHeader(http.StatusOK) return } From d485a8a43708c8b3e339ef9378886fe71472126e Mon Sep 17 00:00:00 2001 From: letusfly85 Date: Fri, 14 Aug 2015 08:27:39 +0000 Subject: [PATCH 44/56] remove unused import --- server/handler/hook.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/handler/hook.go b/server/handler/hook.go index 553c3bb89..e052fc543 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -4,7 +4,6 @@ import ( "log" "net/http" "regexp" - "strings" "github.com/drone/drone/plugin/remote" "github.com/drone/drone/server/datastore" From 381c6d0782d8ba39f1fcd11787193b5692616363 Mon Sep 17 00:00:00 2001 From: Kpacha Date: Sun, 16 Aug 2015 18:35:33 +0200 Subject: [PATCH 45/56] send build status updates to gitlab as comments on the related commit --- plugin/notify/gitlab.go | 134 ++++++++++++++++++++++++++++++++++ plugin/notify/gitlab_test.go | 107 +++++++++++++++++++++++++++ plugin/notify/notification.go | 9 +++ 3 files changed, 250 insertions(+) create mode 100644 plugin/notify/gitlab.go create mode 100644 plugin/notify/gitlab_test.go diff --git a/plugin/notify/gitlab.go b/plugin/notify/gitlab.go new file mode 100644 index 000000000..92cb25c2c --- /dev/null +++ b/plugin/notify/gitlab.go @@ -0,0 +1,134 @@ +package notify + +import ( + "fmt" + "strconv" + + "github.com/Bugagazavr/go-gitlab-client" + "github.com/drone/drone/plugin/remote/gitlab" + "github.com/drone/drone/shared/model" +) + +type Gitlab struct { + SkipVerify bool `yaml:"skip_verify,omitempty"` + Started bool `yaml:"on_started,omitempty"` + Success bool `yaml:"on_success,omitempty"` + Failure bool `yaml:"on_failure,omitempty"` +} + +type GitlabClient interface { + SendRepoCommitComment(id string, sha string, body string) (*gogitlab.CommitComment, error) +} + +const ( + StatusPending = ":raised_hand:" + StatusSuccess = ":thumbsup:" + StatusFailure = ":thumbsdown:" + StatusError = ":exclamation:" +) + +const ( + DescPending = "this build is pending" + DescSuccess = "the build was successful" + DescFailure = "the build failed" + DescError = "oops, something went wrong" +) + +const ( + PRMasterBranch = "master" + PRBadToMerge = " -> bad to merge" + PRGoodToMerge = " -> good to merge" +) + +// Send uses the Gitlab repository API to comment the commit +func (g *Gitlab) Send(context *model.Request) error { + if !g.isRequested(context) { + return nil + } + + return g.send( + context, + gitlab.NewClient(fmt.Sprintf("http://%s", context.Repo.Host), context.User.Access, g.SkipVerify), + ) +} + +func (g *Gitlab) isRequested(context *model.Request) bool { + if context.Repo.Remote != model.RemoteGitlab { + return false + } + + switch context.Commit.Status { + case model.StatusStarted: + if !g.Started { + return false + } + case model.StatusSuccess: + if !g.Success { + return false + } + case model.StatusFailure, model.StatusError, model.StatusKilled: + if !g.Failure { + return false + } + } + + return true +} + +func (g *Gitlab) send(context *model.Request, client GitlabClient) error { + msg := fmt.Sprintf( + "[%s](%s) %s%s", + getDesc(context.Commit.Status), + getBuildUrl(context), + getStatus(context.Commit.Status), + getMergeRequestComment(context.Commit.Branch, context.Commit.Status), + ) + + _, err := client.SendRepoCommitComment(strconv.FormatInt(context.Repo.ID, 10), context.Commit.Sha, msg) + + return err +} + +// getStatus converts a Drone status to a Gitlab status. +func getStatus(status string) string { + switch status { + case model.StatusEnqueue, model.StatusStarted: + return StatusPending + case model.StatusSuccess: + return StatusSuccess + case model.StatusFailure: + return StatusFailure + case model.StatusError, model.StatusKilled: + return StatusError + default: + return StatusError + } +} + +// getDesc generates a description message for the comment based on the status. +func getDesc(status string) string { + switch status { + case model.StatusEnqueue, model.StatusStarted: + return DescPending + case model.StatusSuccess: + return DescSuccess + case model.StatusFailure: + return DescFailure + case model.StatusError, model.StatusKilled: + return DescError + default: + return DescError + } +} + +func getMergeRequestComment(branch, status string) string { + if branch != PRMasterBranch { + switch status { + case model.StatusSuccess: + return PRGoodToMerge + case model.StatusFailure: + return PRBadToMerge + } + } + return "" +} diff --git a/plugin/notify/gitlab_test.go b/plugin/notify/gitlab_test.go new file mode 100644 index 000000000..2e44add4a --- /dev/null +++ b/plugin/notify/gitlab_test.go @@ -0,0 +1,107 @@ +package notify + +import ( + "fmt" + "testing" + + "github.com/Bugagazavr/go-gitlab-client" + "github.com/drone/drone/shared/model" +) + +type MockGitlabClient struct { + Comment *gogitlab.CommitComment + id string + sha string + body string +} + +func (c *MockGitlabClient) SendRepoCommitComment(id string, sha string, body string) (*gogitlab.CommitComment, error) { + c.id = id + c.sha = sha + c.body = body + return c.Comment, nil +} + +var gitlabClient = &MockGitlabClient{} + +var gitlabSubject = &Gitlab{ + SkipVerify: false, + Started: true, + Success: true, + Failure: true, +} + +var gitlabRequest = &model.Request{ + Host: "http://examplehost.com", + Repo: &model.Repo{ + ID: 123456, + Host: "examplegit.com", + Owner: "owner", + Name: "repo", + Remote: model.RemoteGitlab, + }, + Commit: &model.Commit{ + Sha: "abc", + Branch: "example", + }, + User: &model.User{ + Access: "secret_token", + }, +} + +func Test_GitlabSendStarted(t *testing.T) { + gitlabRequest.Commit.Status = "Started" + + expected := gogitlab.CommitComment{ + Note: fmt.Sprintf("[this build is pending](%s) :raised_hand:", getBuildUrl(gitlabRequest)), + } + + gitlabClient.Comment = &expected + + err := gitlabSubject.send(gitlabRequest, gitlabClient) + if err != nil { + t.Errorf("Unexepected error: %s", err.Error()) + } + + if *gitlabClient.Comment != expected { + t.Errorf("Invalid gitlab payload. Expected: %v, got %v", expected, *gitlabClient.Comment) + } +} + +func Test_GitlabSendSuccess(t *testing.T) { + gitlabRequest.Commit.Status = "Success" + + expected := gogitlab.CommitComment{ + Note: fmt.Sprintf("[the build was successful](%s) :thumbsup: -> good to merge", getBuildUrl(gitlabRequest)), + } + + gitlabClient.Comment = &expected + + err := gitlabSubject.send(gitlabRequest, gitlabClient) + if err != nil { + t.Errorf("Unexepected error: %s", err.Error()) + } + + if *gitlabClient.Comment != expected { + t.Errorf("Invalid gitlab payload. Expected: %v, got %v", expected, *gitlabClient.Comment) + } +} + +func Test_GitlabSendFailure(t *testing.T) { + gitlabRequest.Commit.Status = "Failure" + + expected := gogitlab.CommitComment{ + Note: fmt.Sprintf("[the build failed](%s) :thumbsdown: -> bad to merge", getBuildUrl(gitlabRequest)), + } + + gitlabClient.Comment = &expected + + err := gitlabSubject.send(gitlabRequest, gitlabClient) + if err != nil { + t.Errorf("Unexepected error: %s", err.Error()) + } + + if *gitlabClient.Comment != expected { + t.Errorf("Invalid gitlab payload. Expected: %v, got %v", expected, *gitlabClient.Comment) + } +} diff --git a/plugin/notify/notification.go b/plugin/notify/notification.go index da6701ace..680e2c664 100644 --- a/plugin/notify/notification.go +++ b/plugin/notify/notification.go @@ -31,6 +31,7 @@ type Notification struct { Gitter *Gitter `yaml:"gitter,omitempty"` Flowdock *flowdock.Flowdock `yaml:"flowdock,omitempty"` KatoIM *katoim.KatoIM `yaml:"katoim,omitempty"` + Gitlab *Gitlab `yaml:"gitlab,omitempty"` GitHub github.GitHub `yaml:"--"` } @@ -100,6 +101,14 @@ func (n *Notification) Send(context *model.Request) error { } } + // send Gitlab notifications + if n.Gitlab != nil { + err := n.Gitlab.Send(context) + if err != nil { + log.Println(err) + } + } + // send email notifications // TODO (bradrydzewski) need to improve this code githubStatus := new(github.GitHub) From dbdad86d90cadd75d2d528a3971c93df2a3d458f Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 2 Sep 2015 11:53:36 -0700 Subject: [PATCH 46/56] fix SSL error when wget docker --- plugin/publish/docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/publish/docker.go b/plugin/publish/docker.go index 3e9548a43..1a59a2e39 100644 --- a/plugin/publish/docker.go +++ b/plugin/publish/docker.go @@ -62,7 +62,7 @@ func (d *Docker) Write(f *buildfile.Buildfile) { if len(d.DockerVersion) > 0 { // Download docker binary and install it as /usr/local/bin/docker if it does not exist - f.WriteCmd("type -p docker || wget -qO- https://get.docker.io/builds/Linux/x86_64/docker-" + + f.WriteCmd("type -p docker || curl -sSL https://get.docker.io/builds/Linux/x86_64/docker-" + d.DockerVersion + ".tgz |sudo tar zxf - -C /") } From f98ac210105fd0ed9eef16f2bbd5a5e2cdfc222d Mon Sep 17 00:00:00 2001 From: Henrik Jonsson Date: Thu, 3 Sep 2015 17:28:08 +0200 Subject: [PATCH 47/56] Fix build errors due to changes in github.com/gogits/go-gogs-client Change ParseHook -> ParsePushHook (https://github.com/gogits/go-gogs-client/blob/master/repo_hooks.go#L185), PayloadCommit.Id->ID (https://github.com/gogits/go-gogs-client/blob/master/repo_hooks.go#L88). Tested: `make deps` works after this change Fixes #1185 --- plugin/remote/gogs/gogs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/remote/gogs/gogs.go b/plugin/remote/gogs/gogs.go index 73038a4dc..23da4fcbe 100644 --- a/plugin/remote/gogs/gogs.go +++ b/plugin/remote/gogs/gogs.go @@ -164,7 +164,7 @@ func (r *Gogs) Deactivate(user *model.User, repo *model.Repo, link string) error func (r *Gogs) ParseHook(req *http.Request) (*model.Hook, error) { defer req.Body.Close() var payloadbytes, _ = ioutil.ReadAll(req.Body) - var payload, err = gogs.ParseHook(payloadbytes) + var payload, err = gogs.ParsePushHook(payloadbytes) if err != nil { return nil, err } @@ -181,7 +181,7 @@ func (r *Gogs) ParseHook(req *http.Request) (*model.Hook, error) { return &model.Hook{ Owner: payload.Repo.Owner.UserName, Repo: payload.Repo.Name, - Sha: payload.Commits[0].Id, + Sha: payload.Commits[0].ID, Branch: payload.Branch(), Author: payload.Commits[0].Author.UserName, Timestamp: time.Now().UTC().String(), From bdd4742171f359098953751e792d28fe2c8947ac Mon Sep 17 00:00:00 2001 From: Daisuke Fujita Date: Fri, 11 Sep 2015 19:05:30 +0900 Subject: [PATCH 48/56] Return 200 even if non-action webhook is come --- server/handler/hook.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/handler/hook.go b/server/handler/hook.go index e052fc543..c1a978784 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -40,6 +40,11 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { return } + if hook == nil { + w.WriteHeader(http.StatusOK) + return + } + // in some cases we have neither a hook nor error. An example // would be GitHub sending a ping request to the URL, in which // case we'll just exit quiely with an 'OK' From 45b3f3cf7942eb0f3505039397b3b25308978add Mon Sep 17 00:00:00 2001 From: Kpacha Date: Tue, 15 Sep 2015 19:54:39 +0200 Subject: [PATCH 49/56] use PUT method instead POST --- plugin/deploy/marathon/marathon.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin/deploy/marathon/marathon.go b/plugin/deploy/marathon/marathon.go index b55000a68..7e80a822d 100644 --- a/plugin/deploy/marathon/marathon.go +++ b/plugin/deploy/marathon/marathon.go @@ -10,6 +10,7 @@ import ( type Marathon struct { //Hostname for the Marathon Master Host string `yaml:"host,omitempty"` + App string `yaml:"app,omitempty"` // The app config for marathon //https://mesosphere.github.io/marathon/docs/rest-api.html#post-v2-apps @@ -26,14 +27,15 @@ func (m *Marathon) Write(f *buildfile.Buildfile) { // debugging purposes so we can see if / where something is failing f.WriteCmdSilent("echo 'deploying to Marathon ...'") - post := fmt.Sprintf( - "curl -X POST -d @%s http://%s/v2/apps --header \"Content-Type:application/json\"", + put := fmt.Sprintf( + "curl -X PUT -d @%s http://%s/v2/apps/%s --header \"Content-Type:application/json\"", m.ConfigFile, + m.App, m.Host, ) - f.WriteCmdSilent(post) + f.WriteCmdSilent(put) } func (m *Marathon) GetCondition() *condition.Condition { return m.Condition -} +} \ No newline at end of file From 4d08b918657b39a380857f8983b3006fe99248d2 Mon Sep 17 00:00:00 2001 From: Kpacha Date: Wed, 16 Sep 2015 19:43:37 +0200 Subject: [PATCH 50/56] go fmt --- plugin/deploy/marathon/marathon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/deploy/marathon/marathon.go b/plugin/deploy/marathon/marathon.go index 7e80a822d..b24be68fc 100644 --- a/plugin/deploy/marathon/marathon.go +++ b/plugin/deploy/marathon/marathon.go @@ -38,4 +38,4 @@ func (m *Marathon) Write(f *buildfile.Buildfile) { func (m *Marathon) GetCondition() *condition.Condition { return m.Condition -} \ No newline at end of file +} From cb9a7f049ee3ff902dde521d6ea8847c687c76fc Mon Sep 17 00:00:00 2001 From: kpacha Date: Thu, 17 Sep 2015 16:16:58 +0200 Subject: [PATCH 51/56] fix the curl construction --- plugin/deploy/marathon/marathon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/deploy/marathon/marathon.go b/plugin/deploy/marathon/marathon.go index b24be68fc..307ad1287 100644 --- a/plugin/deploy/marathon/marathon.go +++ b/plugin/deploy/marathon/marathon.go @@ -30,8 +30,8 @@ func (m *Marathon) Write(f *buildfile.Buildfile) { put := fmt.Sprintf( "curl -X PUT -d @%s http://%s/v2/apps/%s --header \"Content-Type:application/json\"", m.ConfigFile, - m.App, m.Host, + m.App, ) f.WriteCmdSilent(put) } From a9366b772018bc452321178833164929fc4e5728 Mon Sep 17 00:00:00 2001 From: Henrik Jonsson Date: Thu, 8 Oct 2015 10:08:18 +0200 Subject: [PATCH 52/56] Update comments in shared.build.Builder They were previously referring to fields with different names. New comments are taken from the type declaration of `shared.build.script.Build` and what seems appropriate for `shared.build.repo.Repo` (sending separate PR). --- shared/build/build.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/build/build.go b/shared/build/build.go index 37433c6af..56c5b284a 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -41,11 +41,11 @@ func New(dockerClient *docker.Client) *Builder { // Builder represents a build process being prepared // to run. type Builder struct { - // Image specifies the Docker Image that will be - // used to virtualize the Build process. + // Build specifies the configuration details for building, + // testing and deploying code. Build *script.Build - // Source specifies the Repository path of the code + // Repo specifies the repository details for the code that // that we are testing. // // The source repository may be a local repository From dcd2f01872f7b8b9a562a7969b0af4938f341196 Mon Sep 17 00:00:00 2001 From: Henrik Jonsson Date: Thu, 8 Oct 2015 10:11:01 +0200 Subject: [PATCH 53/56] Add comment to shared.build.repo.Repo type --- shared/build/repo/repo.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared/build/repo/repo.go b/shared/build/repo/repo.go index 01daa073c..65a14908a 100644 --- a/shared/build/repo/repo.go +++ b/shared/build/repo/repo.go @@ -5,6 +5,12 @@ import ( "strings" ) +// Repo specifies the repository details for the code that +// that we are testing. +// +// The source repository may be a local repository +// on the current filesystem, or a remote repository +// on GitHub, Bitbucket, etc. type Repo struct { // The name of the Repository. This should be the // canonical name, for example, github.com/drone/drone. From 3223f4772a64479388d5b0ed49c6fa52395c00d5 Mon Sep 17 00:00:00 2001 From: Mark Fayngersh Date: Thu, 15 Oct 2015 13:12:58 -0400 Subject: [PATCH 54/56] Update repo.go to clone specific branch for PR --- shared/build/repo/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/build/repo/repo.go b/shared/build/repo/repo.go index 01daa073c..355b93ab9 100644 --- a/shared/build/repo/repo.go +++ b/shared/build/repo/repo.go @@ -114,7 +114,7 @@ func (r *Repo) Commands() []string { cmds := []string{} if len(r.PR) > 0 { // If a specific PR is provided then we need to clone it. - cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive %s %s", r.Depth, r.Path, r.Dir)) + cmds = append(cmds, fmt.Sprintf("git clone --depth=%d --recursive --branch=%s %s %s", r.Depth, branch, r.Path, r.Dir)) cmds = append(cmds, fmt.Sprintf("git fetch origin +refs/pull/%s/head:refs/remotes/origin/pr/%s", r.PR, r.PR)) cmds = append(cmds, fmt.Sprintf("git checkout -qf -b pr/%s origin/pr/%s", r.PR, r.PR)) } else { From c8e1bd66178899766ae4fa3ccc5146d2c325b09d Mon Sep 17 00:00:00 2001 From: Mark Fayngersh Date: Thu, 15 Oct 2015 15:15:35 -0400 Subject: [PATCH 55/56] Fix unit test --- shared/build/build_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/build/build_test.go b/shared/build/build_test.go index 2367202a5..adaaf7d87 100644 --- a/shared/build/build_test.go +++ b/shared/build/build_test.go @@ -594,7 +594,7 @@ func TestWriteBuildScript(t *testing.T) { f.WriteEnv("CI_PULL_REQUEST", "123") f.WriteHost("127.0.0.1") f.WriteFile("$HOME/.ssh/id_rsa", []byte("ssh-rsa AAA..."), 600) - f.WriteCmd("git clone --depth=0 --recursive git://github.com/drone/drone.git /var/cache/drone/github.com/drone/drone") + f.WriteCmd("git clone --depth=0 --recursive --branch=master git://github.com/drone/drone.git /var/cache/drone/github.com/drone/drone") f.WriteCmd("git fetch origin +refs/pull/123/head:refs/remotes/origin/pr/123") f.WriteCmd("git checkout -qf -b pr/123 origin/pr/123") From 4aee17e264fc90aeca559d9a0a941da60fccdaf4 Mon Sep 17 00:00:00 2001 From: Tanguy Herrmann Date: Wed, 21 Oct 2015 02:20:54 +0200 Subject: [PATCH 56/56] Modify to comply to the RFC7239 * Changed the previous code based on X- headers to the RFC7239 * Refactored the code to determine if a request is https or not --- shared/httputil/httputil.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/shared/httputil/httputil.go b/shared/httputil/httputil.go index 4affaccec..4fbf226f5 100644 --- a/shared/httputil/httputil.go +++ b/shared/httputil/httputil.go @@ -5,6 +5,15 @@ import ( "strings" ) +func hasHttpsForwarded(r *http.Request) bool { + forwardedHeader := r.Header["Forwarded"] + for _, w := range forwardedHeader { + strings.Contains(w, "proto=https") + return true + } + return false +} + // IsHttps is a helper function that evaluates the http.Request // and returns True if the Request uses HTTPS. It is able to detect, // using the X-Forwarded-Proto, if the original request was HTTPS and @@ -17,7 +26,7 @@ func IsHttps(r *http.Request) bool { return true case strings.HasPrefix(r.Proto, "HTTPS"): return true - case r.Header.Get("X-Forwarded-Proto") == "https": + case hasHttpsForwarded(r): return true default: return false @@ -29,18 +38,10 @@ func IsHttps(r *http.Request) bool { // using the X-Forwarded-Proto, if the original request was HTTPS // and routed through a reverse proxy with SSL termination. func GetScheme(r *http.Request) string { - switch { - case r.URL.Scheme == "https": + if IsHttps(r) { return "https" - case r.TLS != nil: - return "https" - case strings.HasPrefix(r.Proto, "HTTPS"): - return "https" - case r.Header.Get("X-Forwarded-Proto") == "https": - return "https" - default: - return "http" } + return "http" } // GetHost is a helper function that evaluates the http.Request