|
15 | 15 | package main |
16 | 16 |
|
17 | 17 | import ( |
18 | | - "context" |
19 | 18 | "dagger/workflow_runtime/internal/dagger" |
20 | | - "fmt" |
21 | 19 | ) |
22 | 20 |
|
23 | 21 | func New( |
24 | 22 | // +required |
25 | 23 | // +ignore=["node_modules/", ".moon/cache/", ".cache/"] |
26 | 24 | dir *dagger.Directory, |
27 | | - // +optional |
28 | | - // +default="dev" |
29 | | - mode string, |
30 | | - // +optional |
31 | | - ghToken *dagger.Secret, |
32 | 25 | ) *WorkflowRuntime { |
33 | 26 | return &WorkflowRuntime{ |
34 | | - Dir: dir, |
35 | | - Mode: mode, |
36 | | - GhToken: ghToken, |
| 27 | + Dir: dir, |
37 | 28 | } |
38 | 29 | } |
39 | | - |
40 | | -// Setup Proto |
41 | | -func (m *WorkflowRuntime) BuildBaseEnv(ctx context.Context) *WorkflowRuntime { |
42 | | - m.Con = dag. |
43 | | - Container(). |
44 | | - From("ubuntu:plucky"). |
45 | | - // apt-get update && apt-get install -y curl git unzip gzip xz-utils |
46 | | - WithExec([]string{"apt-get", "update"}). |
47 | | - WithExec([]string{"apt-get", "install", "-y", "build-essential", "curl", "git", "unzip", "bash", "gzip", "xz-utils"}). |
48 | | - // curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s 0.35.3 --yes |
49 | | - WithExec([]string{"bash", "-l", "-c", "curl -fsSL https://moonrepo.dev/install/proto.sh | bash -s 0.44.1 --yes"}). |
50 | | - WithEnvVariable("PROTO_HOME", "/root/.proto", dagger.ContainerWithEnvVariableOpts{Expand: true}). |
51 | | - WithEnvVariable("PATH", "$PATH:$PROTO_HOME/shims:$PROTO_HOME/bin", dagger.ContainerWithEnvVariableOpts{Expand: true}) |
52 | | - |
53 | | - return m |
54 | | -} |
55 | | - |
56 | | -func (m *WorkflowRuntime) BuildEnv(ctx context.Context) *WorkflowRuntime { |
57 | | - source := dag.Directory().WithDirectory("/", m.Dir, dagger.DirectoryWithDirectoryOpts{ |
58 | | - Exclude: []string{"node_modules", ".cache", ".moon/cache"}, |
59 | | - }) |
60 | | - |
61 | | - m.Con = m.BuildBaseEnv(ctx). |
62 | | - Con. |
63 | | - WithWorkdir("/workspace"). |
64 | | - WithFile("/workspace/.prototools", m.Dir.File(".prototools")). |
65 | | - // proto use |
66 | | - WithExec([]string{"proto", "use"}). |
67 | | - // rm .prototools |
68 | | - WithoutFile("/workspace/.prototools"). |
69 | | - WithMountedDirectory("/workspace", source). |
70 | | - // moon setup |
71 | | - WithExec([]string{"moon", "setup"}). |
72 | | - // yarn install --immutable |
73 | | - WithExec([]string{"yarn", "install", "--immutable"}) |
74 | | - |
75 | | - m = m.setEnvs(ctx) |
76 | | - |
77 | | - return m |
78 | | -} |
79 | | - |
80 | | -func (m *WorkflowRuntime) WithAction(ctx context.Context, action string) *WorkflowRuntime { |
81 | | - m.Con = m.Con.WithExec([]string{"bash", "-l", "-c", fmt.Sprintf("./etc/scripts/actions/%s.ts", action)}) |
82 | | - |
83 | | - return m |
84 | | -} |
85 | | - |
86 | | -func (m *WorkflowRuntime) Container(ctx context.Context) *dagger.Container { |
87 | | - return m.Con |
88 | | -} |
89 | | - |
90 | | -func (m *WorkflowRuntime) Stdout(ctx context.Context) (string, error) { |
91 | | - stdout, err := m.Con.Stdout(ctx) |
92 | | - if err != nil { |
93 | | - return "", fmt.Errorf("failed to get stdout: %w", err) |
94 | | - } |
95 | | - return stdout, nil |
96 | | -} |
97 | | - |
98 | | -func (m *WorkflowRuntime) setEnvs(ctx context.Context) *WorkflowRuntime { |
99 | | - m.Con = m.Con. |
100 | | - WithEnvVariable("MODE", m.Mode) |
101 | | - |
102 | | - if m.GhToken != nil { |
103 | | - tokenString, _ := m.GhToken.Plaintext(ctx) |
104 | | - |
105 | | - m.Con = m.Con. |
106 | | - WithEnvVariable("GH_TOKEN", tokenString) |
107 | | - } |
108 | | - |
109 | | - return m |
110 | | -} |
0 commit comments