Skip to content

Commit

Permalink
Merge pull request #961 from vdice/fix/dockerignore
Browse files Browse the repository at this point in the history
fix(docker.go): read .dockerignore file for appropriate build exclusions
  • Loading branch information
carolynvs-msft authored Mar 27, 2020
2 parents dae845a + 0c0b063 commit 86cd302
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/build/provider/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
portercontext "get.porter.sh/porter/pkg/context"
"get.porter.sh/porter/pkg/manifest"
"github.com/docker/cli/cli/command"
clibuild "github.com/docker/cli/cli/command/image/build"
cliflags "github.com/docker/cli/cli/flags"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
Expand Down Expand Up @@ -43,7 +44,12 @@ func (b *DockerBuilder) BuildInvocationImage(manifest *manifest.Manifest) error
"BUNDLE_DIR": &build.BUNDLE_DIR,
},
}
tar, err := archive.TarWithOptions(path, &archive.TarOptions{})

excludes, err := clibuild.ReadDockerignore(path)
if err != nil {
return err
}
tar, err := archive.TarWithOptions(path, &archive.TarOptions{ExcludePatterns: excludes})
if err != nil {
return err
}
Expand Down
30 changes: 30 additions & 0 deletions tests/build_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// +build integration

package tests

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"get.porter.sh/porter/pkg/porter"
)

func TestBuild_withDockerignore(t *testing.T) {
p := porter.NewTestPorter(t)
p.SetupIntegrationTest()
defer p.CleanupIntegrationTest()
p.Debug = false

p.TestConfig.TestContext.AddTestDirectory(filepath.Join(p.TestDir, "testdata/bundles/outputs-example"), ".")

// Create .dockerignore file which ignores the Dockerfile
err := p.FileSystem.WriteFile(".dockerignore", []byte("Dockerfile"), 0644)
require.NoError(t, err)

// Verify Porter uses the .dockerignore file
opts := porter.BuildOptions{}
err = p.Build(opts)
require.EqualError(t, err, "unable to build CNAB invocation image: Error response from daemon: Cannot locate specified Dockerfile: Dockerfile")
}

0 comments on commit 86cd302

Please sign in to comment.