Documentation ¶
Overview ¶
Package containers provides a set of utilities to create and run containers.
Index ¶
- Variables
- func ApplyCustomizations(runtime *daggers.Runtime, container *dagger.Container, ...) (*dagger.Container, error)
- func ContainerFromImage(runtime *daggers.Runtime, address string) *dagger.Container
- func CustomizedContainerFromImage(ctx context.Context, runtime *daggers.Runtime, address string, ...) (*dagger.Container, error)
- func MountRuntimeWorkdir(runtime *daggers.Runtime, container *dagger.Container) *dagger.Container
- func NewCacheVolumeWithFileHashKeys(ctx context.Context, client *dagger.Client, cacheKeyPrefix string, ...) (*dagger.CacheVolume, error)
- type ContainerCustomizerFn
- func AppendToPATH(ctx context.Context, path string) ContainerCustomizerFn
- func DownloadExecutableFile(url, destFile string) ContainerCustomizerFn
- func DownloadFile(url, destFile string) ContainerCustomizerFn
- func InstallGithubCli(version string, extensions ...string) ContainerCustomizerFn
- func InstallGo(ctx context.Context, version string) ContainerCustomizerFn
- func WithDockerSocket() ContainerCustomizerFn
- func WithEnvVariables(env map[string]string) ContainerCustomizerFn
- func WithGitHubEnvs(ctx context.Context) ContainerCustomizerFn
- func WithGithubAuth(ctx context.Context) ContainerCustomizerFn
- func WithHostEnvSecret(name string) ContainerCustomizerFn
- func WithHostEnvSecrets(include ...string) ContainerCustomizerFn
- func WithHostEnvVariable(ctx context.Context, name string) ContainerCustomizerFn
- func WithHostEnvVariables(ctx context.Context, include ...string) ContainerCustomizerFn
- func WithHostEnvVariablesWithPrefix(ctx context.Context, prefix string, ignore ...string) ContainerCustomizerFn
- func WithMountedCache(cacheVol *dagger.CacheVolume, path, envVarName string) ContainerCustomizerFn
- func WithMountedGoCache(ctx context.Context, path string) ContainerCustomizerFn
- func WithSSHSocket(ctx context.Context) ContainerCustomizerFn
Constants ¶
This section is empty.
Variables ¶
var ErrMissingRequiredArgument = errors.New("missing required argument")
ErrMissingRequiredArgument is returned when a required argument is missing.
Functions ¶
func ApplyCustomizations ¶
func ApplyCustomizations( runtime *daggers.Runtime, container *dagger.Container, customizers ...ContainerCustomizerFn, ) (*dagger.Container, error)
ApplyCustomizations applies customizations to the given container.
func ContainerFromImage ¶
ContainerFromImage creates a container from the given image.
func CustomizedContainerFromImage ¶
func CustomizedContainerFromImage( ctx context.Context, runtime *daggers.Runtime, address string, mountWorkdir bool, customizers ...ContainerCustomizerFn, ) (*dagger.Container, error)
CustomizedContainerFromImage creates a container from the given image, applies customizations to it and mounts the runtime workdir to it if mountWorkdir is true.
func MountRuntimeWorkdir ¶
MountRuntimeWorkdir mounts the runtime workdir to the given container and configures the working directory of the container to the hardcoded /src path.
func NewCacheVolumeWithFileHashKeys ¶
func NewCacheVolumeWithFileHashKeys( ctx context.Context, client *dagger.Client, cacheKeyPrefix string, workDir *dagger.Directory, fileNames ...string, ) (*dagger.CacheVolume, error)
NewCacheVolumeWithFileHashKeys creates a new cache volume with generated keys based on the file hashes and prefix.
Types ¶
type ContainerCustomizerFn ¶
ContainerCustomizerFn is a function that customizes a container.
func AppendToPATH ¶
func AppendToPATH(ctx context.Context, path string) ContainerCustomizerFn
AppendToPATH appends the given path to the PATH environment variable.
func DownloadExecutableFile ¶
func DownloadExecutableFile(url, destFile string) ContainerCustomizerFn
DownloadExecutableFile downloads the given URL to the given destination file and makes it executable.
func DownloadFile ¶
func DownloadFile(url, destFile string) ContainerCustomizerFn
DownloadFile downloads the given URL to the given destination file.
func InstallGithubCli ¶
func InstallGithubCli(version string, extensions ...string) ContainerCustomizerFn
InstallGithubCli installs github cli in the container using the given version and provided extensions. If the version is empty, the hardcoded "2.20.2" is used.
Github cli uses GITHUB_TOKEN to authenticate, installation process read GITHUB_TOKEN env variable from host and configure it as a secret.
The container must have the "curl" and "tar" binaries installed in order to install Go.
func InstallGo ¶
func InstallGo(ctx context.Context, version string) ContainerCustomizerFn
InstallGo installs Go in the container using the given version. If the version is empty, the hardcoded "1.19.3" is used.
The container must have the "curl" and "tar" binaries installed in order to install Go.
func WithDockerSocket ¶
func WithDockerSocket() ContainerCustomizerFn
WithDockerSocket mounts the Docker socket from the host and sets the DOCKER_HOST environment variable in the container.
func WithEnvVariables ¶
func WithEnvVariables(env map[string]string) ContainerCustomizerFn
WithEnvVariables sets the given environment variables in the container.
func WithGitHubEnvs ¶
func WithGitHubEnvs(ctx context.Context) ContainerCustomizerFn
WithGitHubEnvs sets GitHub environment variables in the container from the host.
The following environment variables are set: - GITHUB_TOKEN as a secret - GITHUB_* as regular environment variables except for GITHUB_TOKEN - RUNNER_* as regular environment variables.
func WithGithubAuth ¶
func WithGithubAuth(ctx context.Context) ContainerCustomizerFn
WithGithubAuth sets the GitHub authentication for git commands in the container.
if SSH_AUTH_SOCK is exist, ssh authentication will be used, otherwise, https authentication with GITHUB_TOKEN, will be used.
func WithHostEnvSecret ¶
func WithHostEnvSecret(name string) ContainerCustomizerFn
WithHostEnvSecret sets the given environment variable in the container from the host as a secret.
func WithHostEnvSecrets ¶
func WithHostEnvSecrets(include ...string) ContainerCustomizerFn
WithHostEnvSecrets sets the given environment variables in the container from the host as secrets.
func WithHostEnvVariable ¶
func WithHostEnvVariable(ctx context.Context, name string) ContainerCustomizerFn
WithHostEnvVariable sets the given environment variable in the container from the host.
func WithHostEnvVariables ¶
func WithHostEnvVariables(ctx context.Context, include ...string) ContainerCustomizerFn
WithHostEnvVariables sets the given environment variables in the container from the host.
func WithHostEnvVariablesWithPrefix ¶
func WithHostEnvVariablesWithPrefix(ctx context.Context, prefix string, ignore ...string) ContainerCustomizerFn
WithHostEnvVariablesWithPrefix sets the given environment variables in the container from the host, using the given prefix to filter the host environment variables. If a ignore list is given, the variables in the ignore list are explicitly ignored to avoid leaking sensitive information and/or to avoid conflicts.
For example, if the prefix is "FOO_" and the ignore list is "FOO_PASSWORD", the environment variable "FOO_PASSWORD" from the host will be ignored, but "FOO_USERNAME" will be set in the container.
func WithMountedCache ¶
func WithMountedCache(cacheVol *dagger.CacheVolume, path, envVarName string) ContainerCustomizerFn
WithMountedCache mounts the given cache volume at the given path in the container and if envVarName provided, set env variable with the cache mount path.
func WithMountedGoCache ¶
func WithMountedGoCache(ctx context.Context, path string) ContainerCustomizerFn
WithMountedGoCache mounts a cache volume for the container's GOCACHE and GOMODCACHE environment variables using the contents of the go.mod and go.sum files in the given path. If the path is empty, the current working directory is used.
func WithSSHSocket ¶
func WithSSHSocket(ctx context.Context) ContainerCustomizerFn
WithSSHSocket mounts the SSH socket from the host into the container and sets the SSH_AUTH_SOCK environment variable.