container

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DOCKER_COMMAND = "docker"
	PODMAN_COMMAND = "podman"
)
View Source
const IMAGE_NAME_PREFIX = "cli-"
View Source
const LABEL_PREFIX = "dev.openrun."
View Source
const (
	OPENRUN_FIELD_MANAGER = "openrun"
)
View Source
const UNNAMED_VOLUME = "<UNNAMED>"
View Source
const VERSION_HASH_LABEL = LABEL_PREFIX + "version.hash"

Variables

View Source
var (
	KNOWN_OPTIONS = []string{"cpus", "memory", "min_replicas", "max_replicas"}
)

Functions

func BuildHTTPTransport

func BuildHTTPTransport(r *types.RegistryConfig) (*http.Transport, error)

func BytesString added in v0.16.0

func BytesString(s string) (string, error)

BytesString parses s and returns bytes as a base-10 integer string.

Rules: 1) If already an integer string (bytes), return as-is. 2) If docker-like (e.g., 512m, 1g), parse via Docker and return bytes. 3) Otherwise parse as k8s Quantity (e.g., 512Mi, 1Gi, 500M) and return bytes.

func CPUString added in v0.16.0

func CPUString(s string, targetIsDocker bool) (string, error)

CPUString converts CPU from either docker-like ("0.5", "2") or k8s-like ("500m", "1") into a string that "makes sense" for the target.

  • targetIsDocker=true => return cores as decimal string (e.g. "0.5", "2")
  • targetIsDocker=false => return millicores as integer string (e.g. "500", "2000")

Notes:

  • Bare "1" is treated as 1 core (not 1 millicore).
  • For millicores input, use "m" suffix: "500m".

func CreateOrUpdateSecret

func CreateOrUpdateSecret(ctx context.Context, cs *kubernetes.Clientset, ns, name string, data map[string][]byte, typ corev1.SecretType) error

func DelegateHandler

func DelegateHandler(w http.ResponseWriter, r *http.Request, config *types.ServerConfig, logger *types.Logger)

DelegateHandler is the handler for the delegated build API

func GenerateDockerConfigJSON

func GenerateDockerConfigJSON(r *types.RegistryConfig) ([]byte, error)

func GetDockerConfig

func GetDockerConfig(ctx context.Context, imageRef string, registryConfig *types.RegistryConfig) (name.Reference, []remote.Option, error)

func ImageExists

func ImageExists(ctx context.Context, logger *types.Logger, imageRef string, r *types.RegistryConfig) (bool, error)

func KanikoJob

func KanikoJob(ctx context.Context, logger *types.Logger, cs *kubernetes.Clientset, cfg *rest.Config, r *types.RegistryConfig, dockerCfgJSON []byte, kb KanikoBuild) error

func LookupContainerCommand

func LookupContainerCommand(checkKubernetes bool) string

func TrimLabelValue added in v0.16.0

func TrimLabelValue(input string) string

TrimLabelValue trims the input string to 63 characters so that it can be used as a Kubernetes label value

Types

type CommandCM added in v0.16.0

type CommandCM struct {
	*types.Logger
	// contains filtered or unexported fields
}

func NewCommandCM added in v0.16.0

func NewCommandCM(logger *types.Logger, config *types.ServerConfig, appId types.AppId, appRunDir string) *CommandCM

func (*CommandCM) BuildImage added in v0.16.0

func (c *CommandCM) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, containerArgs map[string]string) error

func (*CommandCM) ExecTailN added in v0.16.0

func (c *CommandCM) ExecTailN(ctx context.Context, command string, args []string, n int) ([]string, error)

ExecTailN executes a command and returns the last n lines of output

func (*CommandCM) GetContainerLogs added in v0.16.0

func (c *CommandCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)

func (*CommandCM) GetContainerState added in v0.16.0

func (c *CommandCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)

GetContainerState returns the host:port of the running container, "" if not running. running is true if the container is running.

func (*CommandCM) ImageExists added in v0.16.0

func (c *CommandCM) ImageExists(ctx context.Context, name ImageName) (bool, error)

func (*CommandCM) RemoveContainer added in v0.16.0

func (c *CommandCM) RemoveContainer(ctx context.Context, name ContainerName) error

func (*CommandCM) RemoveImage added in v0.16.0

func (c *CommandCM) RemoveImage(ctx context.Context, name ImageName) error

func (*CommandCM) RunContainer added in v0.16.0

func (c *CommandCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName,
	imageName ImageName, port int64, envMap map[string]string, volumes []*VolumeInfo,
	containerOptions map[string]string, paramMap map[string]string, versionHash string) error

func (*CommandCM) StartContainer added in v0.16.0

func (c *CommandCM) StartContainer(ctx context.Context, name ContainerName) error

func (*CommandCM) StopContainer added in v0.16.0

func (c *CommandCM) StopContainer(ctx context.Context, name ContainerName) error

func (*CommandCM) SupportsInPlaceUpdate added in v0.16.0

func (k *CommandCM) SupportsInPlaceUpdate() bool

func (CommandCM) VolumeCreate added in v0.16.0

func (c CommandCM) VolumeCreate(ctx context.Context, name VolumeName) error

func (CommandCM) VolumeExists added in v0.16.0

func (c CommandCM) VolumeExists(ctx context.Context, name VolumeName) bool

type CommandOptions added in v0.16.0

type CommandOptions struct {
	Other map[string]any `mapstructure:",remain"`
	// contains filtered or unexported fields
}

type Container

type Container struct {
	ID         string `json:"ID"`
	Names      string `json:"Names"`
	Image      string `json:"Image"`
	State      string `json:"State"`
	Status     string `json:"Status"`
	PortString string `json:"Ports"`
	Port       int
}

type ContainerManager

type ContainerManager interface {
	BuildImage(ctx context.Context, name ImageName, sourceUrl, containerFile string, containerArgs map[string]string) error
	ImageExists(ctx context.Context, name ImageName) (bool, error)
	GetContainerState(ctx context.Context, name ContainerName, expectHash string) (hostPort string, running bool, err error)
	StartContainer(ctx context.Context, name ContainerName) error
	StopContainer(ctx context.Context, name ContainerName) error
	RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName,
		imageName ImageName, port int64, envMap map[string]string, volumes []*VolumeInfo,
		containerOptions map[string]string, paramMap map[string]string, versionHash string) error
	GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
	VolumeExists(ctx context.Context, name VolumeName) bool
	VolumeCreate(ctx context.Context, name VolumeName) error
	SupportsInPlaceUpdate() bool
}

ContainerManager is the interface for managing containers

type ContainerName

type ContainerName string

func GenContainerName

func GenContainerName(appId types.AppId, cm ContainerManager, contentHash string, supportsInPlaceUpdate bool) ContainerName

type DelegateRequest

type DelegateRequest struct {
	ImageTag       string
	ContainerFile  string
	ContainerArgs  map[string]string
	RegistryConfig *types.RegistryConfig
}

type DevContainerManager

type DevContainerManager interface {
	ContainerManager
	RemoveImage(ctx context.Context, name ImageName) error
	RemoveContainer(ctx context.Context, name ContainerName) error
}

DevContainerManager is the interface for managing containers in dev mode

type ExistsResult

type ExistsResult struct {
	Exists bool
	Digest string
}

func CheckImagesExists

func CheckImagesExists(ctx context.Context, logger *types.Logger, imageRef string, registryConfig *types.RegistryConfig) (ExistsResult, error)

type ImageName

type ImageName string

func GenImageName

func GenImageName(appId types.AppId, contentHash string) ImageName

type KanikoBuild

type KanikoBuild struct {
	Namespace     string
	JobName       string
	Image         string // e.g. "cgr.dev/chainguard/kaniko:latest"
	SourceDir     string // Local directory to tar up and send to Kaniko
	Dockerfile    string
	Destination   string
	ContainerArgs map[string]string
	ExtraArgs     []string
}

type KubernetesCM added in v0.16.0

type KubernetesCM struct {
	*types.Logger
	// contains filtered or unexported fields
}

func NewKubernetesCM added in v0.16.0

func NewKubernetesCM(logger *types.Logger, config *types.ServerConfig, appConfig *types.AppConfig, appRunDir string, appId types.AppId) (*KubernetesCM, error)

func (*KubernetesCM) BuildImage added in v0.16.0

func (k *KubernetesCM) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, containerArgs map[string]string) error

func (*KubernetesCM) GetContainerLogs added in v0.16.0

func (k *KubernetesCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)

func (*KubernetesCM) GetContainerState added in v0.16.0

func (k *KubernetesCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)

func (*KubernetesCM) ImageExists added in v0.16.0

func (k *KubernetesCM) ImageExists(ctx context.Context, name ImageName) (bool, error)

func (*KubernetesCM) RunContainer added in v0.16.0

func (k *KubernetesCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName,
	imageName ImageName, port int64, envMap map[string]string, volumes []*VolumeInfo,
	containerOptions map[string]string, paramMap map[string]string, versionHash string) error

func (*KubernetesCM) StartContainer added in v0.16.0

func (k *KubernetesCM) StartContainer(ctx context.Context, name ContainerName) error

func (*KubernetesCM) StopContainer added in v0.16.0

func (k *KubernetesCM) StopContainer(ctx context.Context, name ContainerName) error

func (*KubernetesCM) SupportsInPlaceUpdate added in v0.16.0

func (k *KubernetesCM) SupportsInPlaceUpdate() bool

func (*KubernetesCM) VolumeCreate added in v0.16.0

func (k *KubernetesCM) VolumeCreate(ctx context.Context, name VolumeName) error

func (*KubernetesCM) VolumeExists added in v0.16.0

func (k *KubernetesCM) VolumeExists(ctx context.Context, name VolumeName) bool

type KubernetesOptions added in v0.16.0

type KubernetesOptions struct {
	Cpus        string         `mapstructure:"cpus"`
	Memory      string         `mapstructure:"memory"`
	MinReplicas int32          `mapstructure:"min_replicas"` // min number of replicas to run the app on
	MaxReplicas int32          `mapstructure:"max_replicas"` // max number of replicas to run the app on
	Other       map[string]any `mapstructure:",remain"`
}

type VolumeInfo

type VolumeInfo struct {
	IsSecret   bool
	VolumeName string
	SourcePath string
	TargetPath string
	ReadOnly   bool
}

type VolumeName

type VolumeName string

func GenVolumeName

func GenVolumeName(appId types.AppId, dirName string) VolumeName

Jump to

Keyboard shortcuts

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