filter

package
v0.0.0-...-4b51ba2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComplexPatterns

func ComplexPatterns(patterns []*patternmatcher.Pattern) []*patternmatcher.Pattern

ComplexPatterns checks if all patterns are prefix patterns.

Types

type Digester

type Digester struct{}

func (*Digester) Digest

func (d *Digester) Digest(r io.Reader) (digest.Digest, error)

type DockerIgnoreContext

type DockerIgnoreContext struct {
	// contains filtered or unexported fields
}

DockerIgnoreContext wrap a continuity.Context that filters resources based on a .dockerignore file.

func NewDockerIgnoreContext

func NewDockerIgnoreContext(root string, dockerignore *DockerIgnoreFilter, opts continuity.ContextOptions) (*DockerIgnoreContext, error)

NewDockerIgnoreContext creates a new DockerIgnoreContext with a dockerignore filter.

Example
package main

import (
	"fmt"
	"os"
	"path"

	"github.com/containerd/continuity"
	"github.com/depot/orca/filter"
)

func main() {
	// Make some test data:
	root, _ := os.MkdirTemp("", "testwalk")
	f, err := os.Create(path.Join(root, "index.ts"))
	if err != nil {
		panic(err)
	}
	_ = f.Close()

	// This dockerignore filter will ignore all files in node_modules.
	ignoreNodeModules, err := filter.NewDockerIgnoreFilter([]string{"node_modules"})
	if err != nil {
		panic(err)
	}

	// Create a context that will walk the file tree and filter out node_modules.
	ctx, err := filter.NewDockerIgnoreContext(root, ignoreNodeModules, continuity.ContextOptions{
		// This digester will create chunked digests for each file.
		Digester: &filter.Digester{},
	})
	if err != nil {
		panic(err)
	}

	manifest, _ := continuity.BuildManifest(ctx)
	for _, r := range manifest.Resources {
		fmt.Printf("%v\n", r.Path())
	}
}
Output:

/index.ts

func (*DockerIgnoreContext) Apply

Apply passes through to the inner context.

func (*DockerIgnoreContext) Resource

Resource passes through to the inner context.

func (*DockerIgnoreContext) Verify

Verify passes through to the inner context.

func (*DockerIgnoreContext) Walk

func (c *DockerIgnoreContext) Walk(walkFn filepath.WalkFunc) error

Walk applies a dockerignore to filter files from a directory tree. Files that are not filtered by the dockerignore are passed through to the inner context.

This was transliterated from buildkit. It has *BIG* assumption that it is ok for the same directory to be visited multiple times.

type DockerIgnoreFilter

type DockerIgnoreFilter struct {
	Patterns           []*patternmatcher.Pattern
	HasExclusions      bool
	OnlySimplePatterns bool
}

DockerIgnoreFilter is a filter that uses dockerignore rules to filter files from a directory tree.

This is largely transliterated from buildkit.

func NewDockerIgnoreFilter

func NewDockerIgnoreFilter(patterns []string) (*DockerIgnoreFilter, error)

func (*DockerIgnoreFilter) Matches

func (f *DockerIgnoreFilter) Matches(path string, parentPathMatches MatchedPatterns) (ok bool, patterns MatchedPatterns, err error)

Matches checks if the path matches the dockerignore patterns.

type MatchedPatterns

type MatchedPatterns []bool

MatchIndices is a slice of booleans that indicate which patterns matched the path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL