func (b *buildFile) addContext(container *env.Container, orig, dest string) error { origPath := path.Join(b.context, orig) destPath := path.Join(container.RootfsPath(), dest) // Preserve the trailing '/' if strings.HasSuffix(dest, "/") { destPath = destPath + "/" } fi, err := os.Stat(origPath) if err != nil { return err } if fi.IsDir() { if err := utils.CopyWithTar(origPath, destPath); err != nil { return err } // First try to unpack the source as an archive } else if err := utils.UntarPath(origPath, destPath); err != nil { utils.Debugf("Couldn't untar %s to %s: %s", origPath, destPath, err) // If that fails, just copy it as a regular file if err := os.MkdirAll(path.Dir(destPath), 0755); err != nil { return err } if err := utils.CopyWithTar(origPath, destPath); err != nil { return err } } return nil }
func (b *buildFile) addRemote(container *env.Container, orig, dest string) error { file, err := utils.Download(orig, ioutil.Discard) if err != nil { return err } defer file.Body.Close() // If the destination is a directory, figure out the filename. if strings.HasSuffix(dest, "/") { u, err := url.Parse(orig) if err != nil { return err } path := u.Path if strings.HasSuffix(path, "/") { path = path[:len(path)-1] } parts := strings.Split(path, "/") filename := parts[len(parts)-1] if filename == "" { return fmt.Errorf("cannot determine filename from url: %s", u) } dest = dest + filename } return container.Inject(file.Body, dest) }