-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathenv_pipeline.go
51 lines (40 loc) · 995 Bytes
/
env_pipeline.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
package main
import (
"context"
"log"
"os"
"path/filepath"
"time"
"dagger.io/dagger"
)
func main() {
ctx := context.Background()
if len(os.Args) < 3 {
log.Fatalf("Incorrect arguments: expected repo, KubeCfgPath")
}
err := run(ctx, os.Args[1], os.Args[2])
if err != nil {
panic(err)
}
}
func run(ctx context.Context, repo, kubeCfgPath string) error {
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
defer c.Close()
kubeCfgFilePath := c.Host().Directory(filepath.Dir(kubeCfgPath)).File(filepath.Base(kubeCfgPath))
repoDir := c.Git(repo).Branch("main").Tree()
_, err = c.Container().From("quay.io/roboll/helmfile:helm3-v0.135.0").
WithWorkdir("/app").
WithMountedDirectory(".", repoDir).
WithFile(".kube/config", kubeCfgFilePath).
WithEnvVariable("FOO", time.Now().String()).
WithExec([]string{"sh", "-c", `
set -ex
helmfile repos
helmfile template > final.yaml
helmfile sync
`}).ExitCode(ctx)
return err
}