Add support for .dockerignore file

This commit is contained in:
Priya Wadhwa
2018-10-19 09:58:50 -07:00
parent adac8d495d
commit 3fc43f4c73
5 changed files with 54 additions and 62 deletions
+21
View File
@@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"path/filepath"
"strconv"
"strings"
@@ -168,3 +169,23 @@ func saveStage(index int, stages []instructions.Stage) bool {
}
return false
}
// DockerignoreExists returns true if .dockerignore exists in the source context
func DockerignoreExists(opts *config.KanikoOptions) bool {
path := filepath.Join(opts.SrcContext, ".dockerignore")
return util.FilepathExists(path)
}
// ParseDockerignore returns a list of all paths in .dockerignore
func ParseDockerignore(opts *config.KanikoOptions) ([]string, error) {
path := filepath.Join(opts.SrcContext, ".dockerignore")
contents, err := ioutil.ReadFile(path)
if err != nil {
return nil, errors.Wrap(err, "parsing .dockerignore")
}
return strings.FieldsFunc(string(contents), split), nil
}
func split(r rune) bool {
return r == '\n' || r == ' '
}