fix #50 - exclude anything in .gitignore from being copied into the job volume

This commit is contained in:
Casey Lee 2020-03-09 18:32:48 -07:00
parent b7fcf137ab
commit 7f88f81bf6
No known key found for this signature in database
GPG key ID: 1899120ECD0A1784
3 changed files with 16 additions and 1 deletions

4
go.mod
View file

@ -9,7 +9,7 @@ require (
github.com/andreaskoch/go-fswatch v1.0.0
github.com/containerd/containerd v1.3.3 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v0.0.0-20200229013735-71373c6105e3
github.com/docker/docker v0.0.0-20200229013735-71373c6105e3
github.com/docker/go-connections v0.4.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/go-ini/ini v1.41.0
@ -21,6 +21,7 @@ require (
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/mgutz/str v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20160105113617-38717d0a108c
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
@ -51,4 +52,5 @@ require (
)
replace github.com/docker/docker => github.com/docker/docker v0.0.0-20200229013735-71373c6105e3
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a

2
go.sum
View file

@ -101,6 +101,8 @@ github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnG
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/monochromegane/go-gitignore v0.0.0-20160105113617-38717d0a108c h1:RRUev95N3Gq4Aog4avFzXJA2V8fgXmND+cvcH7KLMyk=
github.com/monochromegane/go-gitignore v0.0.0-20160105113617-38717d0a108c/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=

View file

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
gitignore "github.com/monochromegane/go-gitignore"
"github.com/nektos/act/pkg/common"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
@ -305,6 +306,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string) common.E
}
}
// nolint: gocyclo
func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Executor {
return func(ctx context.Context) error {
logger := common.Logger(ctx)
@ -323,6 +325,11 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
}
log.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath)
gitignore, err := gitignore.NewGitIgnore(filepath.Join(srcPath, ".gitignore"))
if err != nil {
log.Debugf("Error loading .gitignore: %v", err)
}
err = filepath.Walk(srcPath, func(file string, fi os.FileInfo, err error) error {
if err != nil {
return err
@ -333,6 +340,10 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
return nil
}
if gitignore != nil && gitignore.Match(file, fi.IsDir()) {
return nil
}
// create a new dir/file header
header, err := tar.FileInfoHeader(fi, fi.Name())
if err != nil {