Skip to content

Commit

Permalink
fix: use ArgoCD application path relatively to git root
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil committed Sep 5, 2023
1 parent 5dc1b5e commit 92f0617
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions internal/myks/globe.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ type Globe struct {

/// Runtime data

// Git repository path prefix (non-empty if running in a subdirectory of a git repository)
GitPathPrefix string
// Git repository branch
GitRepoBranch string
// Git repository URL
Expand Down Expand Up @@ -128,6 +130,10 @@ func New(rootDir string) *Globe {
log.Fatal().Err(err).Msg("Unable to set defaults")
}

if err := g.setGitPathPrefix(); err != nil {
log.Warn().Err(err).Msg("Unable to set git path prefix")
}

if err := g.setGitRepoUrl(); err != nil {
log.Warn().Err(err).Msg("Unable to set git repo url")
}
Expand Down Expand Up @@ -351,6 +357,24 @@ func (g *Globe) collectEnvironmentsInPath(searchPath string) {
}
}

func (g *Globe) setGitPathPrefix() error {
if g.GitPathPrefix == "" {
gitArgs := []string{}
if g.RootDir != "" {
gitArgs = append(gitArgs, "-C", g.RootDir)
}
gitArgs = append(gitArgs, "rev-parse", "--show-prefix")
result, err := runCmd("git", nil, gitArgs, func(name string, args []string) {
log.Debug().Msg(msgRunCmd("set git path prefix", name, args))
})
if err != nil {
return err
}
g.GitPathPrefix = strings.Trim(result.Stdout, "\n")
}
return nil
}

func (g *Globe) setGitRepoUrl() error {
if g.GitRepoUrl == "" {
result, err := runCmd("git", nil, []string{"remote", "get-url", "origin"}, func(name string, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion internal/myks/plugin_argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (a *Application) argoCDPrepareDefaults() (filename string, err error) {

data := Data{
AppName: a.Name,
AppPath: a.getDestinationDir(),
AppPath: filepath.Join(a.e.g.GitPathPrefix, a.getDestinationDir()),
RepoURL: a.e.g.GitRepoUrl,
TargetRevision: a.e.g.GitRepoBranch,
}
Expand Down

0 comments on commit 92f0617

Please sign in to comment.