Fix GitRepository include for nested paths
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
fd636d6c39
commit
add5444f16
|
@ -756,6 +756,12 @@ var _ = Describe("GitRepositoryReconciler", func() {
|
||||||
createFiles: []string{"dir1", "dir2"},
|
createFiles: []string{"dir1", "dir2"},
|
||||||
checkFiles: []string{"sub/dir1", "sub/dir2"},
|
checkFiles: []string{"sub/dir1", "sub/dir2"},
|
||||||
}),
|
}),
|
||||||
|
Entry("to nested path", includeTestCase{
|
||||||
|
fromPath: "",
|
||||||
|
toPath: "sub/nested",
|
||||||
|
createFiles: []string{"dir1", "dir2"},
|
||||||
|
checkFiles: []string{"sub/nested/dir1", "sub/nested/dir2"},
|
||||||
|
}),
|
||||||
Entry("from and to path", includeTestCase{
|
Entry("from and to path", includeTestCase{
|
||||||
fromPath: "nested",
|
fromPath: "nested",
|
||||||
toPath: "sub",
|
toPath: "sub",
|
||||||
|
|
|
@ -354,27 +354,35 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
|
||||||
return s.Copy(artifact, f)
|
return s.Copy(artifact, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyToPath copies the contents of the given atrifact to the path.
|
// CopyToPath copies the contents of the given artifact to the path.
|
||||||
func (s *Storage) CopyToPath(atrifact *sourcev1.Artifact, subPath, toPath string) error {
|
func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error {
|
||||||
// create a tmp directory to store artifact
|
// create a tmp directory to store artifact
|
||||||
tmp, err := ioutil.TempDir("", "flux-include")
|
tmp, err := ioutil.TempDir("", "flux-include")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmp)
|
defer os.RemoveAll(tmp)
|
||||||
|
|
||||||
// read artifact file content
|
// read artifact file content
|
||||||
localPath := s.LocalPath(*atrifact)
|
localPath := s.LocalPath(*artifact)
|
||||||
f, err := os.Open(localPath)
|
f, err := os.Open(localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
// untar the artifact
|
// untar the artifact
|
||||||
untarPath := filepath.Join(tmp, "tar")
|
untarPath := filepath.Join(tmp, "tar")
|
||||||
if _, err = untar.Untar(f, untarPath); err != nil {
|
if _, err = untar.Untar(f, untarPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// copy the folder to the path
|
|
||||||
|
// create the destination parent dir
|
||||||
|
if err = os.MkdirAll(filepath.Dir(toPath), os.ModePerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the artifact content to the destination dir
|
||||||
fromPath := filepath.Join(untarPath, subPath)
|
fromPath := filepath.Join(untarPath, subPath)
|
||||||
if err := fs.RenameWithFallback(fromPath, toPath); err != nil {
|
if err := fs.RenameWithFallback(fromPath, toPath); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -62,6 +62,9 @@ type GitRepositorySpec struct {
|
||||||
// This option is available only when using the 'go-git' GitImplementation.
|
// This option is available only when using the 'go-git' GitImplementation.
|
||||||
// +optional
|
// +optional
|
||||||
RecurseSubmodules bool `json:"recurseSubmodules,omitempty"`
|
RecurseSubmodules bool `json:"recurseSubmodules,omitempty"`
|
||||||
|
|
||||||
|
// Extra git repositories to map into the repository
|
||||||
|
Include []GitRepositoryInclude `json:"include,omitempty"`
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -529,8 +532,8 @@ spec:
|
||||||
include:
|
include:
|
||||||
- repository:
|
- repository:
|
||||||
name: app-repo
|
name: app-repo
|
||||||
from: deploy/kubernetes
|
fromPath: deploy/kubernetes
|
||||||
to: base/app
|
toPath: base/app
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Secret
|
kind: Secret
|
||||||
|
@ -543,9 +546,9 @@ data:
|
||||||
password: <GitHub Token>
|
password: <GitHub Token>
|
||||||
```
|
```
|
||||||
|
|
||||||
The `from` and `to` parameters allows you to limit the files included and where they will be
|
The `fromPath` and `toPath` parameters allows you to limit the files included and where they will be
|
||||||
copied to in the main repository. If you do not specify a value for `from` all files in the
|
copied to in the main repository. If you do not specify a value for `fromPath` all files in the
|
||||||
repository will be included. The `to` value will default to the name of the repository.
|
repository will be included. The `toPath` value will default to the name of the repository.
|
||||||
|
|
||||||
## Status examples
|
## Status examples
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue