Skip to content

Commit

Permalink
propogate HTTP_PROXY environment variables throuhgout build
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Oct 6, 2015
1 parent acb27f4 commit 0943117
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ deps:
go get -u github.com/elazarl/go-bindata-assetfs/...
go get -u github.com/dchest/jsmin
go get -u github.com/franela/goblin
go get -u github.com/go-swagger/go-swagger
go get -u github.com/go-swagger/go-swagger/...
go get -u github.com/PuerkitoBio/goquery
go get -u github.com/russross/blackfriday

Expand Down
6 changes: 5 additions & 1 deletion controller/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"time"

log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"

"github.com/drone/drone/model"
Expand All @@ -22,7 +23,10 @@ func ShowIndex(c *gin.Context) {
return
}

repos, _ := model.GetRepoList(db, user)
repos, err := model.GetRepoList(db, user)
if err != nil {
log.Errorf(err)
}

c.HTML(200, "repos.html", gin.H{
"User": user,
Expand Down
2 changes: 1 addition & 1 deletion drone.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
remote_ := remote.Load(env)

// setup the runner
engine_ := engine.Load(database_, remote_)
engine_ := engine.Load(database_, env, remote_)

// setup the server and start the listener
server_ := server.Load(env)
Expand Down
26 changes: 21 additions & 5 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/drone/drone/model"
"github.com/drone/drone/remote"
"github.com/drone/drone/shared/docker"
"github.com/drone/drone/shared/envconfig"
"github.com/samalba/dockerclient"
)

Expand Down Expand Up @@ -54,18 +55,31 @@ type engine struct {
bus *eventbus
updater *updater
pool *pool
envs []string
}

// Load creates a new build engine, loaded with registered nodes from the
// database. The registered nodes are added to the pool of nodes to immediately
// start accepting workloads.
func Load(db *sql.DB, remote remote.Remote) Engine {
func Load(db *sql.DB, env envconfig.Env, remote remote.Remote) Engine {
engine := &engine{}
engine.bus = newEventbus()
engine.pool = newPool()
engine.db = db
engine.updater = &updater{engine.bus, db, remote}

// quick fix to propogate HTTP_PROXY variables
// throughout the build environment.
if env := env.Get("HTTP_PROXY"); len(env) != 0 {
engine.envs = append(engine.envs, "HTTP_PROXY="+env)
}
if env := env.Get("HTTPS_PROXY"); len(env) != 0 {
engine.envs = append(engine.envs, "HTTPS_PROXY="+env)
}
if env := env.Get("NO_PROXY"); len(env) != 0 {
engine.envs = append(engine.envs, "NO_PROXY="+env)
}

nodes, err := model.GetNodeList(db)
if err != nil {
log.Fatalf("failed to get nodes from database. %s", err)
Expand Down Expand Up @@ -174,7 +188,7 @@ func (e *engine) Schedule(req *Task) {
// run all bulid jobs
for _, job := range req.Jobs {
req.Job = job
runJob(req, e.updater, client)
e.runJob(req, e.updater, client)
}

// update overall status based on each job
Expand All @@ -192,7 +206,7 @@ func (e *engine) Schedule(req *Task) {
}

// run notifications
err = runJobNotify(req, client)
err = e.runJobNotify(req, client)
if err != nil {
log.Errorf("error executing notification step. %s", err)
}
Expand Down Expand Up @@ -235,7 +249,7 @@ func newDockerClient(addr, cert, key, ca string) (dockerclient.Client, error) {
return dockerclient.NewDockerClient(addr, tlc)
}

func runJob(r *Task, updater *updater, client dockerclient.Client) error {
func (e *engine) runJob(r *Task, updater *updater, client dockerclient.Client) error {

name := fmt.Sprintf("drone_build_%d_job_%d", r.Build.ID, r.Job.ID)

Expand Down Expand Up @@ -281,6 +295,7 @@ func runJob(r *Task, updater *updater, client dockerclient.Client) error {
Image: DefaultAgent,
Entrypoint: DefaultEntrypoint,
Cmd: args,
Env: e.envs,
HostConfig: dockerclient.HostConfig{
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
},
Expand Down Expand Up @@ -358,7 +373,7 @@ func runJob(r *Task, updater *updater, client dockerclient.Client) error {
return nil
}

func runJobNotify(r *Task, client dockerclient.Client) error {
func (e *engine) runJobNotify(r *Task, client dockerclient.Client) error {

name := fmt.Sprintf("drone_build_%d_notify", r.Build.ID)

Expand All @@ -383,6 +398,7 @@ func runJobNotify(r *Task, client dockerclient.Client) error {
Image: DefaultAgent,
Entrypoint: DefaultEntrypoint,
Cmd: args,
Env: e.envs,
HostConfig: dockerclient.HostConfig{
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
},
Expand Down

0 comments on commit 0943117

Please sign in to comment.