Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from MaterializeInc/support_per_dockerfile_doc…
Browse files Browse the repository at this point in the history
…kerignore_files

Support per-Dockerfile dockerignore files
  • Loading branch information
alex-hunt-materialize authored Feb 7, 2022
2 parents 4783008 + 3ce16b8 commit 2db0117
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cmd/pulumi-resource-docker-buildkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,26 @@ func (ch *contextHash) hexSum() string {
}

func hashContext(contextPath string, dockerfile string) (string, error) {
dockerIgnore, err := os.ReadFile(filepath.Join(contextPath, ".dockerignore"))
if err != nil && !os.IsNotExist(err) {
return "", fmt.Errorf("unable to read .dockerignore file: %w", err)
dockerIgnorePath := dockerfile + ".dockerignore"
dockerIgnore, err := os.ReadFile(dockerIgnorePath)
if err != nil {
if os.IsNotExist(err) {
dockerIgnorePath = filepath.Join(contextPath, ".dockerignore")
dockerIgnore, err = os.ReadFile(dockerIgnorePath)
if err != nil && !os.IsNotExist(err) {
return "", fmt.Errorf("unable to read %s file: %w", dockerIgnorePath, err)
}
} else {
return "", fmt.Errorf("unable to read %s file: %w", dockerIgnorePath, err)
}
}
ignorePatterns, err := dockerignore.ReadAll(bytes.NewReader(dockerIgnore))
if err != nil {
return "", fmt.Errorf("unable to parse .dockerignore file: %w", err)
return "", fmt.Errorf("unable to parse %s file: %w", dockerIgnorePath, err)
}
ignoreMatcher, err := fileutils.NewPatternMatcher(ignorePatterns)
if err != nil {
return "", fmt.Errorf("unable to load rules from .dockerignore: %w", err)
return "", fmt.Errorf("unable to load rules from %s: %w", dockerIgnorePath, err)
}
ch := newContextHash(contextPath)
err = ch.hashPath(dockerfile, 0)
Expand All @@ -412,7 +421,7 @@ func hashContext(contextPath string, dockerfile string) (string, error) {
}
ignore, err := ignoreMatcher.Matches(path)
if err != nil {
return fmt.Errorf(".dockerignore rule failed: %w", err)
return fmt.Errorf("%s rule failed: %w", dockerIgnorePath, err)
}
if ignore {
if d.IsDir() {
Expand Down

0 comments on commit 2db0117

Please sign in to comment.