diff --git a/.drone.yml b/.drone.yml index bdc48b1af..f5d5bb106 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,9 +17,12 @@ services: - postgres - mysql notify: - email: - recipients: - - brad@drone.io + gitter: + room_id: 76f5e5ec935c5b40259a + token: $$GITTER_TOKEN + on_started: false + on_success: false + on_failure: false publish: s3: diff --git a/Dockerfile b/Dockerfile index 9778d6734..1f1bc8421 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,16 +3,14 @@ # docker run -p 127.0.0.1:80:80 -t drone/drone FROM google/golang - -RUN apt-get update -RUN apt-get -y install zip libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null +ENV DRONE_SERVER_PORT :80 ADD . /gopath/src/github.com/drone/drone/ WORKDIR /gopath/src/github.com/drone/drone -RUN make deps build embed install +RUN apt-get update +RUN apt-get -y install zip libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null +RUN make deps build test embed install EXPOSE 80 - ENTRYPOINT ["/usr/local/bin/droned"] -CMD ["--bind=:80"] diff --git a/server/handler/hook.go b/server/handler/hook.go index 9f02285fb..31f858521 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -76,7 +76,7 @@ func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { // verify the commit hooks branch matches the list of approved // branches (unless it is a pull request). Note that we don't really // care if parsing the yaml fails here. - s, _ := script.ParseBuild(string(yml), map[string]string{}) + s, _ := script.ParseBuild(string(yml)) if len(hook.PullRequest) == 0 && !s.MatchBranch(hook.Branch) { w.WriteHeader(http.StatusOK) return diff --git a/server/worker/docker/docker.go b/server/worker/docker/docker.go index 352e5ab06..ad1f3bf50 100644 --- a/server/worker/docker/docker.go +++ b/server/worker/docker/docker.go @@ -81,7 +81,7 @@ func (d *Docker) Do(c context.Context, r *worker.Work) { if err != nil { log.Printf("Error parsing PARAMS for %s/%s, Err: %s", r.Repo.Owner, r.Repo.Name, err.Error()) } - script, err := script.ParseBuild(r.Commit.Config, params) + script, err := script.ParseBuild(script.Inject(r.Commit.Config, params)) if err != nil { log.Printf("Error parsing YAML for %s/%s, Err: %s", r.Repo.Owner, r.Repo.Name, err.Error()) } diff --git a/shared/build/script/inject.go b/shared/build/script/inject.go new file mode 100644 index 000000000..f52c290b6 --- /dev/null +++ b/shared/build/script/inject.go @@ -0,0 +1,16 @@ +package script + +import ( + "strings" +) + +func Inject(script string, params map[string]string) string { + if params == nil { + return script + } + injected := script + for k, v := range params { + injected = strings.Replace(injected, "$$"+k, v, -1) + } + return injected +} diff --git a/shared/build/script/inject_test.go b/shared/build/script/inject_test.go new file mode 100644 index 000000000..3984bd741 --- /dev/null +++ b/shared/build/script/inject_test.go @@ -0,0 +1,32 @@ +package script + +import ( + "github.com/franela/goblin" + "testing" +) + +func Test_Inject(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Inject params", func() { + + g.It("Should replace vars with $$", func() { + s := "echo $$FOO $BAR" + m := map[string]string{} + m["FOO"] = "BAZ" + g.Assert("echo BAZ $BAR").Equal(Inject(s, m)) + }) + + g.It("Should not replace vars with single $", func() { + s := "echo $FOO $BAR" + m := map[string]string{} + m["FOO"] = "BAZ" + g.Assert(s).Equal(Inject(s, m)) + }) + + g.It("Should not replace vars in nil map", func() { + s := "echo $$FOO $BAR" + g.Assert(s).Equal(Inject(s, nil)) + }) + }) +} diff --git a/shared/build/script/script.go b/shared/build/script/script.go index 0819af92f..cbedd9984 100644 --- a/shared/build/script/script.go +++ b/shared/build/script/script.go @@ -1,8 +1,6 @@ package script import ( - "bytes" - "fmt" "io/ioutil" "strings" @@ -16,11 +14,11 @@ import ( "github.com/drone/drone/shared/build/repo" ) -func ParseBuild(data string, params map[string]string) (*Build, error) { +func ParseBuild(data string) (*Build, error) { build := Build{} // parse the build configuration file - err := yaml.Unmarshal(injectParams([]byte(data), params), &build) + err := yaml.Unmarshal([]byte(data), &build) return &build, err } @@ -30,15 +28,7 @@ func ParseBuildFile(filename string) (*Build, error) { return nil, err } - return ParseBuild(string(data), nil) -} - -// injectParams injects params into data. -func injectParams(data []byte, params map[string]string) []byte { - for k, v := range params { - data = bytes.Replace(data, []byte(fmt.Sprintf("{{%s}}", k)), []byte(v), -1) - } - return data + return ParseBuild(string(data)) } // Build stores the configuration details for