Skip to content

Commit deb0404

Browse files
authored
Add pro:docker option (#334)
1 parent 469334f commit deb0404

22 files changed

+345
-110
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ FROM alpine:3.19 AS dagger
44

55
# TODO: pull the binary from registry.dagger.io/cli:v0.9.8 (or similar) when
66
# https://github.com/dagger/dagger/issues/6887 is resolved
7-
ARG DAGGER_VERSION=v0.9.8
7+
ARG DAGGER_VERSION=v0.11.6
88
ADD https://github.com/dagger/dagger/releases/download/${DAGGER_VERSION}/dagger_${DAGGER_VERSION}_linux_amd64.tar.gz /tmp
99
RUN tar zxf /tmp/dagger_${DAGGER_VERSION}_linux_amd64.tar.gz -C /tmp
1010
RUN mv /tmp/dagger /bin/dagger
1111

1212
FROM golang:1.22-alpine
1313

14-
ARG DAGGER_VERSION=v0.9.8
14+
ARG DAGGER_VERSION=v0.11.6
1515

1616
WORKDIR /src
1717
RUN apk add --no-cache git wget bash jq

arguments/docker.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,38 @@ var (
4343
Value: docker.DefaultBoringTagFormat,
4444
}
4545

46+
ProDockerRegistryFlag = &cli.StringFlag{
47+
Name: "pro-registry",
48+
Usage: "Prefix the image name with the registry provided",
49+
Value: "docker.io",
50+
}
51+
ProDockerOrgFlag = &cli.StringFlag{
52+
Name: "pro-org",
53+
Usage: "Overrides the organization of the images",
54+
Value: "grafana",
55+
}
56+
ProDockerRepoFlag = &cli.StringFlag{
57+
Name: "pro-repo",
58+
Usage: "Overrides the docker repository of the built images",
59+
Value: "grafana-pro",
60+
}
61+
ProTagFormatFlag = &cli.StringFlag{
62+
Name: "pro-tag-format",
63+
Usage: "Provide a go template for formatting the docker tag(s) for Grafana Pro images",
64+
Value: docker.DefaultProTagFormat,
65+
}
66+
4667
DockerRegistry = pipeline.NewStringFlagArgument(DockerRegistryFlag)
4768
DockerOrg = pipeline.NewStringFlagArgument(DockerOrgFlag)
4869
AlpineImage = pipeline.NewStringFlagArgument(AlpineImageFlag)
4970
UbuntuImage = pipeline.NewStringFlagArgument(UbuntuImageFlag)
5071
TagFormat = pipeline.NewStringFlagArgument(TagFormatFlag)
5172
UbuntuTagFormat = pipeline.NewStringFlagArgument(UbuntuTagFormatFlag)
5273
BoringTagFormat = pipeline.NewStringFlagArgument(BoringTagFormatFlag)
74+
75+
// The docker registry for Grafana Pro is often different than the one for Grafana & Enterprise
76+
ProDockerRegistry = pipeline.NewStringFlagArgument(ProDockerRegistryFlag)
77+
ProDockerOrg = pipeline.NewStringFlagArgument(ProDockerOrgFlag)
78+
ProDockerRepo = pipeline.NewStringFlagArgument(ProDockerRepoFlag)
79+
ProTagFormat = pipeline.NewStringFlagArgument(ProTagFormatFlag)
5380
)

arguments/golang.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
const (
9-
DefaultGoVersion = "1.22.4"
9+
DefaultGoVersion = "1.22.5"
1010
DefaultViceroyVersion = "v0.4.0"
1111
)
1212

arguments/grafana.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ type GrafanaDirectoryOpts struct {
5959
PatchesRef string
6060
}
6161

62-
func (o *GrafanaDirectoryOpts) githubToken(ctx context.Context) (string, error) {
62+
func githubToken(ctx context.Context, token string) (string, error) {
6363
// Since GrafanaDir was not provided, we must clone it.
64-
ght := o.GitHubToken
64+
ght := token
6565

6666
// If GitHubToken was not set from flag
6767
if ght != "" {
@@ -79,7 +79,7 @@ func (o *GrafanaDirectoryOpts) githubToken(ctx context.Context) (string, error)
7979
return token, nil
8080
}
8181

82-
func GrafanaDirectoryOptsFromFlags(ctx context.Context, c cliutil.CLIContext) (*GrafanaDirectoryOpts, error) {
82+
func GrafanaDirectoryOptsFromFlags(c cliutil.CLIContext) *GrafanaDirectoryOpts {
8383
return &GrafanaDirectoryOpts{
8484
GrafanaRepo: c.String("grafana-repo"),
8585
EnterpriseRepo: c.String("enterprise-repo"),
@@ -91,7 +91,7 @@ func GrafanaDirectoryOptsFromFlags(ctx context.Context, c cliutil.CLIContext) (*
9191
PatchesRepo: c.String("patches-repo"),
9292
PatchesPath: c.String("patches-path"),
9393
PatchesRef: c.String("patches-ref"),
94-
}, nil
94+
}
9595
}
9696

9797
func cloneOrMount(ctx context.Context, client *dagger.Client, localPath, repo, ref string, ght string) (*dagger.Directory, error) {
@@ -156,12 +156,9 @@ func applyPatches(ctx context.Context, client *dagger.Client, src *dagger.Direct
156156
}
157157

158158
func grafanaDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, error) {
159-
o, err := GrafanaDirectoryOptsFromFlags(ctx, opts.CLIContext)
160-
if err != nil {
161-
return nil, err
162-
}
159+
o := GrafanaDirectoryOptsFromFlags(opts.CLIContext)
163160

164-
ght, err := o.githubToken(ctx)
161+
ght, err := githubToken(ctx, o.GitHubToken)
165162
if err != nil {
166163
log.Println("No github token found:", err)
167164
}
@@ -202,17 +199,14 @@ func grafanaDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, er
202199

203200
func enterpriseDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, error) {
204201
// Get the Grafana directory...
205-
o, err := GrafanaDirectoryOptsFromFlags(ctx, opts.CLIContext)
206-
if err != nil {
207-
return nil, err
208-
}
202+
o := GrafanaDirectoryOptsFromFlags(opts.CLIContext)
209203

210204
grafanaDir, err := grafanaDirectory(ctx, opts)
211205
if err != nil {
212206
return nil, fmt.Errorf("error initializing grafana directory: %w", err)
213207
}
214208

215-
ght, err := o.githubToken(ctx)
209+
ght, err := githubToken(ctx, o.GitHubToken)
216210
if err != nil {
217211
return nil, nil
218212
}

arguments/pro.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package arguments
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/grafana/grafana-build/cliutil"
8+
"github.com/grafana/grafana-build/pipeline"
9+
"github.com/urfave/cli/v2"
10+
)
11+
12+
var ProDirectoryFlags = []cli.Flag{
13+
&cli.StringFlag{
14+
Name: "hosted-grafana-dir",
15+
Usage: "Local clone of HG to use, instead of git cloning",
16+
Required: false,
17+
},
18+
&cli.StringFlag{
19+
Name: "hosted-grafana-repo",
20+
Usage: "https `.git` repository to use for hosted-grafana",
21+
Required: false,
22+
Value: "https://github.com/grafana/hosted-grafana.git",
23+
},
24+
&cli.StringFlag{
25+
Name: "hosted-grafana-ref",
26+
Usage: "git ref to checkout",
27+
Required: false,
28+
Value: "main",
29+
},
30+
}
31+
32+
// ProDirectory will provide the valueFunc that initializes and returns a *dagger.Directory that has a repository that has the Grafana Pro docker image.
33+
// Where possible, when cloning and no authentication options are provided, the valuefunc will try to use the configured github CLI for cloning.
34+
var ProDirectory = pipeline.Argument{
35+
Name: "pro-dir",
36+
Description: "The source tree of that has the Dockerfile for Grafana Pro",
37+
Flags: ProDirectoryFlags,
38+
ValueFunc: proDirectory,
39+
}
40+
41+
type ProDirectoryOpts struct {
42+
GitHubToken string
43+
HGDir string
44+
HGRepo string
45+
HGRef string
46+
}
47+
48+
func ProDirectoryOptsFromFlags(c cliutil.CLIContext) *ProDirectoryOpts {
49+
return &ProDirectoryOpts{
50+
GitHubToken: c.String("github-token"),
51+
HGDir: c.String("hosted-grafana-dir"),
52+
HGRepo: c.String("hosted-grafana-repo"),
53+
HGRef: c.String("hosted-grafana-ref"),
54+
}
55+
}
56+
57+
func proDirectory(ctx context.Context, opts *pipeline.ArgumentOpts) (any, error) {
58+
o := ProDirectoryOptsFromFlags(opts.CLIContext)
59+
ght, err := githubToken(ctx, o.GitHubToken)
60+
if err != nil {
61+
return nil, fmt.Errorf("could not get GitHub token: %w", err)
62+
}
63+
64+
src, err := cloneOrMount(ctx, opts.Client, o.HGDir, o.HGRepo, o.HGRef, ght)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
return src, nil
70+
}

artifacts/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (b *Backend) PublishFile(ctx context.Context, opts *pipeline.ArtifactPublis
9292
panic("not implemented") // TODO: Implement
9393
}
9494

95-
func (b *Backend) PublisDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
95+
func (b *Backend) PublishDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
9696
panic("not implemented") // TODO: Implement
9797
}
9898

artifacts/frontend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (f *Frontend) PublishFile(ctx context.Context, opts *pipeline.ArtifactPubli
5858
panic("not implemented") // TODO: Implement
5959
}
6060

61-
func (f *Frontend) PublisDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
61+
func (f *Frontend) PublishDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
6262
panic("not implemented") // TODO: Implement
6363
}
6464

artifacts/npm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (f *NPMPackages) PublishFile(ctx context.Context, opts *pipeline.ArtifactPu
5757
panic("not implemented") // TODO: Implement
5858
}
5959

60-
func (f *NPMPackages) PublisDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
60+
func (f *NPMPackages) PublishDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
6161
panic("not implemented") // TODO: Implement
6262
}
6363

artifacts/package_deb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (d *Deb) PublishFile(ctx context.Context, opts *pipeline.ArtifactPublishFil
9999
panic("not implemented") // TODO: Implement
100100
}
101101

102-
func (d *Deb) PublisDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
102+
func (d *Deb) PublishDir(ctx context.Context, opts *pipeline.ArtifactPublishDirOpts) error {
103103
panic("not implemented") // TODO: Implement
104104
}
105105

0 commit comments

Comments
 (0)