dockerfile

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CACertEnvVar is the environment variable that specifies the CA certificate to inject
	CACertEnvVar = "COG_CA_CERT"

	// CACertFilename is the filename used for the CA cert in the build context and container
	CACertFilename = "cog-ca-cert.crt"

	// CACertContainerPath is where the cert is installed in the container
	CACertContainerPath = "/usr/local/share/ca-certificates/" + CACertFilename

	// SystemCertBundle is the path to the system certificate bundle after update-ca-certificates
	SystemCertBundle = "/etc/ssl/certs/ca-certificates.crt"
)
View Source
const CFlags = "ENV CFLAGS=\"-O3 -funroll-loops -fno-strict-aliasing -flto -S\""
View Source
const CogBaseImageName = "cog-base"
View Source
const LDConfigCacheBuildCommand = "RUN find / -type f -name \"*python*.so\" -printf \"%h\\n\" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig"
View Source
const MinimumCUDAVersion = "11.6"
View Source
const MinimumPythonVersion = "3.10"
View Source
const MinimumTorchVersion = "1.13.1"
View Source
const PrecompilePythonCommand = "" /* 247-byte string literal not displayed */
View Source
const STANDARD_GENERATOR_NAME = "STANDARD_GENERATOR"
View Source
const StripDebugSymbolsCommand = "find / -type f -name \"*python*.so\" -not -name \"*cpython*.so\" -exec strip -S {} \\;"
View Source
const UVVersion = "0.9.26"

Variables

This section is empty.

Functions

func BaseImageConfigurationExists added in v0.9.7

func BaseImageConfigurationExists(ctx context.Context, client registry.Client, cudaVersion, pythonVersion, torchVersion string, generate bool) (bool, string, string, string, error)

func BaseImageName added in v0.9.7

func BaseImageName(cudaVersion string, pythonVersion string, torchVersion string) string

func CheckMajorMinorOnly added in v0.14.0

func CheckMajorMinorOnly(s string) bool

func GenerateCACertInstall added in v0.16.10

func GenerateCACertInstall(certData []byte, writeTemp func(filename string, contents []byte) ([]string, string, error)) (string, error)

GenerateCACertInstall generates the Dockerfile lines to install a CA certificate. It writes the cert to the build context and returns the Dockerfile lines.

The returned lines:

  1. COPY the cert to /usr/local/share/ca-certificates/
  2. RUN update-ca-certificates
  3. Set SSL_CERT_FILE and REQUESTS_CA_BUNDLE env vars

Parameters:

  • certData: The PEM-encoded certificate data
  • writeTemp: Function to write a file to the build context (returns COPY lines and container path)

Returns the Dockerfile lines to add, or error

func ReadCACert added in v0.16.10

func ReadCACert() ([]byte, error)

ReadCACert reads the CA certificate from the COG_CA_CERT environment variable. It supports multiple input formats:

  • File path: /path/to/cert.crt
  • Directory: /path/to/certs/ (concatenates all *.crt and *.pem files)
  • Inline PEM: -----BEGIN CERTIFICATE-----...
  • Base64-encoded PEM: LS0tLS1CRUdJTi...

Returns:

  • (nil, nil) if COG_CA_CERT is not set (no-op case)
  • (certBytes, nil) if a valid certificate was found
  • (nil, error) if the input is invalid

Types

type AvailableBaseImageConfigurations added in v0.9.10

type AvailableBaseImageConfigurations struct {
	PythonVersions []PythonVersion `json:"python_versions"`
}

type BaseImageConfiguration added in v0.9.7

type BaseImageConfiguration struct {
	CUDAVersion   string `json:"cuda_version" yaml:"cuda_version"`
	PythonVersion string `json:"python_version" yaml:"python_version"`
	TorchVersion  string `json:"torch_version" yaml:"torch_version"`
}

func BaseImageConfigurations added in v0.9.7

func BaseImageConfigurations() []BaseImageConfiguration

BaseImageConfigurations returns a list of CUDA/Python/Torch versions

func (BaseImageConfiguration) MarshalJSON added in v0.9.7

func (b BaseImageConfiguration) MarshalJSON() ([]byte, error)

type BaseImageGenerator added in v0.9.7

type BaseImageGenerator struct {
	// contains filtered or unexported fields
}

func NewBaseImageGenerator added in v0.9.7

func NewBaseImageGenerator(ctx context.Context, client registry.Client, cudaVersion string, pythonVersion string, torchVersion string, command command.Command, generate bool) (*BaseImageGenerator, error)

func (*BaseImageGenerator) GenerateDockerfile added in v0.9.7

func (g *BaseImageGenerator) GenerateDockerfile(ctx context.Context) (string, error)

func (*BaseImageGenerator) SetBreakSystemPackages added in v0.20.0

func (g *BaseImageGenerator) SetBreakSystemPackages(breakSystemPackages bool)

func (*BaseImageGenerator) SetBuildContextDir added in v0.20.0

func (g *BaseImageGenerator) SetBuildContextDir(buildContextDir string)

type CUDAVersion added in v0.9.10

type CUDAVersion struct {
	Version string `json:"versions"`
}

type Generator added in v0.0.16

type Generator interface {
	GenerateInitialSteps(ctx context.Context) (string, error)
	SetUseCogBaseImage(bool)
	SetUseCogBaseImagePtr(*bool)
	SetBreakSystemPackages(bool)
	GenerateModelBaseWithSeparateWeights(ctx context.Context, imageName string) (string, string, []string, error)
	SetStrip(bool)
	SetPrecompile(bool)
	SetUseCudaBaseImage(string)
	IsUsingCogBaseImage() bool
	BaseImage(ctx context.Context) (string, error)
	GenerateWeightsManifest(ctx context.Context) (*weightslegacy.Manifest, error)
	GenerateDockerfileWithoutSeparateWeights(ctx context.Context) (string, error)
	GenerateModelBase(ctx context.Context) (string, error)
	Name() string
	BuildDir() (string, error)
	BuildContexts() (map[string]string, error)
	BuildCacheDir() string
}

type PyTorchVersion added in v0.9.10

type PyTorchVersion struct {
	Version string `json:"version"`
}

type PythonVersion added in v0.9.10

type PythonVersion struct {
	Version string           `json:"version"`
	PyTorch []PyTorchVersion `json:"pytorch"`
	CUDA    []CUDAVersion    `json:"cuda"`
}

type StandardGenerator added in v0.13.7

type StandardGenerator struct {
	Config         *config.Config
	Dir            string
	ConfigFilename string // Base filename like "cog.yaml" or "my-config.yaml"

	// these are here to make this type testable
	GOOS   string
	GOARCH string
	// contains filtered or unexported fields
}

func NewStandardGenerator added in v0.13.7

func NewStandardGenerator(config *config.Config, dir string, buildCacheDir string, configFilename string, command command.Command, client registry.Client, requiresCog bool) (*StandardGenerator, error)

func (*StandardGenerator) BaseImage added in v0.13.7

func (g *StandardGenerator) BaseImage(ctx context.Context) (string, error)

func (*StandardGenerator) BuildCacheDir added in v0.20.0

func (g *StandardGenerator) BuildCacheDir() string

BuildCacheDir returns the absolute path to .cog/build/ where all build staging artifacts live (Dockerfile, wheels, requirements.txt, schemas, weights manifest, CA certs).

func (*StandardGenerator) BuildContexts added in v0.14.4

func (g *StandardGenerator) BuildContexts() (map[string]string, error)

BuildContexts returns named build contexts passed to BuildKit. The "cog_build" context points at .cog/build/ and is referenced by COPY --from=cog_build instructions in the generated Dockerfile.

func (*StandardGenerator) BuildDir added in v0.14.4

func (g *StandardGenerator) BuildDir() (string, error)

BuildDir returns the Docker build context directory (the project root). The context is filtered at the BuildKit session level to exclude .cog/, so this just returns "." — the actual filtering happens in buildkit.go via ExcludePatterns.

func (*StandardGenerator) GenerateDockerfileWithoutSeparateWeights added in v0.13.7

func (g *StandardGenerator) GenerateDockerfileWithoutSeparateWeights(ctx context.Context) (string, error)

GenerateDockerfileWithoutSeparateWeights generates a Dockerfile that doesn't write model weights to a separate layer.

func (*StandardGenerator) GenerateInitialSteps added in v0.13.7

func (g *StandardGenerator) GenerateInitialSteps(ctx context.Context) (string, error)

func (*StandardGenerator) GenerateModelBase added in v0.13.7

func (g *StandardGenerator) GenerateModelBase(ctx context.Context) (string, error)

func (*StandardGenerator) GenerateModelBaseWithSeparateWeights added in v0.13.7

func (g *StandardGenerator) GenerateModelBaseWithSeparateWeights(ctx context.Context, imageName string) (weightsBase string, dockerfile string, weightsExcludePatterns []string, err error)

GenerateModelBaseWithSeparateWeights creates a weights Dockerfile (FROM scratch + COPY), a runner Dockerfile (full image minus weight files), and a list of exclude patterns for the runner build context (so weight files aren't sent twice).

func (*StandardGenerator) GenerateWeightsManifest added in v0.13.7

func (g *StandardGenerator) GenerateWeightsManifest(ctx context.Context) (*weightslegacy.Manifest, error)

func (*StandardGenerator) IsUsingCogBaseImage added in v0.13.7

func (g *StandardGenerator) IsUsingCogBaseImage() bool

func (*StandardGenerator) Name added in v0.13.7

func (g *StandardGenerator) Name() string

func (*StandardGenerator) SetBreakSystemPackages added in v0.20.0

func (g *StandardGenerator) SetBreakSystemPackages(breakSystemPackages bool)

func (*StandardGenerator) SetPrecompile added in v0.13.7

func (g *StandardGenerator) SetPrecompile(precompile bool)

func (*StandardGenerator) SetStrip added in v0.13.7

func (g *StandardGenerator) SetStrip(strip bool)

func (*StandardGenerator) SetUseCogBaseImage added in v0.13.7

func (g *StandardGenerator) SetUseCogBaseImage(useCogBaseImage bool)

func (*StandardGenerator) SetUseCogBaseImagePtr added in v0.13.7

func (g *StandardGenerator) SetUseCogBaseImagePtr(useCogBaseImage *bool)

func (*StandardGenerator) SetUseCudaBaseImage added in v0.13.7

func (g *StandardGenerator) SetUseCudaBaseImage(argumentValue string)

Jump to

Keyboard shortcuts

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