Merge pull request #536 from bradrydzewski/master

fixed Dockerfile to pass port via ENV
This commit is contained in:
Brad Rydzewski 2014-10-12 13:17:53 -07:00
commit e9ca829dcf
7 changed files with 63 additions and 24 deletions

View file

@ -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:

View file

@ -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"]

View file

@ -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

View file

@ -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())
}

View file

@ -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
}

View file

@ -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))
})
})
}

View file

@ -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