Documentation
¶
Overview ¶
Package gcpcloudbuild emulates Google Cloud Build: the v1 API (builds, build triggers and worker pools) over gRPC and REST. Build steps run as containers with a shared /workspace; see PARITY.md.
Index ¶
- Constants
- Variables
- type API
- type ConfigProvider
- type Handler
- func (h *Handler) API() *API
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) ApproveBuild(in *cloudbuildpb.ApproveBuildRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) CancelBuild(in *cloudbuildpb.CancelBuildRequest) (*cloudbuildpb.Build, error)
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) CreateBuild(in *cloudbuildpb.CreateBuildRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) CreateBuildTrigger(in *cloudbuildpb.CreateBuildTriggerRequest) (*cloudbuildpb.BuildTrigger, error)
- func (b *InMemoryBackend) CreateWorkerPool(in *cloudbuildpb.CreateWorkerPoolRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteBuildTrigger(in *cloudbuildpb.DeleteBuildTriggerRequest) error
- func (b *InMemoryBackend) DeleteWorkerPool(in *cloudbuildpb.DeleteWorkerPoolRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DisableEngine(reason string)
- func (b *InMemoryBackend) GetBuild(in *cloudbuildpb.GetBuildRequest) (*cloudbuildpb.Build, error)
- func (b *InMemoryBackend) GetBuildTrigger(in *cloudbuildpb.GetBuildTriggerRequest) (*cloudbuildpb.BuildTrigger, error)
- func (b *InMemoryBackend) GetWorkerPool(name string) (*cloudbuildpb.WorkerPool, error)
- func (b *InMemoryBackend) HandlePubsubMessage(topic string, data []byte, attrs map[string]string, id string, ...)
- func (b *InMemoryBackend) ListBuildTriggers(in *cloudbuildpb.ListBuildTriggersRequest) ([]*cloudbuildpb.BuildTrigger, string, error)
- func (b *InMemoryBackend) ListBuilds(in *cloudbuildpb.ListBuildsRequest) ([]*cloudbuildpb.Build, string, error)
- func (b *InMemoryBackend) ListWorkerPools(in *cloudbuildpb.ListWorkerPoolsRequest) ([]*cloudbuildpb.WorkerPool, string, error)
- func (b *InMemoryBackend) ReceiveTriggerWebhook(in *cloudbuildpb.ReceiveTriggerWebhookRequest) error
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) RetryBuild(in *cloudbuildpb.RetryBuildRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) RunBuildTrigger(in *cloudbuildpb.RunBuildTriggerRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) SetClock(now func() time.Time, after timerFunc)
- func (b *InMemoryBackend) SetContext(ctx context.Context)
- func (b *InMemoryBackend) SetRuntime(rt Runtime)
- func (b *InMemoryBackend) SetServices(s Services)
- func (b *InMemoryBackend) SetWorkDir(dir string)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) UpdateBuildTrigger(in *cloudbuildpb.UpdateBuildTriggerRequest) (*cloudbuildpb.BuildTrigger, error)
- func (b *InMemoryBackend) UpdateWorkerPool(in *cloudbuildpb.UpdateWorkerPoolRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) Wait()
- type ObjectStore
- type Provider
- type Publisher
- type Runtime
- type SecretResolver
- type Services
- type Settings
Constants ¶
const ( // DefaultPort is the dedicated gRPC and REST listener's default TCP port. DefaultPort = 8136 // EngineAuto runs build steps as containers when a container runtime is reachable. EngineAuto = "auto" // EngineNone never runs a container: builds are recorded and then fail with a clear status detail. EngineNone = "none" )
const (
// DefaultGitImage is the image git fetches run in when Services.GitImage is empty.
DefaultGitImage = "alpine/git:latest"
)
Variables ¶
var ErrNilAppContext = errors.New("gcpcloudbuild: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
cloudbuildpb.CloudBuildServer
// contains filtered or unexported fields
}
API exposes the Cloud Build service plus stored build logs for in-process callers (dashboard proxy).
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPCloudBuildSettings() Settings
}
ConfigProvider extracts Cloud Build configuration from the AppContext Config.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
// contains filtered or unexported fields
}
Handler serves Cloud Build on a dedicated listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported gRPC methods.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler; the real API is on the dedicated port.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Cloud Build runs on its own listener.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds builds, triggers and worker pools under one lock and runs builds as containers.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend with no container runtime.
func (*InMemoryBackend) ApproveBuild ¶
func (b *InMemoryBackend) ApproveBuild( in *cloudbuildpb.ApproveBuildRequest, ) (*longrunningpb.Operation, error)
ApproveBuild records an approval decision on a build that awaits one.
func (*InMemoryBackend) CancelBuild ¶
func (b *InMemoryBackend) CancelBuild( in *cloudbuildpb.CancelBuildRequest, ) (*cloudbuildpb.Build, error)
CancelBuild cancels a queued, pending or running build.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close cancels running builds and waits for them to exit.
func (*InMemoryBackend) CreateBuild ¶
func (b *InMemoryBackend) CreateBuild( in *cloudbuildpb.CreateBuildRequest, ) (*longrunningpb.Operation, error)
CreateBuild queues a build.
func (*InMemoryBackend) CreateBuildTrigger ¶
func (b *InMemoryBackend) CreateBuildTrigger( in *cloudbuildpb.CreateBuildTriggerRequest, ) (*cloudbuildpb.BuildTrigger, error)
CreateBuildTrigger stores a trigger.
func (*InMemoryBackend) CreateWorkerPool ¶
func (b *InMemoryBackend) CreateWorkerPool( in *cloudbuildpb.CreateWorkerPoolRequest, ) (*longrunningpb.Operation, error)
CreateWorkerPool stores a worker pool; the pool is RUNNING when the operation completes.
func (*InMemoryBackend) DeleteBuildTrigger ¶
func (b *InMemoryBackend) DeleteBuildTrigger(in *cloudbuildpb.DeleteBuildTriggerRequest) error
DeleteBuildTrigger removes a trigger.
func (*InMemoryBackend) DeleteWorkerPool ¶
func (b *InMemoryBackend) DeleteWorkerPool( in *cloudbuildpb.DeleteWorkerPoolRequest, ) (*longrunningpb.Operation, error)
DeleteWorkerPool removes a worker pool; a stale etag aborts the call.
func (*InMemoryBackend) DisableEngine ¶
func (b *InMemoryBackend) DisableEngine(reason string)
DisableEngine records why builds cannot run; builds then fail with this status detail.
func (*InMemoryBackend) GetBuild ¶
func (b *InMemoryBackend) GetBuild(in *cloudbuildpb.GetBuildRequest) (*cloudbuildpb.Build, error)
GetBuild returns a build by name or by project_id and id.
func (*InMemoryBackend) GetBuildTrigger ¶
func (b *InMemoryBackend) GetBuildTrigger( in *cloudbuildpb.GetBuildTriggerRequest, ) (*cloudbuildpb.BuildTrigger, error)
GetBuildTrigger returns a trigger by name or by project_id and trigger_id.
func (*InMemoryBackend) GetWorkerPool ¶
func (b *InMemoryBackend) GetWorkerPool(name string) (*cloudbuildpb.WorkerPool, error)
GetWorkerPool returns a worker pool.
func (*InMemoryBackend) HandlePubsubMessage ¶
func (b *InMemoryBackend) HandlePubsubMessage( topic string, data []byte, attrs map[string]string, id string, published time.Time, )
HandlePubsubMessage starts a build for every enabled pubsub_config trigger subscribed to topic ("projects/p/topics/t"). The trigger's $(body...) bindings see the message as Pub/Sub delivers it to a push endpoint: {"message": {"data": <base64>, "attributes": {...}, "messageId", "publishTime"}, "subscription"}.
func (*InMemoryBackend) ListBuildTriggers ¶
func (b *InMemoryBackend) ListBuildTriggers( in *cloudbuildpb.ListBuildTriggersRequest, ) ([]*cloudbuildpb.BuildTrigger, string, error)
ListBuildTriggers lists the triggers of a project and location ordered by creation time.
func (*InMemoryBackend) ListBuilds ¶
func (b *InMemoryBackend) ListBuilds( in *cloudbuildpb.ListBuildsRequest, ) ([]*cloudbuildpb.Build, string, error)
ListBuilds lists builds of a project and location, newest first.
func (*InMemoryBackend) ListWorkerPools ¶
func (b *InMemoryBackend) ListWorkerPools( in *cloudbuildpb.ListWorkerPoolsRequest, ) ([]*cloudbuildpb.WorkerPool, string, error)
ListWorkerPools lists the worker pools of a location ordered by name.
func (*InMemoryBackend) ReceiveTriggerWebhook ¶
func (b *InMemoryBackend) ReceiveTriggerWebhook( in *cloudbuildpb.ReceiveTriggerWebhookRequest, ) error
ReceiveTriggerWebhook runs a webhook trigger after checking the URL secret.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset cancels running builds and drops all state.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot. Builds that were queued or running when it was taken ended with the old process and are marked INTERNAL_ERROR.
func (*InMemoryBackend) RetryBuild ¶
func (b *InMemoryBackend) RetryBuild( in *cloudbuildpb.RetryBuildRequest, ) (*longrunningpb.Operation, error)
RetryBuild queues a new build from the request that created the original.
func (*InMemoryBackend) RunBuildTrigger ¶
func (b *InMemoryBackend) RunBuildTrigger( in *cloudbuildpb.RunBuildTriggerRequest, ) (*longrunningpb.Operation, error)
RunBuildTrigger queues a build from a trigger's inline build template.
func (*InMemoryBackend) SetClock ¶
func (b *InMemoryBackend) SetClock(now func() time.Time, after timerFunc)
SetClock replaces the wall clock and the timeout timer, for tests.
func (*InMemoryBackend) SetContext ¶
func (b *InMemoryBackend) SetContext(ctx context.Context)
SetContext bounds the lifetime of build goroutines.
func (*InMemoryBackend) SetRuntime ¶
func (b *InMemoryBackend) SetRuntime(rt Runtime)
SetRuntime enables execution of build steps on rt.
func (*InMemoryBackend) SetServices ¶
func (b *InMemoryBackend) SetServices(s Services)
SetServices wires the Cloud Storage, Pub/Sub, Logging, Secret Manager and Artifact Registry seams.
func (*InMemoryBackend) SetWorkDir ¶
func (b *InMemoryBackend) SetWorkDir(dir string)
SetWorkDir sets the host directory build workspaces are created under.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises builds, triggers, worker pools and operations. Workspaces and containers of running builds are not part of it.
func (*InMemoryBackend) UpdateBuildTrigger ¶
func (b *InMemoryBackend) UpdateBuildTrigger( in *cloudbuildpb.UpdateBuildTriggerRequest, ) (*cloudbuildpb.BuildTrigger, error)
UpdateBuildTrigger replaces a trigger, or only the masked fields when update_mask is set.
func (*InMemoryBackend) UpdateWorkerPool ¶
func (b *InMemoryBackend) UpdateWorkerPool( in *cloudbuildpb.UpdateWorkerPoolRequest, ) (*longrunningpb.Operation, error)
UpdateWorkerPool applies the masked fields (all mutable fields when no mask is given).
func (*InMemoryBackend) Wait ¶
func (b *InMemoryBackend) Wait()
Wait blocks until every running build goroutine has exited.
type ObjectStore ¶
type ObjectStore interface {
ReadObject(bucket, object string) ([]byte, error)
WriteObject(bucket, object string, data []byte, contentType string) error
// EnsureBucket creates bucket under project when it does not exist.
EnsureBucket(project, bucket string) error
}
ObjectStore reads and writes Cloud Storage objects in the emulator.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Google Cloud Build. It serves gRPC and REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type Publisher ¶
type Publisher interface {
Publish(project, topic string, data []byte, attrs map[string]string) error
}
Publisher publishes a message to a Pub/Sub topic of a project, creating the topic when missing.
type Runtime ¶
type Runtime interface {
CreateAndStart(ctx context.Context, spec container.Spec) (string, error)
StopAndRemove(ctx context.Context, containerID string) error
}
Runtime is the slice of the container runtime a build needs. The runtime must also implement container.ExitWaiter; it should implement container.LogStreamer (step output) and container.ImagePusher (images:).
type SecretResolver ¶
SecretResolver reads a Secret Manager secret version ("projects/p/secrets/s/versions/v").
type Services ¶
type Services struct {
Store ObjectStore
Pub Publisher
Secrets SecretResolver
Logs gcpserve.LogSink
// RegistryAddr is the Artifact Registry emulator's host:port as the docker daemon reaches it.
RegistryAddr string
// GitImage runs git for gitSource and repoSource; empty uses DefaultGitImage.
GitImage string
// RepoBase is the base URL (http, https or file) repoSource repo_names resolve under as
// <RepoBase>/<project>/<repo>; empty uses Cloud Source Repositories' address.
RepoBase string
}
Services are the emulator backends a build reads from and writes to.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 225-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 199-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPCloudBuild.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
Source Files
¶
- backend.go
- bindings.go
- buildlog.go
- builds.go
- celfilter.go
- dynsubst.go
- errors.go
- filter.go
- gitsource.go
- grpc.go
- handler.go
- inproc.go
- lifecycle.go
- mask.go
- names.go
- ops.go
- persistence.go
- pools.go
- provider.go
- publish.go
- pubsubtrigger.go
- run.go
- runtime.go
- secrets.go
- settings.go
- source.go
- step.go
- steps.go
- subst.go
- triggers.go
- validate.go