imageoptions

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRegistryAuth

func SetRegistryAuth(username, password string) interface{}

SetRegistryAuth sets the registry authentication credentials for pushing or pulling images.

Usage example for pull:

image.SetPullOptions(
	imageoptions.SetRegistryAuth("username", "password"),
)

Usage example for push:

image.SetPushOptions(
	imageoptions.SetRegistryAuth("username", "password"),
)

Types

type Auth

type Auth struct {
	Username string
	Password string
}

Auth represents registry authentication credentials

type BuilderVersion

type BuilderVersion string

BuilderVersion represents the version of the builder to use

const (
	// BuilderV1 uses the legacy builder
	BuilderV1 BuilderVersion = "1"
	// BuilderV2 uses BuildKit
	BuilderV2 BuilderVersion = "2"
)

type OutputType

type OutputType string

OutputType represents the type of build output

const (
	// LocalOutput represents output to a local directory
	LocalOutput OutputType = "local"
	// TarOutput represents output to a tar file
	TarOutput OutputType = "tar"
	// ImageOutput represents output as a Docker image
	ImageOutput OutputType = "image"
)

type SetBuildOptFn

type SetBuildOptFn func(options *types.ImageBuildOptions)

SetBuildOptFn is a function type that configures build options for a Docker image.

func AddLabel

func AddLabel(key, value string) SetBuildOptFn

AddLabel adds a label to the built image.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.AddLabel("org.label-schema.version", "1.0.0"),
)

func AddOutput

func AddOutput(outputType OutputType, attrs map[string]string) SetBuildOptFn

AddOutput adds an output configuration for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	// Output to a local directory
	imageoptions.AddOutput(imageoptions.LocalOutput, map[string]string{
		"dest": "/tmp/output",
	}),
	// Output as a tar file
	imageoptions.AddOutput(imageoptions.TarOutput, map[string]string{
		"dest": "/tmp/output.tar",
	}),
	// Output as an image
	imageoptions.AddOutput(imageoptions.ImageOutput, map[string]string{
		"name": "my-org/my-image:latest",
	}),
)

func AddTag

func AddTag(tag string) SetBuildOptFn

AddTag adds a tag to the image.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.AddTag("v1.0.0"),
	imageoptions.AddTag("latest"),
)

func AllowExtraHosts

func AllowExtraHosts(extraHosts []string) SetBuildOptFn

AllowExtraHosts adds entries to /etc/hosts in building containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.AllowExtraHosts([]string{
		"myhost:10.10.10.10",
		"myother:10.10.10.11",
	}),
)

func CacheEnabled

func CacheEnabled(enabled bool) SetBuildOptFn

CacheEnabled controls whether to use the build cache.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.CacheEnabled(false), // Disable cache
)

func ForceRemove

func ForceRemove(force bool) SetBuildOptFn

ForceRemove forces the removal of the image even if it is being used by stopped containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.ForceRemove(true),
)

func RemoveIntermediateContainers

func RemoveIntermediateContainers(remove bool) SetBuildOptFn

RemoveIntermediateContainers specifies whether to remove intermediate containers after a successful build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.RemoveIntermediateContainers(true),
)

func SetBuildArgs

func SetBuildArgs(args map[string]*string) SetBuildOptFn

SetBuildArgs sets build-time variables.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetBuildArgs(map[string]*string{
		"VERSION": &version,
		"DEBUG": &debug,
	}),
)

func SetBuildContext

func SetBuildContext(context io.Reader) SetBuildOptFn

SetBuildContext provides the build context for the image.

Usage example:

tarFile := createTarContext() // Your tar creation logic
img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetBuildContext(bytes.NewReader(tarFile)),
)

func SetBuildID

func SetBuildID(buildID string) SetBuildOptFn

SetBuildID sets a unique ID for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetBuildID("build-123"),
)

func SetBuildInfo

func SetBuildInfo(args map[string]string) SetBuildOptFn

SetBuildInfo sets build info arguments for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetBuildInfo(map[string]string{
		"key": "value",
	}),
)

func SetBuildPlatform

func SetBuildPlatform(platform string) SetBuildOptFn

SetBuildPlatform sets the platform for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetBuildPlatform("linux/amd64"),
)

func SetBuilderVersion

func SetBuilderVersion(version BuilderVersion) SetBuildOptFn

SetBuilderVersion sets the version of the builder to use.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetBuilderVersion(imageoptions.BuilderV2),
)

func SetCPUSetCPUs

func SetCPUSetCPUs(cpusetcpus string) SetBuildOptFn

SetCPUSetCPUs sets which CPUs to use for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetCPUSetCPUs("0-3"),
)

func SetCPUShares

func SetCPUShares(cpushares int64) SetBuildOptFn

SetCPUShares sets CPU shares for build containers (relative weight).

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetCPUShares(1024),
)

func SetCgroupParent

func SetCgroupParent(cgroupParent string) SetBuildOptFn

SetCgroupParent sets the parent cgroup for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetCgroupParent("/custom/cgroup"),
)

func SetDockerfile

func SetDockerfile(path string) SetBuildOptFn

SetDockerfile specifies the path to the Dockerfile.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetDockerfile("./Dockerfile.prod"),
)

func SetExtraHosts

func SetExtraHosts(hosts []string) SetBuildOptFn

SetExtraHosts adds extra hosts to /etc/hosts in building containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetExtraHosts([]string{
		"myhost:10.10.10.10",
		"myother:10.10.10.11",
	}),
)

func SetIsolation

func SetIsolation(isolation string) SetBuildOptFn

SetIsolation sets container isolation technology.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetIsolation("hyperv"),
)

func SetMemory

func SetMemory(memory int64) SetBuildOptFn

SetMemory sets memory limit for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetMemory(1024*1024*1024), // 1GB
)

func SetNetworkMode

func SetNetworkMode(networkMode string) SetBuildOptFn

SetNetworkMode sets the networking mode for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetNetworkMode("host"),
)

func SetPullParent

func SetPullParent(pull bool) SetBuildOptFn

SetPullParent controls whether to pull the parent image.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetPullParent(true),
)

func SetPullPolicy

func SetPullPolicy(policy string) SetBuildOptFn

SetPullPolicy sets the pull policy for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetPullPolicy("always"),
)

func SetSecurityOpt

func SetSecurityOpt(securityOpt []string) SetBuildOptFn

SetSecurityOpt sets security options for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetSecurityOpt([]string{
		"seccomp=unconfined",
		"apparmor=unconfined",
	}),
)

func SetSessionID

func SetSessionID(sessionID string) SetBuildOptFn

SetSessionID sets a unique session ID for the build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetSessionID("session-123"),
)

func SetShmSize

func SetShmSize(shmSize int64) SetBuildOptFn

SetShmSize sets the size of /dev/shm for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetShmSize(67108864), // 64MB
)

func SetSquash

func SetSquash(squash bool) SetBuildOptFn

SetSquash squashes newly built layers into a single new layer.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetSquash(true),
)

func SetTarget

func SetTarget(target string) SetBuildOptFn

SetTarget sets the target build stage to build.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetTarget("prod"),
)

func SetUlimitCore

func SetUlimitCore(soft, hard int64) SetBuildOptFn

SetUlimitCore sets the core file size limit for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetUlimitCore(0, 0), // disable core dumps
)

func SetUlimitMemlock

func SetUlimitMemlock(soft, hard int64) SetBuildOptFn

SetUlimitMemlock sets the locked-in-memory address space limit for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetUlimitMemlock(65536, 65536), // 64KB soft and hard limit
)

func SetUlimitNProc

func SetUlimitNProc(soft, hard int64) SetBuildOptFn

SetUlimitNProc sets the process limit for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetUlimitNProc(4096, 8192), // soft limit, hard limit
)

func SetUlimitNoFile

func SetUlimitNoFile(soft, hard int64) SetBuildOptFn

SetUlimitNoFile sets the file descriptor limits for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetUlimitNoFile(65535, 65535), // soft limit, hard limit
)

func SetUlimitRtPrio

func SetUlimitRtPrio(soft, hard int64) SetBuildOptFn

SetUlimitRtPrio sets the real-time priority limit for build containers.

Usage example:

img := image.NewConfig("my-image")
img.SetBuildOptions(
	imageoptions.SetUlimitRtPrio(0, 0), // disable real-time priority
)

type SetPullOptFn

type SetPullOptFn func(options *image.PullOptions)

SetPullOptFn is a function type that configures pull options for a Docker image.

func PullAllTags

func PullAllTags(enabled bool) SetPullOptFn

PullAllTags specifies whether to download all tagged images in the repository.

Usage example:

img := image.NewConfig("alpine")
img.SetPullOptions(
	imageoptions.PullAllTags(true),
)

func SetPlatform

func SetPlatform(platform string) SetPullOptFn

SetPlatform sets the platform for pulling multi-platform images.

Usage example:

image.SetPullOptions(
	imageoptions.SetPlatform("linux/amd64"),
)

func SetPrivilegeFunc

func SetPrivilegeFunc(authFn func(ctx context.Context) (string, error)) SetPullOptFn

SetPrivilegeFunc sets the authentication function for restricted access images.

Usage example:

img := image.NewConfig("private-repo/my-image")
img.SetPullOptions(
	imageoptions.SetPrivilegeFunc(func(ctx context.Context) (string, error) {
		return "Bearer " + os.Getenv("DOCKER_TOKEN"), nil
	}),
)

func SetPullPlatform

func SetPullPlatform(platform string) SetPullOptFn

SetPullPlatform sets the platform for image pulling.

Usage example:

img := image.NewConfig("my-image")
img.SetPullOptions(
	imageoptions.SetPullPlatform("linux/amd64"),
)

func UseCurrentPlatform

func UseCurrentPlatform() SetPullOptFn

UseCurrentPlatform sets the platform to match the current system architecture.

Usage example:

img := image.NewConfig("alpine")
img.SetPullOptions(
	imageoptions.UseCurrentPlatform(),
)

type SetPushOptFn

type SetPushOptFn func(options *image.PushOptions)

SetPushOptFn is a function type that configures push options for a Docker image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL