refactor: use a common implementation to extract kustomize files
This commit is contained in:
1 file changed
+8
-50
@@ -11,7 +11,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -58,57 +57,16 @@ func TriggerCorePostDeploy(appName string) error {
|
|||||||
|
|
||||||
// TriggerCorePostExtract moves a configured kustomize root path to be in the app root dir
|
// TriggerCorePostExtract moves a configured kustomize root path to be in the app root dir
|
||||||
func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||||
|
destination := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "scheduler-k3s", appName)
|
||||||
kustomizeRootPath := getComputedKustomizeRootPath(appName)
|
kustomizeRootPath := getComputedKustomizeRootPath(appName)
|
||||||
if kustomizeRootPath == "" {
|
return common.CorePostExtract(common.CorePostExtractInput{
|
||||||
return nil
|
AppName: appName,
|
||||||
}
|
SourceWorkDir: sourceWorkDir,
|
||||||
|
Destination: destination,
|
||||||
existingKustomizeDirectory := getKustomizeDirectory(appName)
|
ToExtract: []common.CorePostExtractToExtract{
|
||||||
files, err := filepath.Glob(fmt.Sprintf("%s.*", existingKustomizeDirectory))
|
{Path: kustomizeRootPath, IsDirectory: true, Destination: "kustomization"},
|
||||||
if err != nil {
|
},
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, f := range files {
|
|
||||||
if err := os.Remove(f); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processSpecificKustomizeRootPath := fmt.Sprintf("%s.%s", existingKustomizeDirectory, os.Getenv("DOKKU_PID"))
|
|
||||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
||||||
Trigger: "git-get-property",
|
|
||||||
Args: []string{appName, "source-image"},
|
|
||||||
})
|
})
|
||||||
appSourceImage := results.StdoutContents()
|
|
||||||
|
|
||||||
if appSourceImage == "" {
|
|
||||||
repoDefaultKustomizeRootPath := path.Join(sourceWorkDir, "kustomization")
|
|
||||||
repoKustomizeRootPath := path.Join(sourceWorkDir, kustomizeRootPath)
|
|
||||||
if !common.DirectoryExists(repoKustomizeRootPath) {
|
|
||||||
if kustomizeRootPath != "kustomization" && common.DirectoryExists(repoDefaultKustomizeRootPath) {
|
|
||||||
if err := os.RemoveAll(repoDefaultKustomizeRootPath); err != nil {
|
|
||||||
return fmt.Errorf("Unable to remove existing kustomize directory: %s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return common.TouchDir(fmt.Sprintf("%s.missing", processSpecificKustomizeRootPath))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := common.Copy(repoKustomizeRootPath, processSpecificKustomizeRootPath); err != nil {
|
|
||||||
return fmt.Errorf("Unable to extract kustomize root path: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if kustomizeRootPath != "kustomization" {
|
|
||||||
if err := common.Copy(repoKustomizeRootPath, repoDefaultKustomizeRootPath); err != nil {
|
|
||||||
return fmt.Errorf("Unable to move kustomize root path into place: %s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := common.CopyDirFromImage(appName, appSourceImage, kustomizeRootPath, processSpecificKustomizeRootPath); err != nil {
|
|
||||||
return common.TouchDir(fmt.Sprintf("%s.missing", processSpecificKustomizeRootPath))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TriggerInstall runs the install step for the scheduler-k3s plugin
|
// TriggerInstall runs the install step for the scheduler-k3s plugin
|
||||||
|
|||||||
Reference in new issue
Block a user