mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
fixing many, many issues
This commit is contained in:
parent
28061efeea
commit
35c66c7b76
4 changed files with 44 additions and 17 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"os"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
|
@ -98,14 +99,18 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull bo
|
|||
id, err := client.CreateContainer(conf, "")
|
||||
if err != nil {
|
||||
// and pull the image and re-create if that fails
|
||||
client.PullImage(conf.Image, nil)
|
||||
err = client.PullImage(conf.Image, nil)
|
||||
if err != nil {
|
||||
log.Errorf("Error pulling %s. %s\n", conf.Image, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err = client.CreateContainer(conf, "")
|
||||
// make sure the container is removed in
|
||||
// the event of a creation error.
|
||||
if err != nil && len(id) != 0 {
|
||||
client.RemoveContainer(id, true, true)
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("Error starting %s. %s\n", conf.Image, err)
|
||||
client.RemoveContainer(id, true, true)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +125,7 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull bo
|
|||
// fetches the container information.
|
||||
info, err := client.InspectContainer(id)
|
||||
if err != nil {
|
||||
log.Errorf("Error inspecting %s. %s\n", conf.Image, err)
|
||||
client.RemoveContainer(id, true, true)
|
||||
return nil, err
|
||||
}
|
||||
|
@ -133,6 +139,7 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull bo
|
|||
// starts the container
|
||||
err := client.StartContainer(id, &conf.HostConfig)
|
||||
if err != nil {
|
||||
log.Errorf("Error starting %s. %s\n", conf.Image, err)
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
|
@ -142,6 +149,7 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull bo
|
|||
// we could use the `wait` function instead
|
||||
rc, err := client.ContainerLogs(id, logOptsTail)
|
||||
if err != nil {
|
||||
log.Errorf("Error tailing %s. %s\n", conf.Image, err)
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
|
@ -151,6 +159,7 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull bo
|
|||
// fetches the container information
|
||||
info, err := client.InspectContainer(id)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting exit code for %s. %s\n", conf.Image, err)
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
|
@ -178,14 +187,15 @@ func daemon(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull
|
|||
id, err := client.CreateContainer(conf, "")
|
||||
if err != nil {
|
||||
// and pull the image and re-create if that fails
|
||||
client.PullImage(conf.Image, nil)
|
||||
id, err = client.CreateContainer(conf, "")
|
||||
// make sure the container is removed in
|
||||
// the event of a creation error.
|
||||
if err != nil && len(id) != 0 {
|
||||
client.RemoveContainer(id, true, true)
|
||||
}
|
||||
err = client.PullImage(conf.Image, nil)
|
||||
if err != nil {
|
||||
log.Errorf("Error pulling %s. %s\n", conf.Image, err)
|
||||
return nil, err
|
||||
}
|
||||
id, err = client.CreateContainer(conf, "")
|
||||
if err != nil {
|
||||
log.Errorf("Error creating %s. %s\n", conf.Image, err)
|
||||
client.RemoveContainer(id, true, true)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -193,11 +203,15 @@ func daemon(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull
|
|||
// fetches the container information
|
||||
info, err := client.InspectContainer(id)
|
||||
if err != nil {
|
||||
log.Errorf("Error inspecting %s. %s\n", conf.Image, err)
|
||||
client.RemoveContainer(id, true, true)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// starts the container
|
||||
err = client.StartContainer(id, &conf.HostConfig)
|
||||
if err != nil {
|
||||
log.Errorf("Error starting daemon %s. %s\n", conf.Image, err)
|
||||
}
|
||||
return info, err
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/drone/drone/common"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
@ -20,14 +21,19 @@ var (
|
|||
publish = flag.Bool("publish", false, "")
|
||||
deploy = flag.Bool("deploy", false, "")
|
||||
notify = flag.Bool("notify", false, "")
|
||||
debug = flag.Bool("debug", false, "")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
ctx, err := parseContext()
|
||||
if err != nil {
|
||||
fmt.Println("Error launching build container.", err)
|
||||
log.Errorln("Error launching build container.", err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
|
@ -37,7 +43,7 @@ func main() {
|
|||
// linked Docker daemon
|
||||
docker, err := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
|
||||
if err != nil {
|
||||
fmt.Println("Error connecting to build server.", err)
|
||||
log.Errorln("Error connecting to build server.", err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
|
@ -46,7 +52,7 @@ func main() {
|
|||
// container to create a pod-like environment.
|
||||
client, err := newClient(docker)
|
||||
if err != nil {
|
||||
fmt.Println("Error starting build server pod", err)
|
||||
log.Errorln("Error starting build server pod", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
ctx.client = client
|
||||
|
@ -56,7 +62,7 @@ func main() {
|
|||
// prior to executing our build tasks.
|
||||
err = setup(ctx)
|
||||
if err != nil {
|
||||
fmt.Println("Error processing .drone.yml file.", err)
|
||||
log.Errorln("Error processing .drone.yml file.", err)
|
||||
client.Destroy()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -124,7 +124,8 @@ func (r *Runner) Run(w *queue.Work) error {
|
|||
worker := newWorkerTimeout(client, w.Repo.Timeout)
|
||||
workers = append(workers, worker)
|
||||
cname := cname(task)
|
||||
state, builderr := worker.Build(cname, in)
|
||||
pullrequest := (w.Commit.PullRequest != "")
|
||||
state, builderr := worker.Build(cname, in, pullrequest)
|
||||
|
||||
switch {
|
||||
case builderr == ErrTimeout:
|
||||
|
|
|
@ -41,6 +41,9 @@ var (
|
|||
// default argument to invoke build steps
|
||||
DefaultBuildArgs = []string{"--build", "--clone", "--publish", "--deploy"}
|
||||
|
||||
// default argument to invoke build steps
|
||||
DefaultPullRequestArgs = []string{"--build", "--clone"}
|
||||
|
||||
// default arguments to invoke notify steps
|
||||
DefaultNotifyArgs = []string{"--notify"}
|
||||
|
||||
|
@ -76,10 +79,13 @@ func newWorkerTimeout(client dockerclient.Client, timeout int64) *worker {
|
|||
}
|
||||
|
||||
// Build executes the clone, build and deploy steps.
|
||||
func (w *worker) Build(name string, stdin []byte) (_ int, err error) {
|
||||
func (w *worker) Build(name string, stdin []byte, pr bool) (_ int, err error) {
|
||||
// the command line arguments passed into the
|
||||
// build agent container.
|
||||
args := DefaultBuildArgs
|
||||
if pr {
|
||||
args = DefaultPullRequestArgs
|
||||
}
|
||||
args = append(args, "--")
|
||||
args = append(args, string(stdin))
|
||||
|
||||
|
|
Loading…
Reference in a new issue