Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix context bug which could hang forever #960

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ func processLogLine(jm jsonmessage.JSONMessage,
info += "failed to parse aux message: " + err.Error()
}
if err := (&resp).Unmarshal(infoBytes); err != nil {
info += "failed to parse aux message: " + err.Error()
info += "failed to parse info bytes: " + err.Error()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint fix.

}
for _, vertex := range resp.Vertexes {
info += fmt.Sprintf("digest: %+v\n", vertex.Digest)
Expand Down
4 changes: 2 additions & 2 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func (accumulator *contextHashAccumulator) hashPath(
if err != nil {
return fmt.Errorf("could not copy symlink path %s to hash: %w", filePath, err)
}
} else {
} else if fileMode.IsRegular() {
// For regular files, we can hash their content.
// TODO: consider only hashing file metadata to improve performance
f, err := os.Open(filePath)
Expand Down Expand Up @@ -737,7 +737,7 @@ func setConfiguration(configVars map[string]string) map[string]string {
}

func marshalBuildOnPreview(inputs resource.PropertyMap) bool {
//set default if not set
// set default if not set
if inputs["buildOnPreview"].IsNull() || inputs["buildOnPreview"].ContainsUnknowns() {
return false
}
Expand Down
18 changes: 18 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"syscall"
"testing"

"github.com/docker/distribution/reference"
Expand Down Expand Up @@ -238,6 +239,23 @@ func TestHashDeepSymlinks(t *testing.T) {
assert.NoError(t, err)
}

func TestIgnoreIrregularFiles(t *testing.T) {
dir := t.TempDir()

// Create a Dockerfile
dockerfile := filepath.Join(dir, "Dockerfile")
err := os.WriteFile(dockerfile, []byte{}, 0o600)
require.NoError(t, err)

// Create a pipe which should be ignored. (We will time out trying to read
// it if it's not.)
err = syscall.Mkfifo(filepath.Join(dir, "pipe"), 0o666)
require.NoError(t, err)

Copy link

@rquitales rquitales Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider adding an assert here that the file <dir>/pipe is is not fileMode.IsRegular() to make it more obvious that we have an irregular file.

_, err = hashContext(dir, dockerfile)
assert.NoError(t, err)
}

func TestHashUnignoredDirs(t *testing.T) {
step1Dir := "./testdata/unignores/basedir"
baseResult, err := hashContext(step1Dir, filepath.Join(step1Dir, defaultDockerfile))
Expand Down
Loading