-
Notifications
You must be signed in to change notification settings - Fork 559
/
helm.go
66 lines (54 loc) · 1.57 KB
/
helm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"strings"
"github.com/dagger/dagger/ci/util"
)
type Helm struct {
Dagger *Dagger // +private
}
func (h *Helm) Test(ctx context.Context) error {
helmChart := h.Dagger.Source.Directory("helm/dagger")
helm := dag.Container().
From("alpine/helm:3.12.3").
WithDirectory("/tmp/dagger-helm", helmChart).
WithWorkdir("/tmp/dagger-helm")
_, err := helm.
WithExec([]string{"lint"}).
WithExec([]string{"lint", "--debug", "--namespace", "dagger", "--set", "magicache.token=hello-world", "--set", "magicache.enabled=true"}).
WithExec([]string{"template", ".", "--debug", "--namespace", "dagger", "--set", "magicache.token=hello-world", "--set", "magicache.enabled=true"}).
Sync(ctx)
return err
}
func (h *Helm) Publish(
ctx context.Context,
tag string,
// +optional
githubToken *Secret,
// +optional
dryRun bool,
) error {
version := strings.TrimPrefix(tag, "helm/chart/v")
helmChart := h.Dagger.Source.Directory("helm/dagger")
helm := dag.Container().
From("alpine/helm:3.12.3").
WithDirectory("/tmp/dagger-helm", helmChart).
WithWorkdir("/tmp/dagger-helm")
if githubToken != nil {
helm = helm.WithSecretVariable("GITHUB_TOKEN", githubToken)
}
pkgCmd := "helm package ."
if dryRun {
helm = helm.With(util.ShellCmd(pkgCmd))
} else {
helm = helm.
With(util.ShellCmds(
"helm registry login ghcr.io/dagger --username dagger --password $GITHUB_TOKEN",
pkgCmd,
"helm push dagger-helm-"+version+".tgz oci://ghcr.io/dagger",
"helm registry logout ghcr.io/dagger",
))
}
_, err := helm.Sync(ctx)
return err
}