mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-21 11:04:24 +02:00
Add support for .dockerignore file
This commit is contained in:
@@ -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 == ' '
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user