Documentation ¶
Index ¶
- func Serve(server any)
- type CacheID
- type CacheVolume
- type Client
- type ClientOpt
- type Container
- func (r *Container) Build(context *Directory, opts ...ContainerBuildOpts) *Container
- func (r *Container) DefaultArgs(ctx context.Context) ([]string, error)
- func (r *Container) Directory(path string) *Directory
- func (r *Container) Entrypoint(ctx context.Context) ([]string, error)
- func (r *Container) EnvVariable(ctx context.Context, name string) (string, error)
- func (r *Container) EnvVariables(ctx context.Context) ([]EnvVariable, error)
- func (r *Container) Exec(opts ...ContainerExecOpts) *Containerdeprecated
- func (r *Container) ExitCode(ctx context.Context) (int, error)
- func (r *Container) Export(ctx context.Context, path string, opts ...ContainerExportOpts) (bool, error)
- func (r *Container) FS() *Directorydeprecated
- func (r *Container) File(path string) *File
- func (r *Container) From(address string) *Container
- func (r *Container) ID(ctx context.Context) (ContainerID, error)
- func (r *Container) Mounts(ctx context.Context) ([]string, error)
- func (r *Container) Platform(ctx context.Context) (Platform, error)
- func (r *Container) Publish(ctx context.Context, address string, opts ...ContainerPublishOpts) (string, error)
- func (r *Container) Rootfs() *Directory
- func (r *Container) Stderr(ctx context.Context) (string, error)
- func (r *Container) Stdout(ctx context.Context) (string, error)
- func (r *Container) User(ctx context.Context) (string, error)
- func (r *Container) WithDefaultArgs(opts ...ContainerWithDefaultArgsOpts) *Container
- func (r *Container) WithEntrypoint(args []string) *Container
- func (r *Container) WithEnvVariable(name string, value string) *Container
- func (r *Container) WithExec(args []string, opts ...ContainerWithExecOpts) *Container
- func (r *Container) WithFS(id *Directory) *Containerdeprecated
- func (r *Container) WithMountedCache(path string, cache *CacheVolume, opts ...ContainerWithMountedCacheOpts) *Container
- func (r *Container) WithMountedDirectory(path string, source *Directory) *Container
- func (r *Container) WithMountedFile(path string, source *File) *Container
- func (r *Container) WithMountedSecret(path string, source *Secret) *Container
- func (r *Container) WithMountedTemp(path string) *Container
- func (r *Container) WithRootfs(id *Directory) *Container
- func (r *Container) WithSecretVariable(name string, secret *Secret) *Container
- func (r *Container) WithUser(name string) *Container
- func (r *Container) WithWorkdir(path string) *Container
- func (r *Container) WithoutEnvVariable(name string) *Container
- func (r *Container) WithoutMount(path string) *Container
- func (r *Container) Workdir(ctx context.Context) (string, error)
- func (r *Container) XXX_GraphQLID(ctx context.Context) (string, error)
- func (r *Container) XXX_GraphQLType() string
- type ContainerBuildOpts
- type ContainerExecOpts
- type ContainerExportOpts
- type ContainerID
- type ContainerOpts
- type ContainerPublishOpts
- type ContainerWithDefaultArgsOpts
- type ContainerWithExecOpts
- type ContainerWithMountedCacheOpts
- type Directory
- func (r *Directory) Diff(other *Directory) *Directory
- func (r *Directory) Directory(path string) *Directory
- func (r *Directory) Entries(ctx context.Context, opts ...DirectoryEntriesOpts) ([]string, error)
- func (r *Directory) Export(ctx context.Context, path string) (bool, error)
- func (r *Directory) File(path string) *File
- func (r *Directory) ID(ctx context.Context) (DirectoryID, error)
- func (r *Directory) LoadProject(configPath string) *Project
- func (r *Directory) WithDirectory(path string, directory *Directory, opts ...DirectoryWithDirectoryOpts) *Directory
- func (r *Directory) WithFile(path string, source *File) *Directory
- func (r *Directory) WithNewDirectory(path string) *Directory
- func (r *Directory) WithNewFile(path string, contents string) *Directory
- func (r *Directory) WithoutDirectory(path string) *Directory
- func (r *Directory) WithoutFile(path string) *Directory
- func (r *Directory) XXX_GraphQLID(ctx context.Context) (string, error)
- func (r *Directory) XXX_GraphQLType() string
- type DirectoryEntriesOpts
- type DirectoryID
- type DirectoryOpts
- type DirectoryWithDirectoryOpts
- type EnvVariable
- type File
- func (r *File) Contents(ctx context.Context) (string, error)
- func (r *File) Export(ctx context.Context, path string) (bool, error)
- func (r *File) ID(ctx context.Context) (FileID, error)
- func (r *File) Secret() *Secret
- func (r *File) Size(ctx context.Context) (int, error)
- func (r *File) XXX_GraphQLID(ctx context.Context) (string, error)
- func (r *File) XXX_GraphQLType() string
- type FileID
- type GitOpts
- type GitRef
- type GitRepository
- type Host
- type HostDirectoryOpts
- type HostVariable
- type HostWorkdirOpts
- type Platform
- type Project
- func (r *Project) Extensions(ctx context.Context) ([]Project, error)
- func (r *Project) GeneratedCode() *Directory
- func (r *Project) Install(ctx context.Context) (bool, error)
- func (r *Project) Name(ctx context.Context) (string, error)
- func (r *Project) SDK(ctx context.Context) (string, error)
- func (r *Project) Schema(ctx context.Context) (string, error)
- type Query
- func (r *Query) CacheVolume(key string) *CacheVolume
- func (r *Query) Container(opts ...ContainerOpts) *Container
- func (r *Query) DefaultPlatform(ctx context.Context) (Platform, error)
- func (r *Query) Directory(opts ...DirectoryOpts) *Directory
- func (r *Query) File(id FileID) *File
- func (r *Query) Git(url string, opts ...GitOpts) *GitRepository
- func (r *Query) HTTP(url string) *File
- func (r *Query) Host() *Host
- func (r *Query) Project(name string) *Project
- func (r *Query) Secret(id SecretID) *Secret
- type Request
- type Response
- type Secret
- type SecretID
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CacheVolume ¶
type CacheVolume struct {
// contains filtered or unexported fields
}
A directory whose contents persist across runs
func (*CacheVolume) XXX_GraphQLID ¶ added in v0.4.0
func (r *CacheVolume) XXX_GraphQLID(ctx context.Context) (string, error)
XXX_GraphQLID is an internal function. It returns the underlying type ID
func (*CacheVolume) XXX_GraphQLType ¶ added in v0.4.0
func (r *CacheVolume) XXX_GraphQLType() string
XXX_GraphQLType is an internal function. It returns the native GraphQL type name
type Client ¶
type Client struct { Query // contains filtered or unexported fields }
Client is the Dagger Engine Client
type ClientOpt ¶
type ClientOpt interface {
// contains filtered or unexported methods
}
ClientOpt holds a client option
func WithConfigPath ¶
WithConfigPath sets the engine config path
func WithLogOutput ¶
WithLogOutput sets the progress writer
func WithNoExtensions ¶
func WithNoExtensions() ClientOpt
WithNoExtensions disables installing extensions
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
An OCI-compatible container, also known as a docker container
Example ¶
package main import ( "context" "fmt" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() alpine := client.Container().From("alpine:3.16.2") out, err := alpine.Exec(dagger.ContainerExecOpts{ Args: []string{"cat", "/etc/alpine-release"}, }).Stdout(ctx) if err != nil { panic(err) } fmt.Println(out) }
Output: 3.16.2
func (*Container) Build ¶
func (r *Container) Build(context *Directory, opts ...ContainerBuildOpts) *Container
Initialize this container from a Dockerfile build
Example ¶
package main import ( "context" "fmt" "strings" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() repo := client.Git("https://github.com/dagger/dagger"). Tag("v0.3.0"). Tree() daggerImg := client.Container().Build(repo) out, err := daggerImg.Exec(dagger.ContainerExecOpts{ Args: []string{"version"}, }).Stdout(ctx) if err != nil { panic(err) } words := strings.Split(strings.TrimSpace(out), " ") fmt.Println(words[0]) }
Output: dagger
func (*Container) DefaultArgs ¶
Default arguments for future commands
func (*Container) Entrypoint ¶
Entrypoint to be prepended to the arguments of all commands
func (*Container) EnvVariable ¶
The value of the specified environment variable
func (*Container) EnvVariables ¶
func (r *Container) EnvVariables(ctx context.Context) ([]EnvVariable, error)
A list of environment variables passed to commands
func (*Container) Exec
deprecated
func (r *Container) Exec(opts ...ContainerExecOpts) *Container
This container after executing the specified command inside it
Deprecated: Replaced by WithExec.
func (*Container) ExitCode ¶
Exit code of the last executed command. Zero means success. Null if no command has been executed.
func (*Container) Export ¶ added in v0.4.0
func (r *Container) Export(ctx context.Context, path string, opts ...ContainerExportOpts) (bool, error)
Write the container as an OCI tarball to the destination file path on the host
func (*Container) From ¶
Initialize this container from the base image published at the given address
func (*Container) ID ¶
func (r *Container) ID(ctx context.Context) (ContainerID, error)
A unique identifier for this container
func (*Container) Publish ¶
func (r *Container) Publish(ctx context.Context, address string, opts ...ContainerPublishOpts) (string, error)
Publish this container as a new image, returning a fully qualified ref
func (*Container) Rootfs ¶ added in v0.4.1
This container's root filesystem. Mounts are not included.
func (*Container) Stderr ¶
The error stream of the last executed command. Null if no command has been executed.
func (*Container) Stdout ¶
The output stream of the last executed command. Null if no command has been executed.
func (*Container) WithDefaultArgs ¶
func (r *Container) WithDefaultArgs(opts ...ContainerWithDefaultArgsOpts) *Container
Configures default arguments for future commands
func (*Container) WithEntrypoint ¶
This container but with a different command entrypoint
func (*Container) WithEnvVariable ¶
This container plus the given environment variable
Example ¶
package main import ( "context" "fmt" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() container := client.Container().From("alpine:3.16.2") container = container.WithEnvVariable("FOO", "bar") out, err := container.Exec(dagger.ContainerExecOpts{ Args: []string{"sh", "-c", "echo $FOO"}, }).Stdout(ctx) if err != nil { panic(err) } fmt.Println(out) }
Output: bar
func (*Container) WithExec ¶ added in v0.4.1
func (r *Container) WithExec(args []string, opts ...ContainerWithExecOpts) *Container
This container after executing the specified command inside it
func (*Container) WithMountedCache ¶
func (r *Container) WithMountedCache(path string, cache *CacheVolume, opts ...ContainerWithMountedCacheOpts) *Container
This container plus a cache volume mounted at the given path
Example ¶
package main import ( "context" "fmt" "strconv" "time" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() cacheKey := "example-" + time.Now().Format(time.RFC3339) cache := client.CacheVolume(cacheKey) container := client.Container().From("alpine:3.16.2") container = container.WithMountedCache("/cache", cache) var out string for i := 0; i < 5; i++ { out, err = container.Exec(dagger.ContainerExecOpts{ Args: []string{ "sh", "-c", "echo $0 >> /cache/x.txt; cat /cache/x.txt", strconv.Itoa(i), }, }).Stdout(ctx) if err != nil { panic(err) } } fmt.Printf("%q", out) }
Output: "0\n1\n2\n3\n4\n"
func (*Container) WithMountedDirectory ¶
This container plus a directory mounted at the given path
Example ¶
package main import ( "context" "fmt" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() dir := client.Directory(). WithNewFile("hello.txt", "Hello, world!"). WithNewFile("goodbye.txt", "Goodbye, world!") container := client.Container().From("alpine:3.16.2") container = container.WithMountedDirectory("/mnt", dir) out, err := container.Exec(dagger.ContainerExecOpts{ Args: []string{"ls", "/mnt"}, }).Stdout(ctx) if err != nil { panic(err) } fmt.Printf("%q", out) }
Output: "goodbye.txt\nhello.txt\n"
func (*Container) WithMountedFile ¶
This container plus a file mounted at the given path
func (*Container) WithMountedSecret ¶
This container plus a secret mounted into a file at the given path
func (*Container) WithMountedTemp ¶
This container plus a temporary directory mounted at the given path
func (*Container) WithRootfs ¶ added in v0.4.1
Initialize this container from this DirectoryID
func (*Container) WithSecretVariable ¶
This container plus an env variable containing the given secret
func (*Container) WithWorkdir ¶
This container but with a different working directory
func (*Container) WithoutEnvVariable ¶
This container minus the given environment variable
func (*Container) WithoutMount ¶
This container after unmounting everything at the given path.
func (*Container) XXX_GraphQLID ¶ added in v0.4.0
XXX_GraphQLID is an internal function. It returns the underlying type ID
func (*Container) XXX_GraphQLType ¶ added in v0.4.0
XXX_GraphQLType is an internal function. It returns the native GraphQL type name
type ContainerBuildOpts ¶
type ContainerBuildOpts struct {
Dockerfile string
}
ContainerBuildOpts contains options for Container.Build
type ContainerExecOpts ¶
type ContainerExecOpts struct { // Command to run instead of the container's default command Args []string // Content to write to the command's standard input before closing Stdin string // Redirect the command's standard output to a file in the container RedirectStdout string // Redirect the command's standard error to a file in the container RedirectStderr string // Provide dagger access to the executed command // Do not use this option unless you trust the command being executed // The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM ExperimentalPrivilegedNesting bool }
ContainerExecOpts contains options for Container.Exec
type ContainerExportOpts ¶ added in v0.4.0
type ContainerExportOpts struct {
PlatformVariants []*Container
}
ContainerExportOpts contains options for Container.Export
type ContainerID ¶
type ContainerID string
A unique container identifier. Null designates an empty container (scratch).
type ContainerOpts ¶
type ContainerOpts struct { ID ContainerID Platform Platform }
ContainerOpts contains options for Query.Container
type ContainerPublishOpts ¶ added in v0.4.0
type ContainerPublishOpts struct {
PlatformVariants []*Container
}
ContainerPublishOpts contains options for Container.Publish
type ContainerWithDefaultArgsOpts ¶
type ContainerWithDefaultArgsOpts struct {
Args []string
}
ContainerWithDefaultArgsOpts contains options for Container.WithDefaultArgs
type ContainerWithExecOpts ¶ added in v0.4.1
type ContainerWithExecOpts struct { // Content to write to the command's standard input before closing Stdin string // Redirect the command's standard output to a file in the container RedirectStdout string // Redirect the command's standard error to a file in the container RedirectStderr string // Provide dagger access to the executed command // Do not use this option unless you trust the command being executed // The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM ExperimentalPrivilegedNesting bool }
ContainerWithExecOpts contains options for Container.WithExec
type ContainerWithMountedCacheOpts ¶
type ContainerWithMountedCacheOpts struct {
Source *Directory
}
ContainerWithMountedCacheOpts contains options for Container.WithMountedCache
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
A directory
Example ¶
package main import ( "context" "fmt" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() dir := client.Directory(). WithNewFile("hello.txt", "Hello, world!"). WithNewFile("goodbye.txt", "Goodbye, world!") entries, err := dir.Entries(ctx) if err != nil { panic(err) } fmt.Println(entries) }
Output: [goodbye.txt hello.txt]
func (*Directory) Export ¶ added in v0.4.0
Write the contents of the directory to a path on the host
func (*Directory) ID ¶
func (r *Directory) ID(ctx context.Context) (DirectoryID, error)
The content-addressed identifier of the directory
func (*Directory) LoadProject ¶
load a project's metadata
func (*Directory) WithDirectory ¶
func (r *Directory) WithDirectory(path string, directory *Directory, opts ...DirectoryWithDirectoryOpts) *Directory
This directory plus a directory written at the given path
func (*Directory) WithFile ¶ added in v0.4.0
This directory plus the contents of the given file copied to the given path
func (*Directory) WithNewDirectory ¶ added in v0.4.0
This directory plus a new directory created at the given path
func (*Directory) WithNewFile ¶
This directory plus a new file written at the given path
func (*Directory) WithoutDirectory ¶
This directory with the directory at the given path removed
func (*Directory) WithoutFile ¶
This directory with the file at the given path removed
func (*Directory) XXX_GraphQLID ¶ added in v0.4.0
XXX_GraphQLID is an internal function. It returns the underlying type ID
func (*Directory) XXX_GraphQLType ¶ added in v0.4.0
XXX_GraphQLType is an internal function. It returns the native GraphQL type name
type DirectoryEntriesOpts ¶
type DirectoryEntriesOpts struct {
Path string
}
DirectoryEntriesOpts contains options for Directory.Entries
type DirectoryOpts ¶
type DirectoryOpts struct {
ID DirectoryID
}
DirectoryOpts contains options for Query.Directory
type DirectoryWithDirectoryOpts ¶ added in v0.4.0
DirectoryWithDirectoryOpts contains options for Directory.WithDirectory
type EnvVariable ¶
type EnvVariable struct {
// contains filtered or unexported fields
}
EnvVariable is a simple key value object that represents an environment variable.
type File ¶
type File struct {
// contains filtered or unexported fields
}
A file
func (*File) XXX_GraphQLID ¶ added in v0.4.0
XXX_GraphQLID is an internal function. It returns the underlying type ID
func (*File) XXX_GraphQLType ¶ added in v0.4.0
XXX_GraphQLType is an internal function. It returns the native GraphQL type name
type GitOpts ¶ added in v0.4.1
type GitOpts struct {
KeepGitDir bool
}
GitOpts contains options for Query.Git
type GitRef ¶
type GitRef struct {
// contains filtered or unexported fields
}
A git ref (tag or branch)
type GitRepository ¶
type GitRepository struct {
// contains filtered or unexported fields
}
A git repository
Example ¶
package main import ( "context" "fmt" "strings" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx) if err != nil { panic(err) } defer client.Close() readme, err := client.Git("https://github.com/dagger/dagger"). Tag("v0.3.0"). Tree().File("README.md").Contents(ctx) if err != nil { panic(err) } lines := strings.Split(strings.TrimSpace(readme), "\n") fmt.Println(lines[0]) }
Output: ## What is Dagger?
func (*GitRepository) Branch ¶
func (r *GitRepository) Branch(name string) *GitRef
Details on one branch
func (*GitRepository) Branches ¶
func (r *GitRepository) Branches(ctx context.Context) ([]string, error)
List of branches on the repository
func (*GitRepository) Commit ¶ added in v0.4.1
func (r *GitRepository) Commit(id string) *GitRef
Details on one commit
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Information about the host execution environment
func (*Host) Directory ¶
func (r *Host) Directory(path string, opts ...HostDirectoryOpts) *Directory
Access a directory on the host
Example ¶
package main import ( "context" "fmt" "strings" "dagger.io/dagger" ) func main() { ctx := context.Background() client, err := dagger.Connect(ctx, dagger.WithWorkdir(".")) if err != nil { panic(err) } defer client.Close() readme, err := client.Host().Directory(".").File("README.md").Contents(ctx) if err != nil { panic(err) } fmt.Printf("%v\n", strings.Contains(readme, "Dagger")) }
Output: true
func (*Host) EnvVariable ¶
func (r *Host) EnvVariable(name string) *HostVariable
Lookup the value of an environment variable. Null if the variable is not available.
func (*Host) Workdir
deprecated
func (r *Host) Workdir(opts ...HostWorkdirOpts) *Directory
The current working directory on the host
Deprecated: Use Directory with path set to '.' instead.
type HostDirectoryOpts ¶ added in v0.4.0
HostDirectoryOpts contains options for Host.Directory
type HostVariable ¶
type HostVariable struct {
// contains filtered or unexported fields
}
An environment variable on the host environment
func (*HostVariable) Secret ¶
func (r *HostVariable) Secret() *Secret
A secret referencing the value of this variable
type HostWorkdirOpts ¶ added in v0.4.0
HostWorkdirOpts contains options for Host.Workdir
type Project ¶
type Project struct {
// contains filtered or unexported fields
}
A set of scripts and/or extensions
func (*Project) Extensions ¶
extensions in this project
func (*Project) GeneratedCode ¶
Code files generated by the SDKs in the project
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) CacheVolume ¶
func (r *Query) CacheVolume(key string) *CacheVolume
Construct a cache volume for a given cache key
func (*Query) Container ¶
func (r *Query) Container(opts ...ContainerOpts) *Container
Load a container from ID. Null ID returns an empty container (scratch). Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.
func (*Query) DefaultPlatform ¶ added in v0.4.0
The default platform of the builder.
func (*Query) Directory ¶
func (r *Query) Directory(opts ...DirectoryOpts) *Directory
Load a directory by ID. No argument produces an empty directory.
type Request ¶
type Request struct { // The literal string representing the GraphQL query, e.g. // `query myQuery { myField }`. Query string `json:"query"` // A JSON-marshalable value containing the variables to be sent // along with the query, or nil if there are none. Variables interface{} `json:"variables,omitempty"` // The GraphQL operation name. The server typically doesn't // require this unless there are multiple queries in the // document, but genqlient sets it unconditionally anyway. OpName string `json:"operationName"` }
Request contains all the values required to build queries executed by the graphql.Client.
Typically, GraphQL APIs will accept a JSON payload of the form
{"query": "query myQuery { ... }", "variables": {...}}`
and Request marshals to this format. However, MakeRequest may marshal the data in some other way desired by the backend.
type Response ¶
type Response struct { Data interface{} `json:"data"` Extensions map[string]interface{} `json:"extensions,omitempty"` Errors gqlerror.List `json:"errors,omitempty"` }
Response that contains data returned by the GraphQL API.
Typically, GraphQL APIs will return a JSON payload of the form
{"data": {...}, "errors": {...}}
It may additionally contain a key named "extensions", that might hold GraphQL protocol extensions. Extensions and Errors are optional, depending on the values returned by the server.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
A reference to a secret value, which can be handled more safely than the value itself
func (*Secret) XXX_GraphQLID ¶ added in v0.4.0
XXX_GraphQLID is an internal function. It returns the underlying type ID
func (*Secret) XXX_GraphQLType ¶ added in v0.4.0
XXX_GraphQLType is an internal function. It returns the native GraphQL type name