feat: add containerimage support, solve ##1734
This commit is contained in:
parent
e328007bc1
commit
cf6f7a5417
|
|
@ -395,7 +395,12 @@ func copyDockerfile() error {
|
||||||
return errors.Wrap(err, "copying dockerfile")
|
return errors.Wrap(err, "copying dockerfile")
|
||||||
}
|
}
|
||||||
dockerignorePath := opts.DockerfilePath + ".dockerignore"
|
dockerignorePath := opts.DockerfilePath + ".dockerignore"
|
||||||
if util.FilepathExists(dockerignorePath) {
|
containerignorePath := opts.DockerfilePath + ".containerignore"
|
||||||
|
if util.FilepathExists(containerignorePath) {
|
||||||
|
if _, err := util.CopyFile(containerignorePath, config.DockerfilePath+".containerignore", util.FileContext{}, util.DoNotChangeUID, util.DoNotChangeGID, fs.FileMode(0o600), true); err != nil {
|
||||||
|
return errors.Wrap(err, "copying Dockerfile.containerignore")
|
||||||
|
}
|
||||||
|
} else if util.FilepathExists(dockerignorePath) {
|
||||||
if _, err := util.CopyFile(dockerignorePath, config.DockerfilePath+".dockerignore", util.FileContext{}, util.DoNotChangeUID, util.DoNotChangeGID, fs.FileMode(0o600), true); err != nil {
|
if _, err := util.CopyFile(dockerignorePath, config.DockerfilePath+".dockerignore", util.FileContext{}, util.DoNotChangeUID, util.DoNotChangeGID, fs.FileMode(0o600), true); err != nil {
|
||||||
return errors.Wrap(err, "copying Dockerfile.dockerignore")
|
return errors.Wrap(err, "copying Dockerfile.dockerignore")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# A .dockerignore file to make sure dockerignore support works
|
||||||
|
ignore/**
|
||||||
|
!ignore/foo
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# A .containerignore file to make sure containerignore support works
|
||||||
|
ignore_relative/**
|
||||||
|
!ignore_relative/foo
|
||||||
|
|
@ -775,17 +775,25 @@ func NewFileContextFromDockerfile(dockerfilePath, buildcontext string) (FileCont
|
||||||
|
|
||||||
// getExcludedFiles returns a list of files to exclude from the .dockerignore
|
// getExcludedFiles returns a list of files to exclude from the .dockerignore
|
||||||
func getExcludedFiles(dockerfilePath, buildcontext string) ([]string, error) {
|
func getExcludedFiles(dockerfilePath, buildcontext string) ([]string, error) {
|
||||||
path := dockerfilePath + ".dockerignore"
|
var path string
|
||||||
if !FilepathExists(path) {
|
|
||||||
|
dockerignorePath := dockerfilePath + ".dockerignore"
|
||||||
|
containerignorePath := dockerfilePath + ".containerignore"
|
||||||
|
if FilepathExists(containerignorePath) {
|
||||||
|
path = containerignorePath
|
||||||
|
} else if FilepathExists(filepath.Join(buildcontext, ".containerignore")) {
|
||||||
|
path = filepath.Join(buildcontext, ".containerignore")
|
||||||
|
} else if FilepathExists(dockerignorePath) {
|
||||||
|
path = dockerignorePath
|
||||||
|
} else if FilepathExists(filepath.Join(buildcontext, ".dockerignore")) {
|
||||||
path = filepath.Join(buildcontext, ".dockerignore")
|
path = filepath.Join(buildcontext, ".dockerignore")
|
||||||
}
|
} else {
|
||||||
if !FilepathExists(path) {
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
logrus.Infof("Using dockerignore file: %v", path)
|
logrus.Infof("Using ignorefile: %v", path)
|
||||||
contents, err := os.ReadFile(path)
|
contents, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "parsing .dockerignore")
|
return nil, errors.Wrap(err, "parsing ignorefile")
|
||||||
}
|
}
|
||||||
reader := bytes.NewBuffer(contents)
|
reader := bytes.NewBuffer(contents)
|
||||||
return dockerignore.ReadAll(reader)
|
return dockerignore.ReadAll(reader)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue