Esempio n. 1
0
File: run.go Progetto: dnephin/dobi
// TODO: support a .mountignore file used to ignore mtime of files
func (t *Task) mountsLastModified(ctx *context.ExecuteContext) (time.Time, error) {
	mountPaths := []string{}
	ctx.Resources.EachMount(t.config.Mounts, func(name string, mount *config.MountConfig) {
		mountPaths = append(mountPaths, mount.Bind)
	})
	return fs.LastModified(mountPaths...)
}
Esempio n. 2
0
func buildIsStale(ctx *context.ExecuteContext, t *Task) (bool, error) {
	image, err := GetImage(ctx, t.config)
	switch err {
	case docker.ErrNoSuchImage:
		t.logger().Debug("Image does not exist")
		return true, nil
	case nil:
	default:
		return true, err
	}

	mtime, err := fs.LastModified(t.config.Context)
	if err != nil {
		t.logger().Warnf("Failed to get last modified time of context.")
		return true, err
	}

	record, err := getImageRecord(recordPath(ctx, t.config))
	if err != nil {
		t.logger().Warnf("Failed to get image record: %s", err)
		if image.Created.Before(mtime) {
			t.logger().Debug("Image older than context")
			return true, nil
		}
		return false, nil
	}

	if image.ID != record.ImageID || record.Info.ModTime().Before(mtime) {
		t.logger().Debug("Image record older than context")
		return true, nil
	}
	return false, nil
}
Esempio n. 3
0
File: run.go Progetto: dnephin/dobi
func (t *Task) artifactLastModified() (time.Time, error) {
	paths := t.config.Artifact.Paths()
	// File or directory doesn't exist
	if len(paths) == 0 {
		return time.Time{}, nil
	}
	return fs.LastModified(paths...)
}
Esempio n. 4
0
File: run.go Progetto: dnephin/dobi
func (t *Task) isStale(ctx *context.ExecuteContext) (bool, error) {
	if t.config.Artifact.Empty() {
		return true, nil
	}

	artifactLastModified, err := t.artifactLastModified()
	if err != nil {
		t.logger().Warnf("Failed to get artifact last modified: %s", err)
		return true, err
	}

	if t.config.Sources.NoMatches() {
		t.logger().Warnf("No sources found matching: %s", &t.config.Sources)
		return true, nil
	}

	if len(t.config.Sources.Paths()) != 0 {
		sourcesLastModified, err := fs.LastModified(t.config.Sources.Paths()...)
		if err != nil {
			return true, err
		}
		if artifactLastModified.Before(sourcesLastModified) {
			t.logger().Debug("artifact older than sources")
			return true, nil
		}
		return false, nil
	}

	mountsLastModified, err := t.mountsLastModified(ctx)
	if err != nil {
		t.logger().Warnf("Failed to get mounts last modified: %s", err)
		return true, err
	}

	if artifactLastModified.Before(mountsLastModified) {
		t.logger().Debug("artifact older than mount files")
		return true, nil
	}

	imageName := ctx.Resources.Image(t.config.Use)
	taskImage, err := image.GetImage(ctx, imageName)
	if err != nil {
		return true, fmt.Errorf("failed to get image %q: %s", imageName, err)
	}
	if artifactLastModified.Before(taskImage.Created) {
		t.logger().Debug("artifact older than image")
		return true, nil
	}
	return false, nil
}