Skip to content

Commit

Permalink
fix: Add missing implementation for function excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
asalkeld committed Jan 26, 2022
1 parent 8263662 commit 57779a3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions mocks/mock_containerengine/mock_containerengine.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ func Create(s *stack.Stack, t *target.Target) error {
fh.Close()

buildArgs := map[string]string{"PROVIDER": t.Provider}
err = cr.Build(path.Base(fh.Name()), f.ContextDirectory, f.ImageTagName(s, t.Provider), buildArgs)
err = cr.Build(path.Base(fh.Name()), f.ContextDirectory, f.ImageTagName(s, t.Provider), buildArgs, f.Excludes)
if err != nil {
return err
}
}

for _, c := range s.Containers {
buildArgs := map[string]string{"PROVIDER": t.Provider}
err := cr.Build(path.Join(c.Context, c.Dockerfile), c.ContextDirectory, c.ImageTagName(s, t.Provider), buildArgs)
err := cr.Build(path.Join(c.Context, c.Dockerfile), c.ContextDirectory, c.ImageTagName(s, t.Provider), buildArgs, []string{})
if err != nil {
return err
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func CreateBaseDev(s *stack.Stack) error {
return err
}

if err := ce.Build(path.Base(f.Name()), s.Dir, rt.DevImageName(), map[string]string{}); err != nil {
if err := ce.Build(path.Base(f.Name()), s.Dir, rt.DevImageName(), map[string]string{}, []string{}); err != nil {
return err
}
imagesToBuild[lang] = rt.DevImageName()
Expand Down
7 changes: 4 additions & 3 deletions pkg/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestCreateBaseDev(t *testing.T) {
s := stack.New("", dir)
s.Functions = map[string]stack.Function{"foo": {Handler: "functions/list.ts"}}

me.EXPECT().Build(gomock.Any(), dir, "nitric-ts-dev", map[string]string{})
me.EXPECT().Build(gomock.Any(), dir, "nitric-ts-dev", map[string]string{}, []string{})

containerengine.DiscoveredEngine = me

Expand All @@ -54,8 +54,8 @@ func TestCreateBaseDev(t *testing.T) {
func TestCreate(t *testing.T) {
ctrl := gomock.NewController(t)
me := mock_containerengine.NewMockContainerEngine(ctrl)
me.EXPECT().Build(gomock.Any(), "", "corp-abc-dev:123456", map[string]string{"PROVIDER": "aws"})
me.EXPECT().Build("Dockerfile.custom", "", "corp-xyz-dev:444444", map[string]string{"PROVIDER": "aws"})
me.EXPECT().Build(gomock.Any(), "", "corp-abc-dev:123456", map[string]string{"PROVIDER": "aws"}, []string{"data/*"})
me.EXPECT().Build("Dockerfile.custom", "", "corp-xyz-dev:444444", map[string]string{"PROVIDER": "aws"}, []string{})

containerengine.DiscoveredEngine = me

Expand All @@ -69,6 +69,7 @@ func TestCreate(t *testing.T) {
Tag: "corp-abc-dev:123456",
},
BuildScripts: []string{"ls"},
Excludes: []string{"data/*"},
},
},
Containers: map[string]stack.Container{
Expand Down
7 changes: 4 additions & 3 deletions pkg/containerengine/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ func (d *docker) Type() string {
return "docker"
}

func tarContextDir(relDockerfile, contextDir string) (io.ReadCloser, error) {
func tarContextDir(relDockerfile, contextDir string, extraExcludes []string) (io.ReadCloser, error) {
excludes, err := build.ReadDockerignore(contextDir)
if err != nil {
return nil, err
}

excludes = append(excludes, utils.NitricLogDir(contextDir))
excludes = append(excludes, extraExcludes...)

if err := build.ValidateContextDirectory(contextDir, excludes); err != nil {
return nil, errors.Errorf("error checking context: '%s'.", err)
Expand All @@ -93,11 +94,11 @@ func tarContextDir(relDockerfile, contextDir string) (io.ReadCloser, error) {
})
}

func (d *docker) Build(dockerfile, srcPath, imageTag string, buildArgs map[string]string) error {
func (d *docker) Build(dockerfile, srcPath, imageTag string, buildArgs map[string]string, excludes []string) error {
ctx, cancel := context.WithTimeout(context.Background(), buildTimeout())
defer cancel()

dockerBuildContext, err := tarContextDir(dockerfile, srcPath)
dockerBuildContext, err := tarContextDir(dockerfile, srcPath, excludes)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/containerengine/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (p *podman) Type() string {
return "podman"
}

func (p *podman) Build(dockerfile, path, imageTag string, buildArgs map[string]string) error {
return p.docker.Build(dockerfile, path, imageTag, buildArgs)
func (p *podman) Build(dockerfile, path, imageTag string, buildArgs map[string]string, excludes []string) error {
return p.docker.Build(dockerfile, path, imageTag, buildArgs, excludes)
}

func (p *podman) ListImages(stackName, containerName string) ([]Image, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/containerengine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ContainerLogger interface {

type ContainerEngine interface {
Type() string
Build(dockerfile, path, imageTag string, buildArgs map[string]string) error
Build(dockerfile, path, imageTag string, buildArgs map[string]string, excludes []string) error
ListImages(stackName, containerName string) ([]Image, error)
ImagePull(rawImage string) error
NetworkCreate(name string) error
Expand Down

0 comments on commit 57779a3

Please sign in to comment.