Skip to content

Commit

Permalink
Fix Dockerfile not located when added to dockerignore (#2272)
Browse files Browse the repository at this point in the history
* test(testdata): add a dockerignore file to the testdata directory to replicate the bug 2203
* fix(container): include the target dockerignore and the target dockerfile to the buildcontext 2203
* test(container): update the parse docker ignore test case to pass under the new changes 2203
  • Loading branch information
danvergara committed Feb 29, 2024
1 parent 8085e2f commit 9d8e386
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func (c *ContainerRequest) Validate() error {

// GetContext retrieve the build context for the request
func (c *ContainerRequest) GetContext() (io.Reader, error) {
var includes []string = []string{"."}

if c.ContextArchive != nil {
return c.ContextArchive, nil
}
Expand All @@ -209,7 +211,14 @@ func (c *ContainerRequest) GetContext() (io.Reader, error) {
if err != nil {
return nil, err
}
buildContext, err := archive.TarWithOptions(c.Context, &archive.TarOptions{ExcludePatterns: excluded})

dockerIgnoreLocation := filepath.Join(abs, ".dockerignore")
includes = append(includes, dockerIgnoreLocation, c.GetDockerfile())

buildContext, err := archive.TarWithOptions(
c.Context,
&archive.TarOptions{ExcludePatterns: excluded, IncludeFiles: includes},
)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func TestParseDockerIgnore(t *testing.T) {
{
filePath: "./testdata",
expectedErr: nil,
expectedExcluded: []string(nil),
expectedExcluded: []string{"Dockerfile", "echo.Dockerfile"},
},
}

Expand Down
2 changes: 2 additions & 0 deletions testdata/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
echo.Dockerfile

0 comments on commit 9d8e386

Please sign in to comment.