diff --git a/arguments/grafana.go b/arguments/grafana.go index 688bb8b..5b242b2 100644 --- a/arguments/grafana.go +++ b/arguments/grafana.go @@ -154,6 +154,23 @@ func grafanaDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, er return nil, err } + gitContainer := opts.Client.Container().From("alpine/git"). + WithWorkdir("/src"). + WithMountedDirectory("/src/.git", src.Directory(".git")). + WithEntrypoint([]string{}) + + commitFile := gitContainer. + WithExec([]string{"/bin/sh", "-c", "git rev-parse HEAD > .buildinfo.grafana-commit"}). + File("/src/.buildinfo.grafana-commit") + + branchFile := gitContainer. + WithExec([]string{"/bin/sh", "-c", "git rev-parse --abbrev-ref HEAD > .buildinfo.grafana-branch"}). + File("/src/.buildinfo.grafana-branch") + + src = src. + WithFile(".buildinfo.commit", commitFile). + WithFile(".buildinfo.branch", branchFile) + if o.PatchesRepo != "" { withPatches, err := applyPatches(ctx, opts.Client, src, o.PatchesRepo, o.PatchesPath, o.PatchesRef, ght) if err != nil { diff --git a/backend/build.go b/backend/build.go index 079787c..4b0f69d 100644 --- a/backend/build.go +++ b/backend/build.go @@ -54,7 +54,7 @@ func Build( out string, opts *BuildOpts, ) *dagger.Directory { - vcsinfo := GetVCSInfo(d, src, opts.Version, opts.Enterprise) + vcsinfo := GetVCSInfo(src, opts.Version, opts.Enterprise) builder = WithVCSInfo(builder, vcsinfo, opts.Enterprise) ldflags := LDFlagsDynamic(vcsinfo) diff --git a/backend/builder.go b/backend/builder.go index 844f8a6..bb5c8aa 100644 --- a/backend/builder.go +++ b/backend/builder.go @@ -149,7 +149,7 @@ func Builder( return nil, err } - commitInfo := GetVCSInfo(d, src, version, opts.Enterprise) + commitInfo := GetVCSInfo(src, version, opts.Enterprise) builder = withCue(builder, src). WithDirectory("/src/", src, dagger.ContainerWithDirectoryOpts{ diff --git a/backend/vcsinfo.go b/backend/vcsinfo.go index cc9bd65..c53e9c5 100644 --- a/backend/vcsinfo.go +++ b/backend/vcsinfo.go @@ -27,22 +27,15 @@ func WithVCSInfo(c *dagger.Container, info *VCSInfo, enterprise bool) *dagger.Co } // VCSInfo gets the VCS data from the directory 'src', writes them to a file on the given container, and returns the files which can be used in other containers. -func GetVCSInfo(d *dagger.Client, src *dagger.Directory, version string, enterprise bool) *VCSInfo { - c := d.Container().From("alpine/git"). - WithEntrypoint([]string{}). - WithMountedDirectory("/src", src). - WithWorkdir("/src"). - WithExec([]string{"/bin/sh", "-c", "git rev-parse HEAD > .buildinfo.commit"}). - WithExec([]string{"/bin/sh", "-c", "git rev-parse --abbrev-ref HEAD > .buildinfo.branch"}) - +func GetVCSInfo(src *dagger.Directory, version string, enterprise bool) *VCSInfo { info := &VCSInfo{ Version: version, - Commit: c.File(".buildinfo.commit"), - Branch: c.File(".buildinfo.branch"), + Commit: src.File(".buildinfo.commit"), + Branch: src.File(".buildinfo.branch"), } if enterprise { - info.EnterpriseCommit = c.File(".buildinfo.enterprise-commit") + info.EnterpriseCommit = src.File(".buildinfo.enterprise-commit") } return info