make path to Dockerfile an absolute path (#228)

* make path to dockerfile an absolute path

* refactored checking dockerfile path
This commit is contained in:
priyawadhwa 2018-07-09 14:25:27 -04:00 committed by GitHub
parent 19287f89c5
commit dbdf116f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -86,7 +86,7 @@ var RootCmd = &cobra.Command{
os.Exit(1)
}
ref, image, err := executor.DoBuild(executor.KanikoBuildArgs{
DockerfilePath: dockerfilePath,
DockerfilePath: absouteDockerfilePath(),
SrcContext: srcContext,
SnapshotMode: snapshotMode,
Args: buildArgs,
@ -113,16 +113,28 @@ func checkContained() bool {
func checkDockerfilePath() error {
if util.FilepathExists(dockerfilePath) {
if _, err := filepath.Abs(dockerfilePath); err != nil {
return err
}
return nil
}
// Otherwise, check if the path relative to the build context exists
if util.FilepathExists(filepath.Join(srcContext, dockerfilePath)) {
dockerfilePath = filepath.Join(srcContext, dockerfilePath)
return nil
}
return errors.New("please provide a valid path to a Dockerfile within the build context")
}
func absouteDockerfilePath() string {
if util.FilepathExists(dockerfilePath) {
// Ignore error since we already checked it in checkDockerfilePath()
abs, _ := filepath.Abs(dockerfilePath)
return abs
}
// Otherwise, return path relative to build context
return filepath.Join(srcContext, dockerfilePath)
}
// resolveSourceContext unpacks the source context if it is a tar in a bucket
// it resets srcContext to be the path to the unpacked build context within the image
func resolveSourceContext() error {