Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

build

v1.1.1
djinn-ci.com/build

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

233 matches

Top ↑

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

Variables

ErrDriver (2 declarations)

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

Functions

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.

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.

InitEvent

func InitEvent(dis event.Dispatcher) queue.InitFunc

InitTagEvent

func InitTagEvent(dis event.Dispatcher) queue.InitFunc

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.

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.

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.

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.

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.

NewTriggerData

func NewTriggerData() triggerData

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

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.

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.

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.

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.

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.

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.

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.

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".

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

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.

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.

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

Artifact.IsZero

func (a *Artifact) IsZero() bool

IsZero implements the database.Model interface.

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.

Artifact.Primary

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

Primary implements the database.Model interface.

Artifact.SetPrimary

func (a *Artifact) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

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.

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.

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.

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.

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.

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.

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.

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.

ArtifactStore.Get

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

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

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.

ArtifactStore.New

func (s *ArtifactStore) New() *Artifact

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

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.

FromContext

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

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

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.

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

Build.IsZero

func (b *Build) IsZero() bool

IsZero implements the database.Model interface.

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.

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.

Build.Primary

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

Primary implements the database.Model interface.

Build.SetPrimary

func (b *Build) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

Curator

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

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

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.

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.

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.

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.

Driver.Endpoint

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

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

Driver.IsZero

func (d *Driver) IsZero() bool

IsZero implements the database.Model interface.

Driver.JSON

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

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

Driver.Primary

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

Primary implements the database.Model interface.

Driver.SetPrimary

func (d *Driver) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

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.

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.

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.

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.

DriverStore.Create

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

Create creates a new driver using the given configuration.

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.

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.

DriverStore.New

func (s *DriverStore) New() *Driver

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

Event

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

Event.Name

func (ev *Event) Name() string

Event.Perform

func (ev *Event) Perform() error

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.

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 {}.

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.

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.

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.

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

Job.IsZero

func (j *Job) IsZero() bool

IsZero implements the database.Model interface.

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.

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.

Job.Primary

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

Primary implements the database.Model interface.

Job.SetPrimary

func (j *Job) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

JobStore

type JobStore struct {
	database.Store

	Build *Build
	Stage *Stage
}

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

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.

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.

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.

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.

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.

JobStore.Get

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

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

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

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.

JobStore.New

func (s *JobStore) New() *Job

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

JobStore.Started

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

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

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.

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.

Key.Endpoint

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

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

Key.IsZero

func (k *Key) IsZero() bool

IsZero implements the database.Model interface.

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.

Key.Primary

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

Primary implements the database.Model interface.

Key.SetPrimary

func (k *Key) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

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.

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.

NewKeyStoreWithCrypto

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.

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.

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.

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.

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.

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.

KeyStore.New

func (s *KeyStore) New() *Key

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

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.

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.

Object.Endpoint

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

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

Object.IsZero

func (o *Object) IsZero() bool

IsZero implements the database.Model interface.

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.

Object.Primary

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

Primary implements the database.Model interface.

Object.SetPrimary

func (o *Object) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

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.

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.

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.

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.

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.

ObjectStore.Create

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

ObjectStore.Get

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

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

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.

ObjectStore.New

func (s *ObjectStore) New() *Object

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

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.

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.

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.

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.

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.

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

Stage.IsZero

func (s *Stage) IsZero() bool

IsZero implements the database.Model interface.

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.

Stage.Primary

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

Primary implements the database.Model interface.

Stage.SetPrimary

func (s *Stage) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

Stage.Stage

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

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

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.

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.

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.

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.

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.

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.

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.

StageStore.New

func (s StageStore) New() *Stage

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

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.

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.

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.

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.

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.

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.

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.

Store.Get

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

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

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

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.

Store.New

func (s *Store) New() *Build

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

Store.Orphan

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.

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.

Store.Started

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

Started marks the build of the given id as started.

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.

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.

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.

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

Tag.IsZero

func (t *Tag) IsZero() bool

IsZero implements the database.Model interface.

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.

Tag.Primary

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

Primary implements the database.Model interface.

Tag.SetPrimary

func (t *Tag) SetPrimary(i int64)

SetPrimary implements the database.Model interface.

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.

TagEvent

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

TagEvent.Name

func (ev *TagEvent) Name() string

TagEvent.Perform

func (ev *TagEvent) Perform() error

TagForm

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

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

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.

TagForm.UnmarshalJSON

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

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

TagForm.Validate

func (f *TagForm) Validate() error

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

TagStore

type TagStore struct {
	database.Store

	User  *user.User
	Build *Build
}

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

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.

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.

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.

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.

TagStore.Delete

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

TagStore.Get

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

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

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.

TagStore.New

func (s TagStore) New() *Tag

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

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.

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.

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.

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.

Trigger.Endpoint

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

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

Trigger.IsZero

func (t *Trigger) IsZero() bool

IsZero implements the database.Model interface.

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.

Trigger.Primary

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

Trigger.SetPrimary

func (t *Trigger) SetPrimary(i int64)

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.

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.

TriggerStore

type TriggerStore struct {
	database.Store

	Build *Build
}

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

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.

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.

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.

TriggerStore.Create

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

TriggerStore.Get

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

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.

TriggerType

type TriggerType uint8

Manual (4 declarations)

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
)

TriggerType.Scan

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

TriggerType.String

func (i TriggerType) String() string

TriggerType.UnmarshalText

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

TriggerType.Value

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

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.

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.

Variable.Endpoint

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

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

Variable.IsZero

func (v *Variable) IsZero() bool

IsZero implements the database.Model interface.

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.

Variable.Primary

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

Primary implements the database.Model interface.

Variable.SetPrimary

func (v *Variable) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

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.

VariableStore

type VariableStore struct {
	database.Store

	Build    *Build
	Variable *variable.Variable
}

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

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.

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.

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.

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.

VariableStore.Create

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

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

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.

VariableStore.New

func (s VariableStore) New() *Variable

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

Dependency graph