mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-17 23:15:33 +02:00
Merge pull request #736 from huguesalary/resolve-paths
Resolve relative paths to absolute paths in command line arguments
This commit is contained in:
@@ -81,6 +81,9 @@ var RootCmd = &cobra.Command{
|
||||
if err := executor.CheckPushPermissions(opts); err != nil {
|
||||
exit(errors.Wrap(err, "error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again"))
|
||||
}
|
||||
if err := resolveRelativePaths(); err != nil {
|
||||
exit(errors.Wrap(err, "error resolving relative paths to absolute paths"))
|
||||
}
|
||||
if err := os.Chdir("/"); err != nil {
|
||||
exit(errors.Wrap(err, "error changing to root dir"))
|
||||
}
|
||||
@@ -228,6 +231,37 @@ func resolveSourceContext() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolveRelativePaths() error {
|
||||
optsPaths := []*string{
|
||||
&opts.DockerfilePath,
|
||||
&opts.SrcContext,
|
||||
&opts.CacheDir,
|
||||
&opts.TarPath,
|
||||
&opts.DigestFile,
|
||||
}
|
||||
|
||||
for _, p := range optsPaths {
|
||||
// Skip empty path
|
||||
if *p == "" {
|
||||
continue
|
||||
}
|
||||
// Skip path that is already absolute
|
||||
if filepath.IsAbs(*p) {
|
||||
logrus.Debugf("Path %s is absolute, skipping", *p)
|
||||
continue
|
||||
}
|
||||
|
||||
// Resolve relative path to absolute path
|
||||
var err error
|
||||
relp := *p // save original relative path
|
||||
if *p, err = filepath.Abs(*p); err != nil {
|
||||
return errors.Wrapf(err, "Couldn't resolve relative path %s to an absolute path", *p)
|
||||
}
|
||||
logrus.Debugf("Resolved relative path %s to %s", relp, *p)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exit(err error) {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user