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
- Variables
- func NewArtifact(logger *zerolog.Logger, cfg *config.Service) artifact.Service
- func NewDevbuild(logger *zerolog.Logger, cfg *config.Service, registerer prometheus.Registerer) devbuild.Service
- func NewGitHubClient(token string) *github.Client
- func NewGitHubClientWithConfig(cfg config.Github) *github.Client
- func NewHotfix(logger *zerolog.Logger, ghClient *github.Client, cfg *config.Service) hotfix.Service
- func NewLarkCardJSON(infos *NotificationInfo) (string, error)
- func NewLarkCardWithGoTemplate(infos *NotificationInfo) (map[string]any, error)
- func NewPublish(logger *zerolog.Logger, cfg *config.Service) publish.Service
- func NewTidbcloud(logger *zerolog.Logger, cfg *config.Service, ...) tidbcloud.Service
- func PipelineStatusEmoji(status string) string
- func StatusColor(status string) string
- func StatusEmoji(status string) string
- func ValidatePublishTargets(cfg *config.Service) error
- type AlertNotifier
- type BinaryInfo
- type ImageCopyPayload
- type ImageInfo
- type LarkNotifier
- func (n *LarkNotifier) Disable()
- func (n *LarkNotifier) HasRecipients() bool
- func (n *LarkNotifier) Notify(ctx context.Context, build *ent.DevBuild) (*schema.NotificationState, error)
- func (n *LarkNotifier) Reload(appID, appSecret string, channels []config.LarkChannel)
- func (n *LarkNotifier) SendAlert(ctx context.Context, title, body string) error
- type NotificationInfo
- type Notifier
- type OpsComponent
- type OpsConfig
- type OpsKernelImageSyncRequest
- type OpsKernelImageSyncRequestImage
- type OpsStageConfig
- type OpsUpdateComponentRequest
- type OpsUpdateComponentResponse
- type PipelineRunInfo
- type TCMSConfig
- type TagMetadata
- type TagMetadataResolver
- type TestPlatformsConfig
- type TiUPStepPayload
- type Worker
Constants ¶
const ( TaskStatusPending = "PENDING" TaskStatusProcessing = "PROCESSING" TaskStatusSucceeded = "SUCCEEDED" TaskStatusFailed = "FAILED" )
Task statuses of an image sync task.
const ( // Platforms MultiArch = "multi-arch" LinuxAmd64 = "linux/amd64" LinuxArm64 = "linux/arm64" DarwinAmd64 = "darwin/amd64" DarwinArm64 = "darwin/arm64" )
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.
const ( PublishStepStateBlocked = "blocked" PublishStepStatePending = "pending" PublishStepStateClaimed = "claimed" PublishStepStateSucceeded = "succeeded" PublishStepStateFailed = "failed" PublishStepStateSkipped = "skipped" )
Publication step states.
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.
const PublishKindTiUP = "tiup"
PublishKindTiUP publishes TiUP packages to the staging and prod mirrors.
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 ¶
var ErrLaneBusy = errors.New("publish lane busy")
ErrLaneBusy means another unit holds the lane; the step must be requeued instead of failed.
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.
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.
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 ¶
NewArtifact returns the artifact service implementation.
func NewDevbuild ¶
func NewDevbuild(logger *zerolog.Logger, cfg *config.Service, registerer prometheus.Registerer) devbuild.Service
func NewGitHubClient ¶
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 ¶
NewGitHubClientWithConfig creates a GitHub client that prefers repository-scoped tokens from the broker and falls back to the static token.
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 ¶
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 ¶
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 ¶
StatusColor returns the Lark card header template color for a status.
func StatusEmoji ¶
StatusEmoji returns an emoji for the build status.
func ValidatePublishTargets ¶
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 ¶
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 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 ¶
func (n *LarkNotifier) Notify(ctx context.Context, build *ent.DevBuild) (*schema.NotificationState, error)
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.
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 ¶
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).
Source Files
¶
- artifact.go
- artifact_alert_lease.go
- artifact_alert_reclaim.go
- artifact_alerts.go
- artifact_lease.go
- artifact_metrics.go
- artifact_target_guard.go
- artifact_worker.go
- builder_image.go
- devbuild.go
- devbuild_allowlist.go
- devbuild_create.go
- devbuild_github.go
- devbuild_jenkins.go
- devbuild_reload.go
- devbuild_tekton.go
- devbuild_transform.go
- doc.go
- hotfix.go
- hotfix_tidbx.go
- lark_card.go
- lark_client.go
- lark_template.go
- notification.go
- notifier.go
- ops_ids.go
- product_capabilities.go
- profile.go
- publish.go
- publish_desired.go
- publish_lane.go
- publish_lane_helpers.go
- publish_nightly_failures.go
- publish_nightly_metrics.go
- publish_nightly_verify.go
- publish_plan.go
- publish_resume.go
- publish_source.go
- publish_supersede.go
- publish_targets.go
- publish_tiup.go
- publish_worker.go
- store_schema.go
- tekton_cloudevent.go
- tekton_reconciler.go
- tidbcloud.go
- tidbcloud_kernel_image.go
- tidbcloud_ops.go
- tidbcloud_tcms.go
- tiup_service.go