Documentation
¶
Index ¶
- Constants
- Variables
- func BuildHTTPTransport(r *types.RegistryConfig) (*http.Transport, error)
- func BytesString(s string) (string, error)
- func CPUString(s string, targetIsDocker bool) (string, error)
- func CommandOptionArgs(options CommandOptions, allowedContainerArgs map[string]string) ([]string, error)
- func CreateOrUpdateSecret(ctx context.Context, cs kubernetes.Interface, ns, name string, ...) error
- func DelegateHandler(r *http.Request, config *types.ServerConfig, logger *types.Logger) (any, error)
- func DigestPinned(image, digest string) string
- func GenerateDockerConfigJSON(r *types.RegistryConfig) ([]byte, error)
- func GetDockerConfig(ctx context.Context, imageRef string, registryConfig *types.RegistryConfig) (name.Reference, []remote.Option, error)
- func ImageExists(ctx context.Context, logger *types.Logger, imageRef string, ...) (bool, error)
- func KanikoJob(ctx context.Context, logger *types.Logger, cs kubernetes.Interface, ...) error
- func LookupContainerCommand(checkKubernetes bool) string
- func TrimLabelValue(input string) string
- type CommandCM
- func (c *CommandCM) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, ...) error
- func (c *CommandCM) ExecTailN(ctx context.Context, command string, args []string, n int) ([]string, error)
- func (c *CommandCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
- func (c *CommandCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)
- func (c *CommandCM) ImageExists(ctx context.Context, name ImageName) (bool, error)
- func (c *CommandCM) ListOpenRunContainers(ctx context.Context) ([]Container, error)
- func (c *CommandCM) RefreshImage(ctx context.Context, name ImageName) (string, error)
- func (c *CommandCM) RemoveContainer(ctx context.Context, name ContainerName) error
- func (c *CommandCM) RemoveImage(ctx context.Context, name ImageName) error
- func (c *CommandCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, ...) error
- func (c *CommandCM) StartContainer(ctx context.Context, name ContainerName) error
- func (c *CommandCM) StopContainer(ctx context.Context, name ContainerName) error
- func (k *CommandCM) SupportsInPlaceUpdate() bool
- func (c CommandCM) VolumeCreate(ctx context.Context, name VolumeName) error
- func (c CommandCM) VolumeExists(ctx context.Context, name VolumeName) bool
- type CommandOptions
- type Container
- type ContainerManager
- type ContainerName
- type DelegateRequest
- type DevContainerManager
- type ExistsResult
- type ImageName
- type KanikoBuild
- type KubernetesCM
- func (k *KubernetesCM) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, ...) error
- func (k *KubernetesCM) GetContainerLogs(ctx context.Context, name ContainerName, linesToShow int) (string, error)
- func (k *KubernetesCM) GetContainerState(ctx context.Context, name ContainerName, expectHash string) (string, bool, error)
- func (k *KubernetesCM) ImageExists(ctx context.Context, name ImageName) (bool, error)
- func (k *KubernetesCM) RefreshImage(ctx context.Context, name ImageName) (string, error)
- func (k *KubernetesCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, ...) error
- func (k *KubernetesCM) StartContainer(ctx context.Context, name ContainerName) error
- func (k *KubernetesCM) StopContainer(ctx context.Context, name ContainerName) error
- func (k *KubernetesCM) SupportsInPlaceUpdate() bool
- func (k *KubernetesCM) VolumeCreate(ctx context.Context, name VolumeName) error
- func (k *KubernetesCM) VolumeExists(ctx context.Context, name VolumeName) bool
- type KubernetesOptions
- type VolumeInfo
- type VolumeName
Constants ¶
const ( DOCKER_COMMAND = "docker" PODMAN_COMMAND = "podman" )
const IMAGE_NAME_PREFIX = "cli-"
const LABEL_PREFIX = "dev.openrun."
const (
OPENRUN_FIELD_MANAGER = "openrun"
)
const UNNAMED_VOLUME = "<UNNAMED>"
const VERSION_HASH_LABEL = LABEL_PREFIX + "version.hash"
Variables ¶
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
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
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 CommandOptionArgs ¶ added in v0.17.0
func CommandOptionArgs(options CommandOptions, allowedContainerArgs map[string]string) ([]string, error)
CommandOptionArgs converts parsed container options into CLI args. Built-in OpenRun options are parsed explicitly. Any remaining Docker/Podman flags must be listed in allowedContainerArgs before they are emitted.
func CreateOrUpdateSecret ¶
func CreateOrUpdateSecret(ctx context.Context, cs kubernetes.Interface, ns, name string, data map[string][]byte, typ corev1.SecretType) error
func DelegateHandler ¶
func DelegateHandler(r *http.Request, config *types.ServerConfig, logger *types.Logger) (any, error)
DelegateHandler is the handler for the delegated build API
func DigestPinned ¶ added in v0.17.3
DigestPinned returns image with the given digest appended, replacing any existing @digest suffix. For example:
("mycompany/jp-app:latest", "sha256:abc") -> "mycompany/jp-app:latest@sha256:abc"
("mycompany/jp-app@sha256:old", "sha256:new") -> "mycompany/jp-app@sha256:new"
("mycompany/jp-app:v1@sha256:old", "sha256:new") -> "mycompany/jp-app:v1@sha256:new"
("mycompany/jp-app", "sha256:abc") -> "mycompany/jp-app@sha256:abc"
Both Docker and Kubernetes accept "repo:tag@digest" references; when both are present the digest is authoritative. Returns image unchanged if either argument is empty.
func GenerateDockerConfigJSON ¶
func GenerateDockerConfigJSON(r *types.RegistryConfig) ([]byte, error)
func GetDockerConfig ¶
func ImageExists ¶
func KanikoJob ¶
func KanikoJob(ctx context.Context, logger *types.Logger, cs kubernetes.Interface, cfg *rest.Config, r *types.RegistryConfig, dockerCfgJSON []byte, kb KanikoBuild) error
func LookupContainerCommand ¶
func TrimLabelValue ¶ added in v0.16.0
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
func NewCommandCM ¶ added in v0.16.0
func (*CommandCM) BuildImage ¶ added in v0.16.0
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 (*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 (*CommandCM) ListOpenRunContainers ¶ added in v0.17.3
ListOpenRunContainers returns running containers with an OpenRun ownership label.
func (*CommandCM) RefreshImage ¶ added in v0.17.3
RefreshImage pulls the named image and returns its content-addressable digest. It first attempts to extract the manifest digest from RepoDigests (which is stable across container managers and matches the digest the registry advertises); it falls back to the image config digest (.Id) when the local image has no associated RepoDigests entry (e.g. it was built locally rather than pulled).
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 (*CommandCM) RunContainer ¶ added in v0.16.0
func (c *CommandCM) RunContainer(ctx context.Context, appEntry *types.AppEntry, sourceDir string, containerName ContainerName, imageName ImageName, port int32, envMap map[string]string, volumes []*VolumeInfo, containerOptions map[string]string, paramMap map[string]string, versionHash string, isImageSpec bool) 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 (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 {
Cpus string `mapstructure:"cpus"`
Memory string `mapstructure:"memory"`
Other map[string]any `mapstructure:",remain"`
}
func ParseCommandOptions ¶ added in v0.17.0
func ParseCommandOptions(containerCommand string, options map[string]string) (CommandOptions, error)
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)
// RefreshImage pulls (or HEADs) the named image from its registry and returns a
// stable content-addressable digest (e.g. "sha256:..."). Only used for
// image-spec apps so the container handler can detect when the upstream
// reference has moved and recreate the container with the new content.
RefreshImage(ctx context.Context, name ImageName) (digest string, err 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 int32, envMap map[string]string, volumes []*VolumeInfo,
containerOptions map[string]string, paramMap map[string]string, versionHash string, isImageSpec bool) 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
func WrapContainerManager ¶ added in v0.17.1
func WrapContainerManager(cm ContainerManager, kind string) ContainerManager
type ContainerName ¶
type ContainerName string
func GenContainerName ¶
func GenContainerName(appId types.AppId, cm ContainerManager, contentHash string, supportsInPlaceUpdate bool) ContainerName
type DelegateRequest ¶
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 ¶
func CheckImagesExists ¶
func CheckImagesExists(ctx context.Context, logger *types.Logger, imageRef string, registryConfig *types.RegistryConfig) (ExistsResult, error)
type KanikoBuild ¶
type KubernetesCM ¶ added in v0.16.0
func NewKubernetesCM ¶ added in v0.16.0
func (*KubernetesCM) BuildImage ¶ added in v0.16.0
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 (*KubernetesCM) RefreshImage ¶ added in v0.17.3
RefreshImage is a no-op on Kubernetes. Returning an empty digest leaves the existing identity hash and container lifecycle on Kubernetes unchanged.
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 int32, envMap map[string]string, volumes []*VolumeInfo, containerOptions map[string]string, paramMap map[string]string, versionHash string, isImageSpec bool) 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 VolumeName ¶
type VolumeName string
func GenVolumeName ¶
func GenVolumeName(appId types.AppId, dirName string) VolumeName