build

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package build provides database implementations for the Build entity and its related entities.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDriver         = errors.New("unknown driver")
	ErrDriverDisabled = errors.New("driver disabled")
)

Functions

func ArtifactModel

func ArtifactModel(aa []*Artifact) func(int) database.Model

ArtifactModel is called along with database.ModelSlice to convert the given slice of Artifact models to a slice of database.Model interfaces.

func DriverModel

func DriverModel(dd []*Driver) func(int) database.Model

DriverModel is called along with database.ModelSlice to convert the given slice of Driver models to a slice of database.Model interfaces.

func InitEvent added in v1.1.0

func InitEvent(dis event.Dispatcher) queue.InitFunc

func InitTagEvent added in v1.1.0

func InitTagEvent(dis event.Dispatcher) queue.InitFunc

func JobModel

func JobModel(jj []*Job) func(int) database.Model

JobModel is called along with database.ModelSlice to convert the given slice of Job models to a slice of database.Model interfaces.

func KeyModel

func KeyModel(kk []*Key) func(int) database.Model

KeyModel is called along with database.ModelSlice to convert the given slice of Key models to a slice of database.Model interfaces.

func LoadJobRelations

func LoadJobRelations(loaders *database.Loaders, jj ...*Job) error

LoadRelations loads all of the available relations for the given Job models using the given loaders available.

func LoadRelations

func LoadRelations(loaders *database.Loaders, bb ...*Build) error

LoadRelations loads all of the available relations for the given Build models using the given loaders available.

func Model

func Model(bb []*Build) func(int) database.Model

Model is called along with database.ModelSlice to convert the given slice of Build models to a slice of database.Model interfaces.

func NewTriggerData

func NewTriggerData() triggerData

NewTriggerData returns an empty set of data for a build trigger.

func ObjectModel

func ObjectModel(oo []*Object) func(int) database.Model

ObjectModel is called along with database.ModelSlice to convert the given slice of Object models to a slice of database.Model interfaces.

func SelectObject

func SelectObject(col string, opts ...query.Option) query.Query

SelectObject returns SELECT query that will select the given column from the build_objects table with the given query options applied.

func StageModel

func StageModel(ss []*Stage) func(int) database.Model

StageModel is called along with database.ModelSlice to convert the given slice of Stage models to a slice of database.Model interfaces.

func TagModel

func TagModel(tt []*Tag) func(int) database.Model

TagModel is called along with database.ModelSlice to convert the given slice of Tag models to a slice of database.Model interfaces.

func TriggerModel

func TriggerModel(tt []*Trigger) func(int) database.Model

TriggerModel is called along with database.ModelSlice to convert the given slice of Trigger models to a slice of database.Model interfaces.

func VariableModel

func VariableModel(vv []*Variable) func(int) database.Model

VariableModel is called along with database.ModelSlice to convert the given slice of Variable models to a slice of database.Model interfaces.

func WhereSearch

func WhereSearch(search string) query.Option

WhereSearch returns a query option that applies a WHERE IN clause to a query. The returned WHERE IN clause operates on the values returned from a SELECT query that uses the given search string.

func WhereStatus

func WhereStatus(status string) query.Option

WhereStatus returns a query option that applies a WHERE IN clause to a query using the given status. If the given status is "passed", then it will be expanded to include "passed_with_failures".

func WhereTag

func WhereTag(tag string) query.Option

WhereTag returns a query option that applies a WHERE IN clause to a query. The returned WHERE IN claue operates on the values returnd from a SELECT query that uses the given tag string.

Types

type Artifact

type Artifact struct {
	ID        int64         `db:"id"`
	UserID    int64         `db:"user_id"`
	BuildID   int64         `db:"build_id"`
	JobID     int64         `db:"job_id"`
	Hash      string        `db:"hash"`
	Source    string        `db:"source"`
	Name      string        `db:"name"`
	Size      sql.NullInt64 `db:"size"`
	MD5       []byte        `db:"md5"`
	SHA256    []byte        `db:"sha256"`
	CreatedAt time.Time     `db:"created_at"`
	DeletedAt sql.NullTime  `db:"deleted_at"`

	Build *Build     `db:"-"`
	Job   *Job       `db:"-"`
	User  *user.User `db:"-"`
}

Artifact is the type that represents a file that has been collected from a build environment for a given build. This contains metadata about the file that was collected.

func (*Artifact) Bind

func (a *Artifact) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or Job models.

func (*Artifact) Endpoint

func (a *Artifact) Endpoint(uris ...string) string

Endpoint implements the database.Model interface. If the current Artifact has a nil or zero value Build bound model then an empty string is returned, otherwise the fulld Build endpoint is returned, suffixed with the Artifact endpoint, for example,

/b/l.belardo/10/artifacts/os-release

func (*Artifact) IsZero

func (a *Artifact) IsZero() bool

IsZero implements the database.Model interface.

func (*Artifact) JSON

func (a *Artifact) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Artifacts values under each key. If any of the Build, or Job bound models exist on the Artifact, then the JSON representation of these models will be in the returned map, under the build, and job keys respectively.

func (*Artifact) Primary

func (a *Artifact) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Artifact) SetPrimary

func (a *Artifact) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Artifact) Values

func (a *Artifact) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, user_id, build_id, job_id, hash, source, name, size, md5, and sha256.

type ArtifactStore

type ArtifactStore struct {
	database.Store

	// Build is the bound Build model. If not nil this will bind the Build
	// model to any Artifact models that are created. If not nil this will
	// append a WHERE clause on the build_id column for all SELECT queries
	// performed.
	Build *Build

	// Job is the bound Job model. If not nil this will bind the Job model to
	// any Artifact models that are created. If not nil this will append a
	// WHERE clause on the job_id column for all SELECT queries performed.
	Job *Job

	User *user.User
	// contains filtered or unexported fields
}

ArtifactStore is the type for creating and modifying Artifact models in the database. The ArtifactStore type can have an underlying runner.Collector implementation that can allow for it to be used for collecting artifacts from a build environment.

func NewArtifactStore

func NewArtifactStore(db *sqlx.DB, mm ...database.Model) *ArtifactStore

NewArtifactStore returns a new ArtifactStore for querying the build_artifacts table. Each model passed to this function will be bound to the returned ArtifactStore.

func NewArtifactStoreWithCollector

func NewArtifactStoreWithCollector(db *sqlx.DB, c runner.Collector, mm ...database.Model) *ArtifactStore

NewArtifactStoreWithCollector returns a new ArtifactStore with the given runner.Collector. This allows for the ArtifactStore to be used as a runner.Collector during a build run. Each collected artifact will be updated in the database, with the actual collection being deferred to the given runner.Collector.

func (*ArtifactStore) All

func (s *ArtifactStore) All(opts ...query.Option) ([]*Artifact, error)

All returns a slice of Artifact models, applying each query.Option that is given.

func (*ArtifactStore) Bind

func (s *ArtifactStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to either Build or Job models.

func (*ArtifactStore) Collect

func (s *ArtifactStore) Collect(name string, r io.Reader) (int64, error)

Collect looks up the Artifact by the given name, and updates it with the size, md5, and sha256 once the underlying runner.Collector has been successfully invoked. If no underlying collector has been set for the ArtifactStore then it immediately errors.

func (*ArtifactStore) Create

func (s *ArtifactStore) Create(hash, src, dst string) (*Artifact, error)

Create creates a new Artifact model in the database. The given hash should be unique across all Artifact models created. The src should be the verbatim name of the Artifact from the build environment. The dst should be the name that is used for collecting the Artifact.

func (*ArtifactStore) Deleted

func (s *ArtifactStore) Deleted(ids ...int64) error

Deleted marks all of the artifacts in the given list of ids as deleted. This will set the deleted_at column to the result of time.Now when this is called.

func (*ArtifactStore) Get

func (s *ArtifactStore) Get(opts ...query.Option) (*Artifact, error)

Get returns a single Artifact model, applying each query.Option that is given.

func (*ArtifactStore) Load

func (s *ArtifactStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load implements the database.Loader interface. Any models that are bound to the ArtifactStore will be applied during querying.

func (*ArtifactStore) New

func (s *ArtifactStore) New() *Artifact

New returns a new Artifact binding any non-nil models to it from the current ArtifactStore.

type Build

type Build struct {
	ID          int64             `db:"id"`
	UserID      int64             `db:"user_id"`
	NamespaceID sql.NullInt64     `db:"namespace_id"`
	Number      int64             `db:"number"`
	Manifest    manifest.Manifest `db:"manifest"`
	Status      runner.Status     `db:"status"`
	Output      sql.NullString    `db:"output"`
	Secret      sql.NullString    `db:"secret"`
	CreatedAt   time.Time         `db:"created_at"`
	StartedAt   sql.NullTime      `db:"started_at"`
	FinishedAt  sql.NullTime      `db:"finished_at"`

	User      *user.User           `db:"-" json:"-"`
	Namespace *namespace.Namespace `db:"-" json:"-"`
	Driver    *Driver              `db:"-" json:"-"`
	Trigger   *Trigger             `db:"-" json:"-"`
	Tags      []*Tag               `db:"-" json:"-"`
	Stages    []*Stage             `db:"-" json:"-"`
}

Build is the type that represents a build that has either run, or will be run.

func FromContext

func FromContext(ctx context.Context) (*Build, bool)

FromContext returns the Build model from the given context, if any.

func (*Build) Bind

func (b *Build) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User, namespace.Namespace, Trigger, Tag, Stage, or Driver.

func (*Build) Endpoint

func (b *Build) Endpoint(uri ...string) string

Endpoint implements the database.Model interface. If the current Build has a nil or zero value User bound model then an empty string is returned, otherwise the full Build endpoint is returned, for example,

/b/l.belardo/10

func (*Build) IsZero

func (b *Build) IsZero() bool

IsZero implements the database.Model interface.

func (*Build) JSON

func (b *Build) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Build values under each key. This will also include urls to the Build's objects, variables, jobs, artifacts, and tags. If any of the User, Namespace, or Trigger bound models exist on the Build, then the JSON representation of these models will be in the returned map, under the user, namespace, and trigger keys respectively.

func (*Build) Kill

func (b *Build) Kill(client *redis.Client) error

Kill kills the given build by publishing the build's secret to the given redis.Client.

func (*Build) Primary

func (b *Build) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Build) SetPrimary

func (b *Build) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Build) Values

func (b *Build) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, user_id, namespace_id, manifest, status, output, secret, started_at, and finished_at.

type Curator

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

Curator is used for removing old build artifacts whose total size exceed the configured limit.

func NewCurator

func NewCurator(db *sqlx.DB, artifacts fs.Store, limit int64) Curator

NewCurator creates a new curator for cleaning up old artifacts from the given block store.

func (*Curator) Invoke

func (c *Curator) Invoke(log *log.Logger) error

Invoke will remove any artifacts whose total size exceeds the configured limit. This will only do it for users who have "cleanup" enabled on their account.

type Driver

type Driver struct {
	ID      int64           `db:"id"`
	BuildID int64           `db:"build_id"`
	Type    driver.Type     `db:"type"`
	Config  manifest.Driver `db:"config"`

	Build *Build `db:"-"`
}

Driver is the type that represents the driver being used by a build.

func (*Driver) Bind

func (d *Driver) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to Build.

func (*Driver) Endpoint

func (*Driver) Endpoint(_ ...string) string

Endpoint implements the database.Model interface. This returns an empty string.

func (*Driver) IsZero

func (d *Driver) IsZero() bool

IsZero implements the database.Model interface.

func (*Driver) JSON

func (*Driver) JSON(_ string) map[string]interface{}

JSON implements the database.Model interface. This returns an empty map.

func (*Driver) Primary

func (d *Driver) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Driver) SetPrimary

func (d *Driver) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Driver) Values

func (d *Driver) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, type, and config.

type DriverStore

type DriverStore struct {
	database.Store

	// Build is the bound Build model. If not nil this will bind the Build
	// model to any Driver models that are created. If not nil this will append
	// a WHERE clause on the build_id column for all SELECT queries performed.
	Build *Build
}

DriverStore is the type for creating Driver models in the database.

func NewDriverStore

func NewDriverStore(db *sqlx.DB, mm ...database.Model) *DriverStore

NewDriverStore returns a new DriverStore for querying the build_drivers table. Each database passed to this function will be bound to the returned DriverStore.

func (*DriverStore) All

func (s *DriverStore) All(opts ...query.Option) ([]*Driver, error)

All returns a slice of Driver models, applying each query.Option that is given. The database.Where option is applied to the *Build bound database.

func (*DriverStore) Bind

func (s *DriverStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to Build.

func (*DriverStore) Create

func (s *DriverStore) Create(cfg map[string]string) (*Driver, error)

Create creates a new driver using the given configuration.

func (*DriverStore) Get

func (s *DriverStore) Get(opts ...query.Option) (*Driver, error)

Get returns a single Driver database, applying each query.Option that is given. The database.Where option is applied to the *Build bound database.

func (*DriverStore) Load

func (s *DriverStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Driver models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls DriverStore.All under the hood, so any bound models will impact the models being loaded.

func (*DriverStore) New

func (s *DriverStore) New() *Driver

New returns a new Driver binding any non-nil models to it from the current DriverStore.

type Event added in v1.1.0

type Event struct {
	Build *Build
	// contains filtered or unexported fields
}

func (*Event) Name added in v1.1.0

func (ev *Event) Name() string

func (*Event) Perform added in v1.1.0

func (ev *Event) Perform() error

type Form

type Form struct {
	Manifest manifest.Manifest `schema:"manifest" json:"manifest"`
	Comment  string            `schema:"comment"  json:"comment"`
	Tags     tags              `schema:"tags"     json:"tags"`
}

Form is the type that represents the input data for creating/submitting a build.

func (Form) Fields

func (f Form) Fields() map[string]string

Fields returns the fields of the build form. If the manifest is empty then return an empty string instead of a pair of {}.

func (Form) Validate

func (f Form) Validate() error

Validate checks to see if there is a manifest, and if that manifest has the bare minimum for a build to be submitted.

type Job

type Job struct {
	ID         int64          `db:"id"`
	BuildID    int64          `db:"build_id"`
	StageID    int64          `db:"stage_id"`
	Name       string         `db:"name"`
	Commands   string         `db:"commands"`
	Status     runner.Status  `db:"status"`
	Output     sql.NullString `db:"output"`
	CreatedAt  time.Time      `db:"created_at"`
	StartedAt  sql.NullTime   `db:"started_at"`
	FinishedAt sql.NullTime   `db:"finished_at"`

	Build     *Build      `db:"-"`
	Stage     *Stage      `db:"-"`
	Artifacts []*Artifact `db:"-"`
}

Job is the type that represents a job that is either running, or has been run during a build.

func (*Job) Bind

func (j *Job) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build, Stage, or Artifact models.

func (*Job) Endpoint

func (j *Job) Endpoint(uri ...string) string

Endpoint implements the database.Model interface. If the current Job has a nil or zero value Build bound model then an empty string is returned, otherwise the full Build endpoint is returned, suffixed with the Job endpoint, for example,

/b/l.belardo/10/jobs/create-driver

func (*Job) IsZero

func (j *Job) IsZero() bool

IsZero implements the database.Model interface.

func (*Job) JSON

func (j *Job) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Job's values under each key.

func (*Job) Job

func (j *Job) Job(w io.Writer) *runner.Job

Job returns the underlying runner.Job of the current Job. This can then be passed to a runner.Driver for execution. It is expected for the Job's Artifact slice to be already loaded onto the current database.

func (*Job) Primary

func (j *Job) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Job) SetPrimary

func (j *Job) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Job) Values

func (j *Job) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, stage_id, name, commands, status, output, started_at, and finished_at.

type JobStore

type JobStore struct {
	database.Store

	Build *Build
	Stage *Stage
}

JobStore is the type for creating and modifying Job models in the database.

func NewJobStore

func NewJobStore(db *sqlx.DB, mm ...database.Model) *JobStore

NewJobStore returns a new JobStore for querying the build_jobs table. Each database passed to this function will be bound to the returned JobStore.

func (*JobStore) All

func (s *JobStore) All(opts ...query.Option) ([]*Job, error)

All returns a slice of Job models, applying each query.Option that is given.

func (*JobStore) Bind

func (s *JobStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build, Stage, or Artifact.

func (*JobStore) Create

func (s *JobStore) Create(name, commands string) (*Job, error)

Create creates a new Job model in the database with the given name and commands.

func (*JobStore) Finished

func (s *JobStore) Finished(id int64, output string, status runner.Status) error

Finished marks the Job model with the given id as finished in the database, with the given output and status.

func (*JobStore) Get

func (s *JobStore) Get(opts ...query.Option) (*Job, error)

Get returns a single Job database, applying each query.Option that is given.

func (*JobStore) Index

func (s *JobStore) Index(vals url.Values, opts ...query.Option) ([]*Job, error)

Index returns the results from the jobs table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,

name - This applies the database.Search query.Option using the value of name status - This applied the WhereStatus query.Option using the value of status

func (*JobStore) Load

func (s *JobStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Job models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls JobStore.All under the hood, so any bound models will impact the models being loaded.

func (*JobStore) New

func (s *JobStore) New() *Job

New returns a new Job binding any non-nil models to it from the current JobStore.

func (*JobStore) Started

func (s *JobStore) Started(id int64) error

Started marks the Job model with the given id as started in the database.

type Key

type Key struct {
	ID       int64         `db:"id"`
	BuildID  int64         `db:"build_id"`
	KeyID    sql.NullInt64 `db:"key_id"`
	Name     string        `db:"name"`
	Key      []byte        `db:"key"`
	Config   string        `db:"config"`
	Location string        `db:"location"`

	Build *Build `db:"-"`
}

Key is the type that represents an SSH key that has been placed into the build environment.

func (*Key) Bind

func (k *Key) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to a Build model.

func (*Key) Endpoint

func (*Key) Endpoint(_ ...string) string

Endpoint implements the database.Model interface. This returns an empty string.

func (*Key) IsZero

func (k *Key) IsZero() bool

IsZero implements the database.Model interface.

func (*Key) JSON

func (k *Key) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Key's values under each key.

func (*Key) Primary

func (k *Key) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Key) SetPrimary

func (k *Key) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Key) Values

func (k *Key) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, key_id, name, key, config, and location.

type KeyStore

type KeyStore struct {
	database.Store

	Build *Build
	Key   *key.Key
	// contains filtered or unexported fields
}

KeyStore is the type for creating and modifying Key models in the database. The KeyStore type uses an underlying crypto.AESGCM for encrypting the SSH key itself when being stored in the database.

func NewKeyStore

func NewKeyStore(db *sqlx.DB, mm ...database.Model) *KeyStore

NewKeyStore returns a new KeyStore for querying the build_jobs table. Each database passed to this function will be bound to the returned JobStore.

func NewKeyStoreWithCrypto added in v1.1.0

func NewKeyStoreWithCrypto(db *sqlx.DB, block *crypto.AESGCM, mm ...database.Model) *KeyStore

NewKeyStoreWithblock is functionally the same as NewStore, however it sets the given crypto.AESGCM on the newly returned KeyStore.

func (*KeyStore) All

func (s *KeyStore) All(opts ...query.Option) ([]*Key, error)

All returns a slice of Key models, applying each query.Option that is given. Each database that is bound to the store will be applied to the list of query options via database.Where.

func (*KeyStore) Bind

func (s *KeyStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to a Build model.

func (*KeyStore) Copy

func (s *KeyStore) Copy(kk ...*key.Key) ([]*Key, error)

Copy copies each given key.Key into a build Key, and returns the slice of newly created Key models.

func (*KeyStore) Get

func (s *KeyStore) Get(opts ...query.Option) (*Key, error)

Get returns a single Key database, applying each query.Option that is given. Each database that is bound to the store will be applied to the list of query options via database.Where.

func (*KeyStore) Load

func (s *KeyStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Key models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls KeyStore.All under the hood, so any bound models will impact the models being loaded.

func (*KeyStore) New

func (s *KeyStore) New() *Key

New returns a new Key binding any non-nil models to it from the current KeyStore.

type Object

type Object struct {
	ID        int64         `db:"id"`
	BuildID   int64         `db:"build_id"`
	ObjectID  sql.NullInt64 `db:"object_id"`
	Source    string        `db:"source"`
	Name      string        `db:"name"`
	Placed    bool          `db:"placed"`
	CreatedAt time.Time     `db:"created_at"`

	Build  *Build         `db:"-"`
	Object *object.Object `db:"-"`
}

Object is the type that represents a file that has been placed into a build environment for a given build. This contains metadata about the file that was placed.

func (*Object) Bind

func (o *Object) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or object.Object.

func (*Object) Endpoint

func (o *Object) Endpoint(_ ...string) string

Endpoint implements the database.Model interface. This returns an empty string.

func (*Object) IsZero

func (o *Object) IsZero() bool

IsZero implements the database.Model interface.

func (*Object) JSON

func (o *Object) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Object's values under each key. If any of the Build, or Object bound models exist on the Object, then the JSON representation of these models will be in the returned map, under the build, and object keys respectively.

func (*Object) Primary

func (o *Object) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Object) SetPrimary

func (o *Object) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Object) Values

func (o *Object) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, object_id, source, name, and placed.

type ObjectStore

type ObjectStore struct {
	database.Store

	// Build is the bound Build model. If not nil this will bind the Build
	// model to any Object models that are created. If not nil this will
	// append a WHERE clause on the build_id column for all SELECT queries
	// performed.
	Build *Build

	// Object is the bound object.Object model. If not nil this will bind the
	// object.Object model to any Object models that are created. If not nil
	// this will append a WHERE clause on the object_id column for all SELECT
	// queries performed.
	Object *object.Object
	// contains filtered or unexported fields
}

ObjectStore is the type for creating and modifying Object models in the database. The ObjectStore type can have an underlying runner.Placer implementation that can allow for it to be used for placing objects into a build environment.

func NewObjectStore

func NewObjectStore(db *sqlx.DB, mm ...database.Model) *ObjectStore

NewObjectStore returns a new ObjectStore for querying the build_objects table. Each model passed to this function will be bound to the returned ObjectStore.

func NewObjectStoreWithPlacer

func NewObjectStoreWithPlacer(db *sqlx.DB, p runner.Placer, mm ...database.Model) *ObjectStore

NewObjectStoreWithCollector returns a new ObjectStore with the given runner.Placer to use for object placement.

func (*ObjectStore) All

func (s *ObjectStore) All(opts ...query.Option) ([]*Object, error)

All returns a slice of Object models, applying each query.Option that is given.

func (*ObjectStore) Bind

func (s *ObjectStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or object.Object.

func (*ObjectStore) Create

func (s *ObjectStore) Create(objectId int64, name, dst string) (*Object, error)

func (*ObjectStore) Get

func (s *ObjectStore) Get(opts ...query.Option) (*Object, error)

Get returns a single Object model, applying each query.Option that is given.

func (*ObjectStore) Load

func (s *ObjectStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Object models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls ObjectStore.All under the hood, so any bound models will impact the models being loaded.

func (*ObjectStore) New

func (s *ObjectStore) New() *Object

New returns a new Object binding any non-nil models to it from the current ObjectStore.

func (*ObjectStore) Place

func (s *ObjectStore) Place(name string, w io.Writer) (int64, error)

Place looks up the Object by the given name, and updates it once object placement has been done via the underlying runner.Placer on the store.

func (*ObjectStore) Stat

func (s *ObjectStore) Stat(name string) (os.FileInfo, error)

Stat returns the os.FileInfo of the Object by the given name. This uses the underlying runner.Placer on the store.

type Payload

type Payload struct {
	Host    string // Host is the server hostname the build was submitted to
	BuildID int64  // BuildID is the ID of the build
}

Payload is how the build is put onto the queue. This struct will be encoded via encoding/gob, and submitted to Redis.

type Stage

type Stage struct {
	ID         int64         `db:"id"`
	BuildID    int64         `db:"build_id"`
	Name       string        `db:"name"`
	CanFail    bool          `db:"can_fail"`
	Status     runner.Status `db:"status"`
	CreatedAt  time.Time     `db:"created_at"`
	StartedAt  sql.NullTime  `db:"started_at"`
	FinishedAt sql.NullTime  `db:"finished_at"`

	Build *Build `db:"-"`
	Jobs  []*Job `db:"-"`
}

Stage is the type that represents a stage that is in a build.

func (*Stage) Bind

func (s *Stage) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or Stage.

func (*Stage) Endpoint

func (s *Stage) Endpoint(_ ...string) string

Endpoint implements the database.Model interface. If the current Stage has a nil or zero value Build bound model then an empty string is returned, otherwise the full Build endpoint is returned, suffixed with the Stage endpoint, for example,

/b/l.belardo/10/stages/2

func (*Stage) IsZero

func (s *Stage) IsZero() bool

IsZero implements the database.Model interface.

func (*Stage) JSON

func (s *Stage) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Stage's values under each key. If the Build bound model exists on the Stage, then the JSON representation of that model will be in the returned map under the build key.

func (Stage) Primary

func (s Stage) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Stage) SetPrimary

func (s *Stage) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (Stage) Stage

func (s Stage) Stage() *runner.Stage

Stage returns the underlying runner.Stage of the current Stage.

func (*Stage) Values

func (s *Stage) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, name, can_fail, status, started_at, finished_at.

type StageStore

type StageStore struct {
	database.Store

	// Build is the bound Build model. If not nil this will bind the Build
	// model to any Stage models that are created. If not nil this will
	// append a WHERE clause on the build_id column for all SELECT queries
	// performed.
	Build *Build
}

StageStore is the type for creating and modifying Stage models in the database.

func NewStageStore

func NewStageStore(db *sqlx.DB, mm ...database.Model) *StageStore

NewStageStore returns a new StageStore for querying the build_stages table. Each database passed to this function will be bound to the returned StageStore.

func (StageStore) All

func (s StageStore) All(opts ...query.Option) ([]*Stage, error)

All returns a slice of Stage models, applying each query.Option that is given.

func (*StageStore) Bind

func (s *StageStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or Stage.

func (*StageStore) Create

func (s *StageStore) Create(name string, canFail bool) (*Stage, error)

Create creates a new Stage model in the database with the name, and whether or not it can fail.

func (StageStore) Load

func (s StageStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Stage models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls StageStore.All under the hood, so any bound models will impact the models being loaded.

func (StageStore) New

func (s StageStore) New() *Stage

New returns a new Stage binding any non-nil models to it from the current StageStore.

type Store

type Store struct {
	database.Store

	// User is the bound User model. If not nil this will bind the User model to
	// any Build models that are created. If not nil this will be passed to the
	// namespace.WhereCollaborator query option on each SELECT query performed.
	User *user.User

	// Namespace is the bound Namespace model. If not nil this will bind the
	// Namespace model to any Build models that are created. If not nil this
	// will append a WHERE clause on the namespace_id column for all SELECT
	// queries performed.
	Namespace *namespace.Namespace
	// contains filtered or unexported fields
}

Store is the type for creating and modifying Build models in the database. The Store type can have an underlying hasher.Hasher that is used for generating artifact hashes.

func NewStore

func NewStore(db *sqlx.DB, mm ...database.Model) *Store

NewStore returns a new Store for querying the builds table. Each model passed to this function will be bound to the returned Store.

func NewStoreWithHasher

func NewStoreWithHasher(db *sqlx.DB, hasher *crypto.Hasher, mm ...database.Model) *Store

NewStoreWithHasher functionally does the same as NewStore, however it sets the given hasher on the newly returned store for hashing of Artifact names.

func (*Store) All

func (s *Store) All(opts ...query.Option) ([]*Build, error)

All returns a slice of Build models, applying each query.Option that is given.

func (*Store) Bind

func (s *Store) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User, namespace.Namespace, Trigger, Tag, Stage, or Driver.

func (*Store) Create

func (s *Store) Create(m manifest.Manifest, t *Trigger, tags ...string) (*Build, error)

Create takes the given manifest.Manifest, Trigger, and tags, and creates a new Build model in the database. This will also create a Trigger, and tags once the Build has been created in the database.

func (*Store) Finished

func (s *Store) Finished(id int64, output string, status runner.Status) error

Finished marks the build of the given id as finished, setting the output of the build and status to the given values.

func (*Store) Get

func (s *Store) Get(opts ...query.Option) (*Build, error)

Get returns a single Build model, applying each query.Option that is given.

func (*Store) Index

func (s *Store) Index(vals url.Values, opts ...query.Option) ([]*Build, database.Paginator, error)

Index returns the paginated results from the builds table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,

tag - This applies the WhereTag query.Option using the value of tag search - This applies the WhereSearch query.Option using the value of search status - This applies the WhereStatus query.Option using the value of status

func (*Store) Load

func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Build models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls Store.All under the hood, so any bound models will impact the models being loaded.

func (*Store) New

func (s *Store) New() *Build

New returns a new Build binding any non-nil models to it from the current Store.

func (*Store) Orphan added in v1.1.0

func (s *Store) Orphan(b *Build) error

Orphan marks the given build as orphaned, and clears down the output of the build and its jobs. An orphaned build happens when the worker is restarted whilst a build is processing.

func (*Store) Paginate

func (s *Store) Paginate(page int64, opts ...query.Option) (database.Paginator, error)

Paginate returns the database.Paginator for the builds table for the given page.

func (*Store) Started

func (s *Store) Started(id int64) error

Started marks the build of the given id as started.

func (*Store) Submit

func (s *Store) Submit(ctx context.Context, prd *curlyq.Producer, host string, b *Build) error

Submit the given build to the given producer. This will also create all of the related entities that belong to the newly submitted build, such as keys, objects, variables, stages, jobs, and artifacts.

type Tag

type Tag struct {
	ID        int64     `db:"id"`
	UserID    int64     `db:"user_id"`
	BuildID   int64     `db:"build_id"`
	Name      string    `db:"name"`
	CreatedAt time.Time `db:"created_at"`

	User  *user.User `db:"-"`
	Build *Build     `db:"-"`
}

Tag is the type that represents a tag on a build.

func (*Tag) Bind

func (t *Tag) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or user.User models.

func (Tag) Endpoint

func (t Tag) Endpoint(uri ...string) string

Endpoint implements the database.Model interface. If the current Tag has a nil or zero value Tag bound model then an emtpy string is returned, otherwise the full Build endpoint is returned, suffixed with the Tag endpoint, for example,

/b/l.belardo/10/tags/qemu

func (*Tag) IsZero

func (t *Tag) IsZero() bool

IsZero implements the database.Model interface.

func (*Tag) JSON

func (t *Tag) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return reutrn a map with the current Tag's values under each key. If the User or Build bound models are not zero, then the JSON representation of each will be in the returned map under the user and build keys respectively.

func (Tag) Primary

func (t Tag) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Tag) SetPrimary

func (t *Tag) SetPrimary(i int64)

SetPrimary implements the database.Model interface.

func (*Tag) Values

func (t *Tag) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, user_id, build_id, and name.

type TagEvent added in v1.1.0

type TagEvent struct {
	Build *Build
	User  *user.User
	Tags  []*Tag
	// contains filtered or unexported fields
}

func (*TagEvent) Name added in v1.1.0

func (ev *TagEvent) Name() string

func (*TagEvent) Perform added in v1.1.0

func (ev *TagEvent) Perform() error

type TagForm

type TagForm struct {
	Tags tags `schema:"tags"`
}

TagForm is the type that represents the input data for creating tags on a build.

func (*TagForm) Fields

func (f *TagForm) Fields() map[string]string

Fields is a stub method to statisfy the form.Form interface. It returns an empty map.

func (*TagForm) UnmarshalJSON

func (f *TagForm) UnmarshalJSON(data []byte) error

UnmarshalJSON will attempt to unmarshal the given byte slice into a slice of strings.

func (*TagForm) Validate

func (f *TagForm) Validate() error

Validate is a stub method to satisfy the form.Form interface. It returns nil.

type TagStore

type TagStore struct {
	database.Store

	User  *user.User
	Build *Build
}

TagStore is the type for creating and modifying Tag models in the database.

func NewTagStore

func NewTagStore(db *sqlx.DB, mm ...database.Model) *TagStore

NewTagStore returns a new TagStore for querying the build_tags table. Each database passed to this function will be bound to the returned TagStore.

func (TagStore) All

func (s TagStore) All(opts ...query.Option) ([]*Tag, error)

All returns a slice of Tag models, applying each query.Option that is given.

func (*TagStore) Bind

func (s *TagStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or user.User models.

func (*TagStore) Create

func (s *TagStore) Create(userId int64, names ...string) ([]*Tag, error)

Create takes the given names, and creates a Tag for each for the given build ID, and user ID. A slice of the created Tag models are returned.

func (*TagStore) Delete

func (s *TagStore) Delete(buildId int64, name string) error

func (TagStore) Get

func (s TagStore) Get(opts ...query.Option) (*Tag, error)

Get returns a single Tag database, applying each query.Option that is given.

func (TagStore) Load

func (s TagStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Job models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls JobStore.All under the hood, so any bound models will impact the models being loaded.

func (TagStore) New

func (s TagStore) New() *Tag

New returns a new Tag binding any non-nil models to it from the current TagStore.

type Trigger

type Trigger struct {
	ID         int64         `db:"id"`
	BuildID    int64         `db:"build_id"`
	ProviderID sql.NullInt64 `db:"provider_id"`
	RepoID     sql.NullInt64 `db:"repo_id"`
	Type       TriggerType   `db:"type"`
	Comment    string        `db:"comment"`
	Data       triggerData   `db:"data"`
	CreatedAt  time.Time     `db:"created_at"`

	Build *Build `db:"-" gob:"-"`
}

Trigger is the type that represents what triggered a build.

func (*Trigger) Bind

func (t *Trigger) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to a Build model.

func (Trigger) CommentBody

func (t Trigger) CommentBody() string

CommentBody parses the trigger comment to get the body of the comment. This will typically return the lines of the comment that appear after the first newline character that is found. If there is no newline character, and the trigger comment itself is less than 72 characters in length, then nothing is returned. The first 72 characters are summed to be the title of the comment.

func (Trigger) CommentTitle

func (t Trigger) CommentTitle() string

CommentTitle parses the trigger comment to get the title of the comment. This treats the first line of the trigger comment as the title. If that first line is longer than 72 characters, then only the first 72 characters will be returned.

func (*Trigger) Endpoint

func (*Trigger) Endpoint(_ ...string) string

Endpoint is a stub to fulfill the database.Model interface. It returns an empty string.

func (*Trigger) IsZero

func (t *Trigger) IsZero() bool

IsZero implements the database.Model interface.

func (*Trigger) JSON

func (t *Trigger) JSON(_ string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Trigger's values under each key.

func (Trigger) Primary

func (t Trigger) Primary() (string, int64)

func (*Trigger) SetPrimary

func (t *Trigger) SetPrimary(i int64)

func (Trigger) String

func (t Trigger) String() string

String returns a formatted string of the trigger itself, this will detail the user who submitted it, if not nil, and format the comment into the title and body.

func (Trigger) Values

func (t Trigger) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, provider_id, type, comment, and data.

type TriggerStore

type TriggerStore struct {
	database.Store

	Build *Build
}

TriggerStore is the type for creating and modifying Trigger models in the database.

func NewTriggerStore

func NewTriggerStore(db *sqlx.DB, mm ...database.Model) *TriggerStore

NewTriggerStore returns a new TriggerStore for querying the build_triggers table. Each database passed to this function will be bound to the returned TriggerStore.

func (TriggerStore) All

func (s TriggerStore) All(opts ...query.Option) ([]*Trigger, error)

All returns a slice of Trigger models, applying each query.Option that is given. The database.Where option is used on the Build bound database to limit the query to those relations.

func (*TriggerStore) Bind

func (s *TriggerStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to a Build model.

func (*TriggerStore) Create

func (s *TriggerStore) Create(tt ...*Trigger) error

func (TriggerStore) Get

func (s TriggerStore) Get(opts ...query.Option) (*Trigger, error)

func (TriggerStore) Load

func (s TriggerStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Trigger models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls StageStore.All under the hood, so any bound models will impact the models being loaded.

type TriggerType

type TriggerType uint8
const (
	// There are three different trigger types for a build trigger,
	// Manual - for when a build was manually submitted for either via the API
	// or UI.
	//
	// Push     - for when a build was triggered via a commit hook.
	// Pull     - for when a build was triggered via a pull-request hook.
	// Schedule - for when a build was triggered via a cron.
	Manual   TriggerType = iota // manual
	Push                        // push
	Pull                        // pull
	Schedule                    // schedule
)

func (*TriggerType) Scan

func (t *TriggerType) Scan(val interface{}) error

func (TriggerType) String

func (i TriggerType) String() string

func (*TriggerType) UnmarshalText

func (t *TriggerType) UnmarshalText(b []byte) error

func (TriggerType) Value

func (t TriggerType) Value() (driver.Value, error)

type Variable

type Variable struct {
	ID         int64         `db:"id"`
	BuildID    int64         `db:"build_id"`
	VariableID sql.NullInt64 `db:"variable_id"`
	Key        string        `db:"key"`
	Value      string        `db:"value"`

	Build    *Build             `db:"-"`
	Variable *variable.Variable `db:"-"`
}

Variable is the type that represents a variable that has been set on a build.

func (*Variable) Bind

func (v *Variable) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either a Build or variable.Variable model.

func (*Variable) Endpoint

func (v *Variable) Endpoint(_ ...string) string

Endpoint implements the database.Model interface. This will return an empty string.

func (*Variable) IsZero

func (v *Variable) IsZero() bool

IsZero implements the database.Model interface.

func (*Variable) JSON

func (v *Variable) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Variable's values. If the Build bound model exists on the current Variable then the JSON representation will be in the returned map under the build key.

func (Variable) Primary

func (v Variable) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Variable) SetPrimary

func (v *Variable) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (Variable) Values

func (v Variable) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, build_id, variable_id, key, and value.

type VariableStore

type VariableStore struct {
	database.Store

	Build    *Build
	Variable *variable.Variable
}

VariableStore is the type for creating and modifying Variable models in the database.

func NewVariableStore

func NewVariableStore(db *sqlx.DB, mm ...database.Model) *VariableStore

NewVariableStore returns a new VariableStore for querying the build_variables table. Each database passed to this function will be bound to the returned VariableStore.

func (VariableStore) All

func (s VariableStore) All(opts ...query.Option) ([]*Variable, error)

All returns a slice of Variable models, applying each query.Option that is given.

func (*VariableStore) Bind

func (s *VariableStore) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the models if they are pointers to either Build or variable.Variable.

func (*VariableStore) Copy

func (s *VariableStore) Copy(vv ...*variable.Variable) ([]*Variable, error)

Copy copies each given variable.Variable into a build Variable, and returns the slice of newly created Variable models.

func (*VariableStore) Create

func (s *VariableStore) Create(key, val string) (*Variable, error)

Create creates a new Variable with the given key and val.

func (VariableStore) Load

func (s VariableStore) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Variable models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls StageStore.All under the hood, so any bound models will impact the models being loaded.

func (VariableStore) New

func (s VariableStore) New() *Variable

New returns a new Variable binding any non-nil models to it from the current VariableStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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