Documentation
¶
Index ¶
- Constants
- func GetImageURL(opts *NewBaseContainerOpts) (string, error)
- func WithEnvVariable(ctr *dagger.Container, name string, value string, expand bool) *dagger.Container
- func WithGoBuildCache(ctr *dagger.Container) *dagger.Container
- func WithGoCgoDisabled(ctr *dagger.Container) *dagger.Container
- func WithGoCgoEnabled(ctr *dagger.Container) *dagger.Container
- func WithGoModCache(ctr *dagger.Container) *dagger.Container
- func WithGoPlatform(ctr *dagger.Container, platform dagger.Platform) interface{}
- func WithSource(ctr *dagger.Container, src *dagger.Directory, workdir string) (*dagger.Container, error)
- func WithTerraformCache(ctr *dagger.Container) *dagger.Container
- func WithTerragruntCache(ctr *dagger.Container) *dagger.Container
- type Client
- type DaggerFnContainer
- type DaggerFnContainerClient
- type NewBaseContainerOpts
Constants ¶
const (
GolangAlpineImage = "golang"
)
Variables ¶
This section is empty.
Functions ¶
func GetImageURL ¶
func GetImageURL(opts *NewBaseContainerOpts) (string, error)
GetImageURL constructs the full image URL from the provided options. It returns an error if the options are nil or the image name is empty.
Parameters:
- opts: A pointer to NewBaseContainerOpts containing the image name and version.
Returns:
- A string containing the full image URL in the format "image:version".
- An error if the options are nil or the image name is empty.
Example:
opts := &NewBaseContainerOpts{
Image: "golang",
Version: "1.16",
}
imageURL, err := GetImageURL(opts)
if err != nil {
// handle error
}
fmt.Println(imageURL) // Output: "golang:1.16"
func WithEnvVariable ¶
func WithEnvVariable( ctr *dagger.Container, name string, value string, expand bool, ) *dagger.Container
WithEnvVariable sets an environment variable in the provided container.
Parameters:
- ctr: The base container to which the environment variable will be added.
- name: The name of the environment variable (e.g., "HOST").
- value: The value of the environment variable (e.g., "localhost").
- expand: If true, replaces `${VAR}` or `$VAR` in the value according to the current environment variables defined in the container.
Returns:
- A pointer to the Dagger container with the environment variable set.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Set an environment variable updatedCtr := WithEnvVariable(ctr, "HOST", "localhost", false) // The container now has the environment variable "HOST" set to "localhost" // Set an environment variable with expansion updatedCtr = WithEnvVariable(ctr, "PATH", "/usr/local/bin:$PATH", true) // The container now has the environment variable "PATH" with expansion
func WithGoBuildCache ¶
WithGoBuildCache sets the build cache for the Go module. This function mounts a cache volume at the default path "/go/build-cache" and sets the environment variable "GOCACHE" to this path.
Parameters:
- ctr: A pointer to the Dagger container to which the build cache will be added.
Returns:
- A pointer to the Dagger container with the build cache set.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Set the Go build cache updatedCtr := WithGoBuildCache(ctr) // The container now has the build cache set at "/go/build-cache" // with the environment variable "GOCACHE" pointing to it.
func WithGoCgoDisabled ¶
WithGoCgoDisabled disables CGO in the provided container by setting the "CGO_ENABLED" environment variable to "0".
Parameters:
- ctr: A pointer to the Dagger container in which CGO will be disabled.
Returns:
- A pointer to the Dagger container with CGO disabled.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Disable CGO in the container updatedCtr := WithGoCgoDisabled(ctr) // The container now has the environment variable "CGO_ENABLED" set to "0"
func WithGoCgoEnabled ¶
WithGoCgoEnabled enables CGO in the provided container by setting the "CGO_ENABLED" environment variable to "1".
Parameters:
- ctr: A pointer to the Dagger container in which CGO will be enabled.
Returns:
- A pointer to the Dagger container with CGO enabled.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Enable CGO in the container updatedCtr := WithGoCgoEnabled(ctr) // The container now has the environment variable "CGO_ENABLED" set to "1"
func WithGoModCache ¶
WithGoModCache sets the module cache for the Go module. This function mounts a cache volume at the default path "/go/pkg/mod" and sets the environment variable "GOMODCACHE" to this path.
Parameters:
- ctr: A pointer to the Dagger container to which the module cache will be added.
Returns:
- A pointer to the Dagger container with the module cache set.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Set the Go module cache updatedCtr := WithGoModCache(ctr) // The container now has the module cache set at "/go/pkg/mod" // with the environment variable "GOMODCACHE" pointing to it.
func WithGoPlatform ¶
WithGoPlatform sets the GOOS, GOARCH, and GOARM environment variables based on the target platform.
Parameters:
- platform: The target platform in "os/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
- ctr: The base container to which the environment variables will be added.
Returns:
- A pointer to the Dagger container with the platform environment variables set.
Example:
// Create a new Dagger container
ctr := dagger.NewContainer()
// Set the platform environment variables
updatedCtr := WithPlatform("linux/amd64", ctr)
// The container now has the environment variables "GOOS", "GOARCH", and "GOARM" set accordingly
func WithSource ¶
func WithSource( ctr *dagger.Container, src *dagger.Directory, workdir string, ) (*dagger.Container, error)
WithSource sets the source directory and mounts it to the container. If the source directory is not provided (nil), it returns an error. The workdir is set to the provided workdir path or defaults to a pre-defined mount prefix.
Parameters:
- ctr: A pointer to the Dagger container to which the source directory will be mounted.
- src: A pointer to the Dagger directory representing the source directory to be mounted.
- workdir: An optional string representing the working directory inside the container.
Returns:
- A pointer to the Dagger container with the source directory mounted and workdir set.
- An error if the source directory is not provided.
Example:
// Create a new Dagger container
ctr := dagger.NewContainer()
// Create a new Dagger directory representing the source directory
src := dagger.NewDirectory()
// Set the source directory and workdir
updatedCtr, err := WithSource(ctr, src, "app")
if err != nil {
// handle error
}
// The container now has the source directory mounted at the mount prefix
// and the workdir set to the combined mount prefix and "app".
func WithTerraformCache ¶
WithTerraformCache sets the Terraform cache. This function mounts two cache volumes: one at the default path "/root/.terraform.d" and another at the default path "/.terraform".
Parameters:
- ctr: A pointer to the Dagger container to which the Terraform cache will be added.
Returns:
- A pointer to the Dagger container with the Terraform cache set.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Set the Terraform cache updatedCtr := WithTerraformCache(ctr) // The container now has the Terraform cache set at "/root/.terraform.d" // and another at "/.terraform".
func WithTerragruntCache ¶
WithTerragruntCache sets the Terragrunt cache. This function mounts a cache volume at the default path "/.terragrunt-cache".
Parameters:
- ctr: A pointer to the Dagger container to which the Terragrunt cache will be added.
Returns:
- A pointer to the Dagger container with the Terragrunt cache set.
Example:
// Create a new Dagger container ctr := dagger.NewContainer() // Set the Terragrunt cache updatedCtr := WithTerragruntCache(ctr) // The container now has the Terragrunt cache set at "/.terragrunt-cache".
Types ¶
type DaggerFnContainer ¶
type DaggerFnContainer interface {
NewBaseContainer(opts *NewBaseContainerOpts) (any, error)
NewGolangAlpineContainer(version string) (interface{}, error)
}
type DaggerFnContainerClient ¶
type DaggerFnContainerClient struct{}
func (*DaggerFnContainerClient) NewBaseContainer ¶
func (c *DaggerFnContainerClient) NewBaseContainer(opts *NewBaseContainerOpts) (any, error)
NewBaseContainer NewBase creates a new base container from the specified image and version. It returns an error if the options are nil or the image name is empty.
Parameters:
- opts: A pointer to NewBaseContainerOpts containing the image name and version.
Returns:
- A pointer to the Dagger container created from the specified image and version.
- An error if the options are nil or the image name is empty.
Example:
opts := &NewBaseContainerOpts{
Image: "golang",
Version: "1.16",
}
container, err := NewBase(opts)
if err != nil {
// handle error
}
// Use the container, e.g., fmt.Println(container)
func (*DaggerFnContainerClient) NewGolangAlpineContainer ¶
func (c *DaggerFnContainerClient) NewGolangAlpineContainer(version string) (any, error)
type NewBaseContainerOpts ¶
type NewBaseContainerOpts struct {
Image string // The name of the base image.
Version string // The version of the base image. If empty, a default version is used.
}
NewBaseContainerOpts contains options for creating a new base container.