-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_runtime.go
More file actions
98 lines (81 loc) · 3.44 KB
/
workflow_runtime.go
File metadata and controls
98 lines (81 loc) · 3.44 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"context"
"dagger/workflow_runtime/internal/dagger"
"fmt"
)
type WorkflowRuntime struct {
Dir *dagger.Directory
Con *dagger.Container
}
// Setup Proto
func (m *WorkflowRuntime) BuildBaseEnv(ctx context.Context) *WorkflowRuntime {
m.Con = dag.
Container().
From("ubuntu:noble").
WithEnvVariable("DEBIAN_FRONTEND", "noninteractive"). // playwright throws error if distribution is not officially supported
WithEnvVariable("SYSTEMD_TMPFILES_ENABLED", "0"). // playwright throws error if systemd is not available
WithExec([]string{"apt-get", "update"}).
// apt-get update && apt-get install -y curl git unzip gzip xz-utils
WithExec([]string{"apt-get", "install", "-y", "apt-utils", "build-essential", "curl", "git", "unzip", "bash", "gzip", "xz-utils", "pkg-config", "libssl-dev"}).
// curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s 0.35.3 --yes
WithExec([]string{"bash", "-l", "-c", "curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s 0.55.4 --yes"}).
WithEnvVariable("PROTO_HOME", "/root/.proto", dagger.ContainerWithEnvVariableOpts{Expand: true}).
WithEnvVariable("PATH", "$PATH:$PROTO_HOME/shims:$PROTO_HOME/bin:/root/.cargo/bin", dagger.ContainerWithEnvVariableOpts{Expand: true}).
WithExec([]string{"proto", "setup"}).
WithExec([]string{"bash", "-l", "-c", "proto setup"})
return m
}
func (m *WorkflowRuntime) BuildEnv(ctx context.Context) *WorkflowRuntime {
source := dag.Directory().WithDirectory("/", m.Dir, dagger.DirectoryWithDirectoryOpts{
Exclude: []string{"node_modules", ".cache", ".moon/cache"},
})
m.Con = m.BuildBaseEnv(ctx).
Con.
WithWorkdir("/workspace").
WithFile("/workspace/.prototools", m.Dir.File(".prototools")).
// proto use
WithExec([]string{"proto", "use"}).
// Install cargo-binstall (fast prebuilt installer for cargo bins)
WithExec([]string{"bash", "-l", "-c", "curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash"}).
// Install trunk and wasm-bindgen-cli via cargo-binstall (matches .moon/toolchains.yml)
WithExec([]string{"bash", "-l", "-c", "cargo binstall --no-confirm --locked trunk@0.21.14 wasm-bindgen-cli@0.2.118"}).
WithMountedDirectory("/workspace", source).
WithMountedDirectory("/workspace/.git", m.Dir.Directory(".git")).
// moon setup
WithExec([]string{"moon", "setup"}).
// yarn install --immutable
WithExec([]string{"yarn", "install", "--immutable"})
return m
}
func (m *WorkflowRuntime) WithMoonTask(ctx context.Context, task string) *WorkflowRuntime {
m.Con = m.Con.WithExec([]string{"moon", "exec", task, "--ignore-ci-checks"})
return m
}
func (m *WorkflowRuntime) WithMoonCommand(
ctx context.Context,
command string,
// +optional
args []string,
) *WorkflowRuntime {
m.Con = m.Con.WithExec(append([]string{"moon", command}, args...))
return m
}
func (m *WorkflowRuntime) Container(ctx context.Context) *dagger.Container {
return m.Con
}
func (m *WorkflowRuntime) Stdout(ctx context.Context) (string, error) {
stdout, err := m.Con.Stdout(ctx)
if err != nil {
return "", fmt.Errorf("failed to get stdout: %w", err)
}
return stdout, nil
}
func (m *WorkflowRuntime) WithEnvVariable(name, value string) *WorkflowRuntime {
m.Con = m.Con.WithEnvVariable(name, value)
return m
}
func (m *WorkflowRuntime) WithSecretVariable(name string, secret *dagger.Secret) *WorkflowRuntime {
m.Con = m.Con.WithSecretVariable(name, secret)
return m
}