From dbdf116f8c597988e7b8ea807309cd8e0cf0ef89 Mon Sep 17 00:00:00 2001 From: priyawadhwa Date: Mon, 9 Jul 2018 14:25:27 -0400 Subject: [PATCH] make path to Dockerfile an absolute path (#228) * make path to dockerfile an absolute path * refactored checking dockerfile path --- cmd/executor/cmd/root.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index b0c714aa5..753388926 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -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 {