Documentation
¶
Overview ¶
Package agent runs gcpemu helper processes inside containers the emulator launches (GKE node metadata proxy, Cloud SQL server-side proxy). The emulator copies its own static binary into the container and starts it with GCPEMU_AGENT=<name>; Main dispatches to the registered agent.
Index ¶
Constants ¶
const BinaryEnv = "GCPEMU_AGENT_BINARY"
BinaryEnv overrides the binary copied into containers (tests set it to a CGO_ENABLED=0 build of ./cmd/gcpemu). See Resolver.
const ContainerPath = "/gcpemu/gcpemu"
ContainerPath is where the binary is placed inside containers.
const EnvVar = "GCPEMU_AGENT"
EnvVar selects the agent to run.
Variables ¶
var ImageRepos = []string{"ghcr.io/linuxuser586/gcpemu", "docker.io/linuxuser586/gcpemu"}
ImageRepos are the repositories of the published image, tried in order for a release build's binary (NFR-PORT-004). The release workflow tags vX.Y.Z as X.Y.Z.
Functions ¶
func BuildForTests ¶
BuildForTests compiles ./cmd/gcpemu for linux/arch with CGO_ENABLED=0 into dir (once per process) and sets GCPEMU_AGENT_BINARY. moduleRoot is the repository root; arch is the runtime's, or "" for the host's.
func Main ¶
func Main()
Main runs the selected agent and exits if GCPEMU_AGENT is set; otherwise it returns immediately. Call it first thing in main (and in TestMain of packages whose tests start agents in-process).
Types ¶
type Images ¶ added in v0.6.0
type Images interface {
// ImageFile pulls ref for platform ("linux/arm64") and returns the
// contents of file in it.
ImageFile(ctx context.Context, ref, platform, file string) ([]byte, error)
}
Images is the part of the container runtime Resolver copies a release build's binary out of the published image with.
type Resolver ¶ added in v0.6.0
type Resolver struct {
// Arch is the runtime's GOARCH; "" means the host's.
Arch string
// Version is the emulator's version (instance.Version).
Version string
// CacheDir holds binaries copied out of the published image; ""
// disables the cache and the pull.
CacheDir string
// Offline skips the pull.
Offline bool
// Images pulls the published image; nil skips the pull.
Images Images
// contains filtered or unexported fields
}
Resolver finds a static linux gcpemu binary for the container runtime's architecture, to copy into Managed containers (ADR 0005). The host's own executable is used when the host is linux on that architecture. Otherwise the binary is, in order: $GCPEMU_AGENT_BINARY; a sibling gcpemu-linux-<arch> next to the executable; the cache at <CacheDir>/<Version>/linux-<arch>/gcpemu; and, for a release build (Version exactly vX.Y.Z), the one in the published image X.Y.Z, which is then cached.