コード例 #1
0
ファイル: targets.go プロジェクト: liamjbennett/sous
// OverrideContainerRebuild returns true and a reason if this container needs to
// be rebuilt.
func (s *Sous) OverrideContainerRebuild(t ContainerTarget, context *Context, container docker.Container) (bool, string) {
	image := container.Image()
	baseImage := t.Dockerfile(context).From
	if docker.BaseImageUpdated(baseImage, image) {
		return true, fmt.Sprintf("base image %s updated", baseImage)
	}
	return false, ""
}
コード例 #2
0
ファイル: targets.go プロジェクト: liamjbennett/sous
// NeedsBuild detects if the project's last
// build is stale, and if it therefore needs to be rebuilt. This can be overidden
// by implementing the Staler interfact on individual build targets. This default
// implementation rebuilds on absolutely any change in sous (i.e. new version/new
// config) or in the working tree (new or modified files).
func (s *Sous) needsToBuildNewImage(t Target, c *Context, asDependency bool, depsRebuilt []string) (bool, string) {
	if len(depsRebuilt) == 1 {
		return true, fmt.Sprintf("its %s dependency was rebuilt", depsRebuilt[0])
	}
	if len(depsRebuilt) > 1 {
		return true, fmt.Sprintf("its dependencies [%s] were reubilt", strings.Join(depsRebuilt, ", "))
	}
	if s.Flags.ForceRebuildAll {
		return true, "-rebuild-all flag was used"
	}
	if s.Flags.ForceRebuild && !asDependency {
		return true, "-rebuild flag was used"
	}
	changes := c.ChangesSinceLastBuild()
	if staler, ok := t.(ImageIsStaler); ok {
		if stale, reason := staler.ImageIsStale(c); stale {
			return true, reason
		}
	} else if changes.Any() {
		reason := "changes were detected"
		if changes.WorkingTreeChanged {
			reason = "your working tree has changed"
		} else if changes.NewCommit {
			reason = "you have a new commit"
		} else if changes.NoBuiltImage {
			reason = "no corresponding image exists yet"
		} else if changes.SousUpdated {
			reason = "sous itself was updated"
		}
		return true, reason
	}
	// Always force a rebuild if is base image has been updated.
	baseImage := t.Dockerfile(c).From
	// TODO: This is probably a bit too aggressive, consider only asking the user to
	// update base images every 24 hours, if they have actually been updated.
	s.UpdateBaseImage(baseImage)
	if c.BuildNumber() == 1 {
		return true, fmt.Sprintf("there are no successful builds yet for the current revision (%s)", c.Git.CommitSHA)
	}
	if !c.LastBuildImageExists() {
		return true, fmt.Sprintf("the last successful build image no longer exists (%s)", c.PrevDockerTag())
	}
	if docker.BaseImageUpdated(baseImage, c.PrevDockerTag()) {
		return true, fmt.Sprintf("the base image %s was updated", baseImage)
	}
	// Always force a build if Sous itself has been updated
	// NB: Always keep this check until last, since it's annoying, so only report this as the reason to rebuild
	// if none of the reasons above hold true. Sous does its own PR innit.
	if changes.SousUpdated {
		return true, fmt.Sprintf("sous itself or its config was updated")
	}
	return false, ""
}