impl

package
v0.0.0-...-27b9d4b Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 83 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package impl implements the tibuild-v2 service endpoints, including the broker-backed GitHub client used for repository lookups and hotfix tags.

Index

Constants

View Source
const (
	TaskStatusPending    = "PENDING"
	TaskStatusProcessing = "PROCESSING"
	TaskStatusSucceeded  = "SUCCEEDED"
	TaskStatusFailed     = "FAILED"
)

Task statuses of an image sync task.

View Source
const (

	// Platforms
	MultiArch   = "multi-arch"
	LinuxAmd64  = "linux/amd64"
	LinuxArm64  = "linux/arm64"
	DarwinAmd64 = "darwin/amd64"
	DarwinArm64 = "darwin/arm64"
)
View Source
const (
	PublishStateQueued    = "queued"
	PublishStateRunning   = "running"
	PublishStateSucceeded = "succeeded"
	// PublishStatePartial means some targets succeeded and some failed: the
	// unit needs an operator decision, not an automatic retry.
	PublishStatePartial  = "partial"
	PublishStateFailed   = "failed"
	PublishStateCanceled = "canceled"
)

Publication unit states. A unit is the aggregate of its steps.

View Source
const (
	PublishStepStateBlocked   = "blocked"
	PublishStepStatePending   = "pending"
	PublishStepStateClaimed   = "claimed"
	PublishStepStateSucceeded = "succeeded"
	PublishStepStateFailed    = "failed"
	PublishStepStateSkipped   = "skipped"
)

Publication step states.

View Source
const (
	// PublishKindImageCopy copies one source digest into N destination
	// repositories. Targets are independent and run in parallel.
	PublishKindImageCopy = "image_copy"
)

Publication kinds and their step payloads.

View Source
const PublishKindTiUP = "tiup"

PublishKindTiUP publishes TiUP packages to the staging and prod mirrors.

View Source
const (
	PublishLaneTiUP = "tiup"
)

Lane names. A lane serializes publication intents of one kind: two TiUP mirrors must never be published concurrently, and a unit's steps must not interleave with another unit's steps, so the TiUP kind owns exactly one lane.

Variables

View Source
var ErrLaneBusy = errors.New("publish lane busy")

ErrLaneBusy means another unit holds the lane; the step must be requeued instead of failed.

View Source
var ErrLostLane = errors.New("publish lane lost")

ErrLostLane means the worker no longer owns the publish lane, so it must not touch the mirror or write a result.

View Source
var ErrNothingToPublish = errors.New("no delivery rule matches the image reference")

ErrNothingToPublish means the rules file has no destination for the reference: the request is a successful no-op, exactly like the legacy generator writing no script.

View Source
var ErrPublishRulesUnavailable = errors.New("delivery rules are not available")

ErrPublishRulesUnavailable means the delivery rules are not readable yet, so the target catalogue cannot be checked. The deployment mounts the file with Flux, which may land after the process starts.

Functions

func NewArtifact

func NewArtifact(logger *zerolog.Logger, cfg *config.Service) artifact.Service

NewArtifact returns the artifact service implementation.

func NewDevbuild

func NewDevbuild(logger *zerolog.Logger, cfg *config.Service, registerer prometheus.Registerer) devbuild.Service

func NewGitHubClient

func NewGitHubClient(token string) *github.Client

NewGitHubClient creates a new GitHub client with the provided static token. It is kept for callers that do not have a full config object.

func NewGitHubClientWithConfig

func NewGitHubClientWithConfig(cfg config.Github) *github.Client

NewGitHubClientWithConfig creates a GitHub client that prefers repository-scoped tokens from the broker and falls back to the static token.

func NewHotfix

func NewHotfix(logger *zerolog.Logger, ghClient *github.Client, cfg *config.Service) hotfix.Service

NewHotfix returns the hotfix service implementation.

func NewLarkCardJSON

func NewLarkCardJSON(infos *NotificationInfo) (string, error)

NewLarkCardJSON builds a Lark Card JSON 2.0 message.

func NewLarkCardWithGoTemplate

func NewLarkCardWithGoTemplate(infos *NotificationInfo) (map[string]any, error)

NewLarkCardWithGoTemplate renders the English notification template. Go supplies artifact data and escaping helpers.

func NewPublish

func NewPublish(logger *zerolog.Logger, cfg *config.Service) publish.Service

NewPublish returns the publish service implementation.

func NewTidbcloud

func NewTidbcloud(logger *zerolog.Logger, cfg *config.Service, resolveTagMetadata TagMetadataResolver) tidbcloud.Service

NewTidbcloud returns the tidbcloud service implementation.

func PipelineStatusEmoji

func PipelineStatusEmoji(status string) string

PipelineStatusEmoji returns an emoji for a PipelineRun status. Uses Tekton's own condition Reason/Status values so users can distinguish between Failed, Cancelled, TimedOut, Skipped, etc. at a glance.

func StatusColor

func StatusColor(status string) string

StatusColor returns the Lark card header template color for a status.

func StatusEmoji

func StatusEmoji(status string) string

StatusEmoji returns an emoji for the build status.

func ValidatePublishTargets

func ValidatePublishTargets(cfg *config.Service) error

ValidatePublishTargets checks that every target the publish worker claims exists in the delivery rules, and fails fast otherwise: a typo would leave those steps pending forever, which looks like a stuck queue instead of a configuration error.

Types

type AlertNotifier

type AlertNotifier interface {
	SendAlert(ctx context.Context, title, body string) error
}

AlertNotifier sends a plain-text operational alert. LarkNotifier implements it, reusing the configured Lark app and channels.

type BinaryInfo

type BinaryInfo struct {
	OciReference    string
	Platform        string
	FileName        string
	URL             string
	Sha256URL       string
	Sha256Reference string
}

BinaryInfo contains information about a binary artifact for notification.

type ImageCopyPayload

type ImageCopyPayload struct {
	// Source is the repository pinned to the planned digest, e.g.
	// us-docker.pkg.dev/project/hub/pingcap/ticdc/image@sha256:...
	Source string `json:"source"`
	// Digest is the pinned digest, kept separate for readability.
	Digest string `json:"digest"`
	// Dest is the destination repository.
	Dest string `json:"dest"`
	// Tags are the tags to write on Dest; the first one is the source tag.
	Tags []string `json:"tags"`
}

ImageCopyPayload is the payload of a kind=image_copy step. It is complete: any worker with the credentials of Target can replay it without consulting the planner again.

type ImageInfo

type ImageInfo struct {
	Platform string
	URL      string
}

ImageInfo contains information about a Docker image artifact for notification.

type LarkNotifier

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

LarkNotifier sends Lark IM messages for each configured channel. Each channel's first send creates a card; subsequent updates refresh it in place.

func NewLarkNotifier

func NewLarkNotifier(appID, appSecret string, channels []config.LarkChannel, logger *zerolog.Logger) *LarkNotifier

NewLarkNotifier creates a new LarkNotifier with Lark app credentials and optional channels.

func (*LarkNotifier) Disable

func (n *LarkNotifier) Disable()

Disable clears the Lark client, effectively disabling notifications.

func (*LarkNotifier) HasRecipients

func (n *LarkNotifier) HasRecipients() bool

HasRecipients reports whether at least one Lark channel is configured. A worker that cannot deliver must not compete for the alert lease, otherwise a cluster without channels could hold the lease and silence the whole fleet.

func (*LarkNotifier) Notify

Notify delivers or updates cards for all channels and returns the updated state.

func (*LarkNotifier) Reload

func (n *LarkNotifier) Reload(appID, appSecret string, channels []config.LarkChannel)

Reload updates credentials and channels at runtime.

func (*LarkNotifier) SendAlert

func (n *LarkNotifier) SendAlert(ctx context.Context, title, body string) error

SendAlert sends a plain-text alert to every configured Lark channel.

type NotificationInfo

type NotificationInfo struct {
	ImageSyncURL string // Configured image sync form URL; empty disables shortcuts.
	BuildID      int
	Product      string
	Edition      string
	Version      string
	IsHotfix     bool
	Status       string
	CreatedBy    string
	CreatedAt    string // RFC3339 formatted build creation time
	CompletedAt  string // RFC3339 formatted build completion time, empty if still running
	GitRef       string // e.g. "branch/master", "tag/v9.0.0", "pull/1234", or commit SHA
	GithubRepo   string
	Platform     string
	ErrMsg       string
	PipelineRuns []PipelineRunInfo
	// Build report fields (populated on success)
	GitSha   string
	Images   []ImageInfo
	Binaries []BinaryInfo
}

NotificationInfo contains information for building a notification card.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, build *ent.DevBuild) (*schema.NotificationState, error)
}

Notifier defines the interface for sending build notifications. Returns the updated notification state for persistence.

type OpsComponent

type OpsComponent struct {
	BaseImage   string `json:"base_image" yaml:"base_image"`
	ClusterType string `json:"cluster_type" yaml:"cluster_type"`
	GitHubRepo  string `json:"github_repo" yaml:"github_repo"`
}

OpsComponent maps an image repository to a TiDB Cloud component.

type OpsConfig

type OpsConfig struct {
	Stages map[string]OpsStageConfig `json:"stages" yaml:"stages"`
}

OpsConfig is the ops platform configuration (per stage).

type OpsKernelImageSyncRequest

type OpsKernelImageSyncRequest struct {
	SourceApplicant   string                           `json:"source_applicant"`
	SourceReleaseID   string                           `json:"source_release_id,omitempty"`
	SourceChangeID    string                           `json:"source_change_id,omitempty"`
	SourceStepKey     string                           `json:"source_step_key,omitempty"`
	SourceExecutionID string                           `json:"source_execution_id,omitempty"`
	Repo              string                           `json:"repo"`
	Branch            string                           `json:"branch,omitempty"`
	CommitSHA         string                           `json:"commit_sha"`
	GitTag            string                           `json:"git_tag,omitempty"`
	Images            []OpsKernelImageSyncRequestImage `json:"images"`
}

OpsKernelImageSyncRequest is the ops kernel image build callback body.

type OpsKernelImageSyncRequestImage

type OpsKernelImageSyncRequestImage struct {
	SourceRepository string `json:"source_repository"`
	SourceTag        string `json:"source_tag"`
}

OpsKernelImageSyncRequestImage is one source image in the callback body.

type OpsStageConfig

type OpsStageConfig struct {
	APIBaseURL string                  `json:"api_base_url" yaml:"api_base_url"`
	APIKey     string                  `json:"api_key" yaml:"api_key"`
	Components map[string]OpsComponent `json:"components" yaml:"components"`
}

OpsStageConfig is one ops environment.

type OpsUpdateComponentRequest

type OpsUpdateComponentRequest struct {
	ClusterType string `json:"cluster_type"`
	Version     string `json:"version"`
	BaseImage   string `json:"base_image"`
	Tag         string `json:"tag"`
	Policy      string `json:"policy"`
	Author      string `json:"author,omitempty"`
	ReleaseID   string `json:"release_id,omitempty"`
	ChangeID    string `json:"change_id,omitempty"`
	StepKey     string `json:"step_key,omitempty"`
	ExecutionID string `json:"execution_id,omitempty"`
}

OpsUpdateComponentRequest is the body of the ops component update.

type OpsUpdateComponentResponse

type OpsUpdateComponentResponse struct {
	InstanceID int `json:"instance_id"`
}

OpsUpdateComponentResponse is the ops response with the ticket id.

type PipelineRunInfo

type PipelineRunInfo struct {
	Name   string
	Status string
	URL    string
}

PipelineRunInfo contains information about a single pipeline run.

type TCMSConfig

type TCMSConfig struct {
	APIBaseURL string `json:"api_base_url" yaml:"api_base_url"`
	AuthToken  string `json:"auth_token" yaml:"auth_token"`
}

TCMSConfig is the TCMS API configuration.

type TagMetadata

type TagMetadata struct {
	Author      string
	ReleaseID   string
	ChangeID    string
	StepKey     string
	ExecutionID string
}

TagMetadata is the author and ops request ids attached to a tidbx git tag. Every ops id is optional, so any of them may be empty.

type TagMetadataResolver

type TagMetadataResolver func(ctx context.Context, repo, tag string) (*TagMetadata, error)

TagMetadataResolver resolves a tag's metadata. TiBuild queries its own hotfix service in process, so the integration does not call back over HTTP.

type TestPlatformsConfig

type TestPlatformsConfig struct {
	TCMS TCMSConfig `json:"tcms" yaml:"tcms"`
}

TestPlatformsConfig is the TCMS configuration.

type TiUPStepPayload

type TiUPStepPayload struct {
	// Mirror is the bare mirror name: staging or prod.
	Mirror string `json:"mirror"`
	// MirrorURL is the base URL of that mirror at planning time.
	MirrorURL string `json:"mirror_url"`
	// ArtifactURL is the OCI reference the packages come from.
	ArtifactURL string `json:"artifact_url,omitempty"`
	// SourceType is "http" when the package comes from a direct URL instead of
	// an OCI artifact (the legacy request-to-publish-single path).
	SourceType string `json:"source_type,omitempty"`
	// SourceURL is the tarball URL for a http source.
	SourceURL string `json:"source_url,omitempty"`
	// Digest pins the artifact manifest, so a moved tag cannot change what is
	// published.
	Digest string `json:"digest"`
	// FileDigest is the sha256 of this package's own file (the OCI layer the
	// mirror stores as the tarball). The mirror records the same value in its
	// component manifest, so it is the identity used to verify that a nightly
	// build actually reached the mirror; the nightly version string cannot do
	// that because it is constant per channel.
	FileDigest string `json:"file_digest,omitempty"`
	// ArtifactCreatedAt is the build time from the OCI manifest annotation
	// org.opencontainers.image.created. It orders queued units of the same
	// channel; it is zero for manual/HTTP sources.
	ArtifactCreatedAt time.Time `json:"artifact_created_at,omitempty"`
	// Nightly marks the nightly channel: its version is a constant, so a new
	// build is expected to replace the previous package of the same version.
	Nightly bool `json:"nightly,omitempty"`
	// NightlyVersion is the version this row asked for. It is recorded when a
	// desired row is published, so the completion callback records the version
	// that was actually published even if a newer push replaced desired_version
	// while the unit was running.
	NightlyVersion string                 `json:"nightly_version,omitempty"`
	Packages       []delivery.TiUPPackage `json:"packages"`
}

TiUPStepPayload is the complete payload of a kind=tiup step. Any worker with the mirror credentials and the artifact reader can replay it.

type Worker

type Worker interface {
	Start(context.Context)
	Stop()
	MetricsHandler() http.Handler
	MetricsGatherer() prometheus.Gatherer
	// Reload applies a validated configuration revision to the running worker.
	Reload(*config.Service)
}

Worker is the background execution surface of the artifact service. It is implemented by artifactsrvc and shared by cmd/tibuild (in-process) and cmd/tibuild-worker (standalone).

func NewWorker

func NewWorker(logger *zerolog.Logger, cfg *config.Service) (Worker, error)

NewWorker builds the standalone background executor. The image sync queue and the publish step executor share one process and one set of per-target registry credentials.

Jump to

Keyboard shortcuts

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