mirror of https://github.com/grafana/grafana.git
Build: Use absolute paths when passed relatives (#106122)
This commit is contained in:
parent
8a11a9bd6d
commit
312fcb4a54
|
@ -3,7 +3,6 @@ package arguments
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -95,16 +94,30 @@ func GrafanaDirectoryOptsFromFlags(c cliutil.CLIContext) *GrafanaDirectoryOpts {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneOrMount(ctx context.Context, client *dagger.Client, localPath, repo, ref string, ght string) (*dagger.Directory, error) {
|
func cloneOrMount(ctx context.Context, client *dagger.Client, localPath, repo, ref string, ght string) (*dagger.Directory, error) {
|
||||||
// If GrafanaDir was provided, then we can just use that one.
|
if localPath != "" {
|
||||||
if path := localPath; path != "" {
|
absolute, err := filepath.Abs(localPath)
|
||||||
slog.Info("Using local Grafana found", "path", path)
|
if err != nil {
|
||||||
return daggerutil.HostDir(client, path)
|
return nil, fmt.Errorf("error getting absolute path for local dir: %w", err)
|
||||||
|
}
|
||||||
|
localPath = absolute
|
||||||
|
slog.Info("Using local directory for repository", "path", localPath, "repo", repo)
|
||||||
|
return daggerutil.HostDir(client, localPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
ght, err := githubToken(ctx, ght)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error acquiring GitHub token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return git.CloneWithGitHubToken(client, ght, repo, ref)
|
return git.CloneWithGitHubToken(client, ght, repo, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyPatches(ctx context.Context, client *dagger.Client, src *dagger.Directory, repo, patchesPath, ref, ght string) (*dagger.Directory, error) {
|
func applyPatches(ctx context.Context, client *dagger.Client, src *dagger.Directory, repo, patchesPath, ref, ght string) (*dagger.Directory, error) {
|
||||||
|
ght, err := githubToken(ctx, ght)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error acquiring GitHub token: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Clone the patches repository on 'main'
|
// Clone the patches repository on 'main'
|
||||||
dir, err := git.CloneWithGitHubToken(client, ght, repo, ref)
|
dir, err := git.CloneWithGitHubToken(client, ght, repo, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,12 +157,7 @@ func applyPatches(ctx context.Context, client *dagger.Client, src *dagger.Direct
|
||||||
func grafanaDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, error) {
|
func grafanaDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, error) {
|
||||||
o := GrafanaDirectoryOptsFromFlags(opts.CLIContext)
|
o := GrafanaDirectoryOptsFromFlags(opts.CLIContext)
|
||||||
|
|
||||||
ght, err := githubToken(ctx, o.GitHubToken)
|
src, err := cloneOrMount(ctx, opts.Client, o.GrafanaDir, o.GrafanaRepo, o.GrafanaRef, o.GitHubToken)
|
||||||
if err != nil {
|
|
||||||
log.Println("No github token found:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
src, err := cloneOrMount(ctx, opts.Client, o.GrafanaDir, o.GrafanaRepo, o.GrafanaRef, ght)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -172,7 +180,7 @@ func grafanaDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, er
|
||||||
WithFile(".buildinfo.branch", branchFile)
|
WithFile(".buildinfo.branch", branchFile)
|
||||||
|
|
||||||
if o.PatchesRepo != "" {
|
if o.PatchesRepo != "" {
|
||||||
withPatches, err := applyPatches(ctx, opts.Client, src, o.PatchesRepo, o.PatchesPath, o.PatchesRef, ght)
|
withPatches, err := applyPatches(ctx, opts.Client, src, o.PatchesRepo, o.PatchesPath, o.PatchesRef, o.GitHubToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
opts.Log.Debug("patch application skipped", "error", err)
|
opts.Log.Debug("patch application skipped", "error", err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,12 +217,7 @@ func enterpriseDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any,
|
||||||
return nil, fmt.Errorf("error initializing grafana directory: %w", err)
|
return nil, fmt.Errorf("error initializing grafana directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ght, err := githubToken(ctx, o.GitHubToken)
|
src, err := cloneOrMount(ctx, opts.Client, o.EnterpriseDir, o.EnterpriseRepo, o.EnterpriseRef, o.GitHubToken)
|
||||||
if err != nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
src, err := cloneOrMount(ctx, opts.Client, o.EnterpriseDir, o.EnterpriseRepo, o.EnterpriseRef, ght)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue