#Andrea strikes again
1 messages · Page 1 of 1 (latest)
so far, it feels great to use
From our own magefile. Before:
modules := c.Directory()
for _, f := range []string{"go.mod", "go.sum", "sdk/go/go.mod", "sdk/go/go.sum"} {
fileID, err := workdir.Read().File(f).ID(ctx)
if err != nil {
return err
}
modules = modules.WithCopiedFile(f, fileID)
}
modID, err := modules.ID(ctx)
if err != nil {
return err
}
builder = builder.
WithMountedDirectory("/app", modID).
Exec(dagger.ContainerExecOpts{
Args: []string{"go", "mod", "download"},
})
After:
// install dependencies
modules := c.Directory()
for _, f := range []string{"go.mod", "go.sum", "sdk/go/go.mod", "sdk/go/go.sum"} {
modules = modules.WithCopiedFile(f, workdir.Read().File(f))
}
builder = builder.
WithMountedDirectory("/app", modules).
Exec(dagger.ContainerExecOpts{
Args: []string{"go", "mod", "download"},
})
omg
you guys are machines
the velocity gain from not having to deal with cueflow bugs is insane
i'm rewriting our magefile -- it feels great
Before:
workdir := c.Host().Workdir().Read()
src, err := workdir.ID(ctx)
if err != nil {
return err
}
cfg, err := workdir.File(".markdownlint.yaml").ID(ctx)
if err != nil {
return err
}
_, err = c.Container().
From("tmknom/markdownlint:0.31.1").
WithMountedDirectory("/src", src).
WithMountedFile("/src/.markdownlint.yaml", cfg).
WithWorkdir("/src").
Exec(dagger.ContainerExecOpts{
Args: []string{
"-c",
".markdownlint.yaml",
"--",
"./docs",
"README.md",
},
}).ExitCode(ctx)
After:
workdir := c.Host().Workdir().Read()
_, err = c.Container().
From("tmknom/markdownlint:0.31.1").
WithMountedDirectory("/src", workdir).
WithMountedFile("/src/.markdownlint.yaml", workdir.File(".markdownlint.yaml")).
WithWorkdir("/src").
Exec(dagger.ContainerExecOpts{
Args: []string{
"-c",
".markdownlint.yaml",
"--",
"./docs",
"README.md",
},
}).ExitCode(ctx)
So not only we don't have to deal with intermediate ID steps -- but the neat thing is stuff can be INLINED
Like this: WithMountedFile("/src/.markdownlint.yaml", workdir.File(".markdownlint.yaml"))
Also removes the confusion about ID(ctx) being lazy (as compared to all other functions that take a ctx and return an error that are NOT lazy)
Now it's pretty obvious and consistent
Things that are weird:
-
Some arguments are named in the API as
id, but now they're not -
It currently doesn't work on optional fields, because they're in a structure. I don't know yet how to get around that without recursive reflection (blargh)
-
Top-level selectors (e.g.
file(id: FileID)) become weird (File(id *File)) -- if you already have the file, what's the point of having a function to look it up?
Summary of weirdness in a snippet:
// Load a file by ID
func (r *Query) File(id *File) *File {
...
type DirectoryOpts struct {
ID DirectoryID
}
// Load a directory by ID. No argument produces an empty directory.
func (r *Query) Directory(opts ...DirectoryOpts) *Directory {
...
/cc @left aurora @radiant otter @hidden kraken
whooooooa
Andrea strikes again