Merge pull request #777 from bradrydzewski/master
improved debugging when Docker errors
This commit is contained in:
commit
0a6227930d
4 changed files with 16 additions and 14 deletions
|
@ -23,7 +23,7 @@ type Permstore interface {
|
|||
// GetPerm retrieves the User's permission from
|
||||
// the datastore for the given repository.
|
||||
func GetPerm(c context.Context, user *model.User, repo *model.Repo) (*model.Perm, error) {
|
||||
// if the user is a gues they should only be granted
|
||||
// if the user is a guest they should only be granted
|
||||
// read access to public repositories.
|
||||
switch {
|
||||
case user == nil && repo.Private:
|
||||
|
@ -43,8 +43,8 @@ func GetPerm(c context.Context, user *model.User, repo *model.Repo) (*model.Perm
|
|||
// if the user is authenticated we'll retireive the
|
||||
// permission details from the database.
|
||||
perm, err := FromContext(c).GetPerm(user, repo)
|
||||
if err == nil && perm.ID != 0 {
|
||||
return perm, err
|
||||
if perm.ID == 0 {
|
||||
perm.Guest = true
|
||||
}
|
||||
|
||||
switch {
|
||||
|
@ -53,12 +53,10 @@ func GetPerm(c context.Context, user *model.User, repo *model.Repo) (*model.Perm
|
|||
perm.Read = true
|
||||
perm.Write = true
|
||||
perm.Admin = true
|
||||
perm.Guest = true
|
||||
|
||||
// if the repo is public, grant read access only.
|
||||
case repo.Private == false:
|
||||
perm.Read = true
|
||||
perm.Guest = true
|
||||
}
|
||||
return perm, err
|
||||
}
|
||||
|
|
|
@ -139,10 +139,13 @@ func (d *Docker) Do(c context.Context, r *worker.Work) {
|
|||
builder.Build = script
|
||||
builder.Repo = repo
|
||||
builder.Stdout = buf
|
||||
builder.Key = []byte(r.Repo.PrivateKey)
|
||||
builder.Timeout = time.Duration(r.Repo.Timeout) * time.Second
|
||||
builder.Privileged = r.Repo.Privileged
|
||||
|
||||
if r.Repo.Private || len(r.Commit.PullRequest) == 0 {
|
||||
builder.Key = []byte(r.Repo.PrivateKey)
|
||||
}
|
||||
|
||||
// run the build
|
||||
err = builder.Run()
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ func (b *Builder) setup() error {
|
|||
if _, err := b.dockerClient.Images.Inspect(b.Build.Image); err == docker.ErrNotFound {
|
||||
// download the image if it doesn't exist
|
||||
if err := b.dockerClient.Images.Pull(b.Build.Image); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Error: Unable to pull image %s. %s", b.Build.Image, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
log.Errf("failed to inspect image %s", b.Build.Image)
|
||||
|
@ -392,7 +392,7 @@ func (b *Builder) run() error {
|
|||
// create the container from the image
|
||||
run, err := b.dockerClient.Containers.Create(&conf)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Error: Failed to create build container. %s", err)
|
||||
}
|
||||
|
||||
// cache instance of docker.Run
|
||||
|
@ -407,7 +407,7 @@ func (b *Builder) run() error {
|
|||
if err := b.dockerClient.Containers.Start(run.ID, &host); err != nil {
|
||||
b.BuildState.ExitCode = 1
|
||||
b.BuildState.Finished = time.Now().UTC().Unix()
|
||||
return err
|
||||
return fmt.Errorf("Error: Failed to start build container. %s", err)
|
||||
}
|
||||
|
||||
// wait for the container to stop
|
||||
|
@ -415,7 +415,7 @@ func (b *Builder) run() error {
|
|||
if err != nil {
|
||||
b.BuildState.ExitCode = 1
|
||||
b.BuildState.Finished = time.Now().UTC().Unix()
|
||||
return err
|
||||
return fmt.Errorf("Error: Failed to wait for build container. %s", err)
|
||||
}
|
||||
|
||||
// set completion time
|
||||
|
@ -503,7 +503,9 @@ func (b *Builder) writeBuildScript(dir string) error {
|
|||
f.WriteHost(mapping)
|
||||
}
|
||||
|
||||
f.WriteFile("$HOME/.ssh/id_rsa", b.Key, 600)
|
||||
if len(b.Key) != 0 {
|
||||
f.WriteFile("$HOME/.ssh/id_rsa", b.Key, 600)
|
||||
}
|
||||
|
||||
// if the repository is remote then we should
|
||||
// add the commands to the build script to
|
||||
|
|
|
@ -422,8 +422,7 @@ func TestRunErrorCreate(t *testing.T) {
|
|||
b.image = &docker.Image{ID: "c3ab8ff137"}
|
||||
b.Build = &script.Build{}
|
||||
b.Repo = &repo.Repo{}
|
||||
|
||||
if err := b.run(); err != docker.ErrBadRequest {
|
||||
if err := b.run(); err == nil || err.Error() != "Error: Failed to create build container. Bad Request" {
|
||||
t.Errorf("Expected error when trying to create build container")
|
||||
}
|
||||
}
|
||||
|
@ -456,7 +455,7 @@ func TestRunErrorStart(t *testing.T) {
|
|||
b.Build = &script.Build{}
|
||||
b.Repo = &repo.Repo{}
|
||||
|
||||
if err := b.run(); err != docker.ErrBadRequest {
|
||||
if err := b.run(); err == nil || err.Error() != "Error: Failed to start build container. Bad Request" {
|
||||
t.Errorf("Expected error when trying to start build container")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue