model

package
v0.0.0-...-6b6719a Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuildScheduled  = "scheduled"
	BuildRunning    = "running"
	BuildSuccessful = "successful"
	BuildFailed     = "failed"
	BuildCanceled   = "canceled"
)
View Source
const (
	WorkerIdle        = "idle"
	WorkerUsed        = "used"
	WorkerUnreachable = "unreachable"
)
View Source
const (
	WorkerMin      = "min"
	WorkerBalanced = "balance"
	WorkerMax      = "max"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Build

type Build struct {
	Number       uint           `json:"number"          gorm:"primaryKey;uniqueIndex:idx_builds"`
	PipelineName string         `json:"pipeline_name"   gorm:"primaryKey;uniqueIndex:idx_builds"`
	ProjectName  string         `json:"project_name"    gorm:"primaryKey;uniqueIndex:idx_builds"`
	Status       string         `json:"status"          gorm:"default:scheduled"`
	Steps        []BuildStep    `json:"steps,omitempty" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:BuildNumber,PipelineName,ProjectName"`
	WorkerName   sql.NullString `json:"worker_name"`
	CreatedAt    time.Time      `json:"created_at"      gorm:"default:now()"`
	UpdatedAt    time.Time      `json:"updated_at"      gorm:"default:now()"`
}

func BuildFromID

func BuildFromID(buildID string) Build

func (*Build) AfterCreate

func (m *Build) AfterCreate(tx *gorm.DB) error

func (*Build) AppendLog

func (m *Build) AppendLog(log BuildLog)

func (*Build) AppendOutput

func (m *Build) AppendOutput(output string)

func (*Build) BeforeCreate

func (m *Build) BeforeCreate(tx *gorm.DB) error

func (*Build) BeforeUpdate

func (m *Build) BeforeUpdate(tx *gorm.DB) error

func (*Build) End

func (m *Build) End()

func (Build) ID

func (m Build) ID() string

type BuildLog

type BuildLog struct {
	Command string `json:"command"`
	Idx     int    `json:"idx,omitempty"`
	Total   int    `json:"total,omitempty"`
	Output  string `json:"output"`
}

type BuildShort

type BuildShort struct {
	Number     uint           `json:"number"`
	Status     string         `json:"status"`
	WorkerName sql.NullString `json:"worker_name,omitempty"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
}

type BuildStep

type BuildStep struct {
	Name         string     `json:"name"           gorm:"primaryKey;uniqueIndex:idx_build_steps"`
	BuildNumber  uint       `json:"-"              gorm:"primaryKey;uniqueIndex:idx_build_steps"`
	PipelineName string     `json:"-"              gorm:"primaryKey;uniqueIndex:idx_build_steps"`
	ProjectName  string     `json:"-"              gorm:"primaryKey;uniqueIndex:idx_build_steps"`
	Start        time.Time  `json:"start"`
	Duration     string     `json:"duration"       gorm:"not null"`
	Logs         []BuildLog `json:"logs,omitempty" gorm:"serializer:json"`
	CreatedAt    time.Time  `json:"created_at"     gorm:"default:now()"`
	UpdatedAt    time.Time  `json:"updated_at"     gorm:"default:now()"`
}

func (*BuildStep) AppendLog

func (step *BuildStep) AppendLog(log BuildLog)

func (*BuildStep) AppendOutput

func (step *BuildStep) AppendOutput(output string)

func (*BuildStep) End

func (step *BuildStep) End()

type Pipeline

type Pipeline struct {
	Name        string         `json:"name"                gorm:"primaryKey;uniqueIndex:idx_pipelines"`
	ProjectName string         `json:"-"                   gorm:"primaryKey;uniqueIndex:idx_pipelines"`
	Branch      string         `json:"branch"              gorm:"not null"`
	Config      PipelineConfig `json:"config"              gorm:"serializer:json;not null"`
	Variables   []Variable     `json:"variables,omitempty" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:PipelineName,ProjectName"`
	Secrets     []Secret       `json:"secrets,omitempty"   gorm:"foreignKey:PipelineName,ProjectName"`
	Builds      []Build        `json:"builds,omitempty"    gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:PipelineName,ProjectName"`
	CreatedAt   time.Time      `json:"created_at"          gorm:"default:now()"`
	UpdatedAt   time.Time      `json:"updated_at"          gorm:"default:now()"`
}

TODO: cascading delete (secrets, issue: https://github.com/go-gorm/gorm/issues/5001)

func (*Pipeline) BeforeDelete

func (m *Pipeline) BeforeDelete(tx *gorm.DB) error

type PipelineConfig

type PipelineConfig struct {
	System     string               `json:"system"`
	Image      string               `json:"image"`
	Shell      string               `json:"shell"`
	Privileged bool                 `json:"privileged"`
	Steps      []PipelineConfigStep `json:"steps"`
	Cleanup    []string             `json:"cleanup"`
}

type PipelineConfigStep

type PipelineConfigStep struct {
	Name     string   `json:"name"`
	Commands []string `json:"commands"`
}

type PipelineInput

type PipelineInput struct {
	Name   string         `json:"name"`
	Branch string         `json:"branch"`
	Config PipelineConfig `json:"config"`
}

type PipelineShort

type PipelineShort struct {
	Name      string    `json:"name"`
	Branch    string    `json:"branch"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Project

type Project struct {
	Name      string     `json:"name"                gorm:"primaryKey"`
	Repo      string     `json:"repo"                gorm:"not null"`
	Variables []Variable `json:"variables,omitempty" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Secrets   []Secret   `json:"secrets,omitempty"`
	Pipelines []Pipeline `json:"pipelines,omitempty" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	CreatedAt time.Time  `json:"created_at"          gorm:"default:now()"`
	UpdatedAt time.Time  `json:"updated_at"          gorm:"default:now()"`
}

TODO: cascading delete (secrets, issue: https://github.com/go-gorm/gorm/issues/5001)

func (*Project) BeforeDelete

func (m *Project) BeforeDelete(tx *gorm.DB) error

type ProjectInput

type ProjectInput struct {
	Name string `json:"name"`
	Repo string `json:"repo"`
}

type ProjectShort

type ProjectShort struct {
	Name      string    `json:"name"`
	Repo      string    `json:"repo"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type QueueContext

type QueueContext struct {
	Build     Build
	Repo      string
	Branch    string
	Config    PipelineConfig
	Secrets   []Secret
	Variables []Variable
}

type QueueElem

type QueueElem struct {
	ID        string       `json:"id"         gorm:"primaryKey"`
	Context   QueueContext `json:"context"    gorm:"serializer:json;not null"`
	CreatedAt time.Time    `json:"created_at" gorm:"default:now()"`
}

func (QueueElem) TableName

func (QueueElem) TableName() string

type QueueElemShort

type QueueElemShort struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
}

type Secret

type Secret struct {
	Key          string         `json:"key"            gorm:"uniqueIndex:idx_secrets"`
	ProjectName  sql.NullString `json:"project_name"   gorm:"uniqueIndex:idx_secrets"`
	PipelineName sql.NullString `json:"pipeline_name"  gorm:"uniqueIndex:idx_secrets"`
	Path         string         `json:"path,omitempty"`
	CreatedAt    time.Time      `json:"created_at"     gorm:"default:now()"`
	UpdatedAt    time.Time      `json:"updated_at"     gorm:"default:now()"`
}

func (*Secret) AfterCreate

func (m *Secret) AfterCreate(tx *gorm.DB) error

func (*Secret) AfterDelete

func (m *Secret) AfterDelete(tx *gorm.DB) error

func (*Secret) AfterUpdate

func (m *Secret) AfterUpdate(tx *gorm.DB) error

func (*Secret) BeforeCreate

func (m *Secret) BeforeCreate(tx *gorm.DB) error

func (Secret) Value

func (m Secret) Value() (string, error)

type SecretInput

type SecretInput struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Path  string `json:"path"`
}

type Variable

type Variable struct {
	Key          string         `json:"key"            gorm:"uniqueIndex:idx_variables"`
	ProjectName  sql.NullString `json:"project_name"   gorm:"uniqueIndex:idx_variables"`
	PipelineName sql.NullString `json:"pipeline_name"  gorm:"uniqueIndex:idx_variables"`
	Value        string         `json:"value"          gorm:"not null"`
	Path         string         `json:"path,omitempty"`
	CreatedAt    time.Time      `json:"created_at"     gorm:"default:now();not null"`
	UpdatedAt    time.Time      `json:"updated_at"     gorm:"default:now();not null"`
}

func (*Variable) AfterUpdate

func (m *Variable) AfterUpdate(tx *gorm.DB) error

func (*Variable) BeforeCreate

func (m *Variable) BeforeCreate(tx *gorm.DB) error

type VariableInput

type VariableInput struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Path  string `json:"path"`
}

type Worker

type Worker struct {
	Name         string    `json:"name"             gorm:"primaryKey"`
	Address      string    `json:"address"          gorm:"not null"`
	System       string    `json:"system"           gorm:"not null"`
	Username     string    `json:"username"         gorm:"not null"`
	IsStatic     bool      `json:"is_static"        gorm:"not null"`
	Status       string    `json:"status"           gorm:"default:idle"`
	Strategy     string    `json:"strategy"         gorm:"default:balance"`
	ActiveBuilds int       `json:"active_builds"    gorm:"default:0"`
	Capacity     int       `json:"capacity"         gorm:"default:0"`
	Builds       []Build   `json:"builds,omitempty" gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL"`
	CreatedAt    time.Time `json:"created_at"       gorm:"default:now()"`
	UpdatedAt    time.Time `json:"updated_at"       gorm:"default:now()"`
}

func (*Worker) AfterCreate

func (m *Worker) AfterCreate(tx *gorm.DB) error

func (*Worker) AfterDelete

func (m *Worker) AfterDelete(tx *gorm.DB) error

func (*Worker) AfterSave

func (m *Worker) AfterSave(tx *gorm.DB) error

func (*Worker) AfterUpdate

func (m *Worker) AfterUpdate(tx *gorm.DB) error

func (*Worker) BeforeCreate

func (m *Worker) BeforeCreate(tx *gorm.DB) error

func (*Worker) BeforeDelete

func (m *Worker) BeforeDelete(tx *gorm.DB) error

func (*Worker) BeforeUpdate

func (m *Worker) BeforeUpdate(tx *gorm.DB) error

func (Worker) PK

func (m Worker) PK() (string, error)

type WorkerInput

type WorkerInput struct {
	Name       string `json:"name"`
	Address    string `json:"address"`
	System     string `json:"system"`
	IsStatic   bool   `json:"is_static"`
	Strategy   string `json:"strategy"`
	Username   string `json:"username"`
	PrivateKey string `json:"private_key"`
	Capacity   int    `json:"capacity"`
}

type WorkerShort

type WorkerShort struct {
	Name         string    `json:"name"`
	Address      string    `json:"address"`
	System       string    `json:"system"`
	Username     string    `json:"username"`
	IsStatic     bool      `json:"is_static"`
	Status       string    `json:"status"`
	Strategy     string    `json:"strategy"`
	ActiveBuilds int       `json:"active_builds"`
	Capacity     int       `json:"capacity"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

Jump to

Keyboard shortcuts

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