func hasModifiedDeps(ctx *context.ExecuteContext, deps []string) bool { for _, dep := range deps { taskName := task.ParseName(dep) if ctx.IsModified(taskName) { return true } } return false }
func pushImage(ctx *context.ExecuteContext, t *Task, tag string) error { repo, err := parseAuthRepo(t.config.Image) if err != nil { return err } return Stream(os.Stdout, func(out io.Writer) error { return ctx.Client.PushImage(docker.PushImageOptions{ Name: tag, OutputStream: out, RawJSONStream: true, // TODO: timeout }, ctx.GetAuthConfig(repo)) }) }
func pullImage(ctx *context.ExecuteContext, t *Task, imageTag string) error { registry, err := parseAuthRepo(t.config.Image) if err != nil { return err } repo, tag := docker.ParseRepositoryTag(imageTag) return Stream(os.Stdout, func(out io.Writer) error { return ctx.Client.PullImage(docker.PullImageOptions{ Repository: repo, Tag: tag, OutputStream: out, RawJSONStream: true, // TODO: timeout }, ctx.GetAuthConfig(registry)) }) }
func executeTasks(ctx *context.ExecuteContext, tasks *TaskCollection) error { startedTasks := []types.Task{} defer func() { logging.Log.Debug("stopping tasks") for _, task := range reversed(startedTasks) { if err := task.Stop(ctx); err != nil { logging.Log.Warnf("Failed to stop task %q: %s", task.Name(), err) } } }() logging.Log.Debug("executing tasks") for _, taskConfig := range tasks.All() { resource, err := taskConfig.Resource().Resolve(ctx.Env) if err != nil { return err } ctx.Resources.Add(taskConfig.Name().Resource(), resource) task := taskConfig.Task(resource) startedTasks = append(startedTasks, task) start := time.Now() logging.Log.WithFields(log.Fields{"time": start, "task": task}).Debug("Start") depsModified := hasModifiedDeps(ctx, taskConfig.Dependencies()) modified, err := task.Run(ctx, depsModified) if err != nil { return fmt.Errorf("failed to execute task %q: %s", task.Name(), err) } if modified { ctx.SetModified(task.Name()) } logging.Log.WithFields(log.Fields{ "elapsed": time.Since(start), "task": task, }).Debug("Complete") } return nil }