2025-05-20 09:40:15 +00:00
|
|
|
// Copyright 2025 Cloudbase Solutions SRL
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
|
// not use this file except in compliance with the License. You may obtain
|
|
|
|
|
// a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
// License for the specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
|
|
|
|
|
2022-04-25 00:03:26 +00:00
|
|
|
package sql
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
2023-04-10 00:03:49 +00:00
|
|
|
"github.com/google/uuid"
|
2022-04-28 16:13:20 +00:00
|
|
|
"github.com/pkg/errors"
|
2023-01-30 00:40:01 +00:00
|
|
|
"gorm.io/datatypes"
|
2022-04-25 00:03:26 +00:00
|
|
|
"gorm.io/gorm"
|
2024-02-22 16:54:38 +01:00
|
|
|
|
|
|
|
|
commonParams "github.com/cloudbase/garm-provider-common/params"
|
|
|
|
|
"github.com/cloudbase/garm/params"
|
2022-04-25 00:03:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Base struct {
|
|
|
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-22 16:54:38 +01:00
|
|
|
func (b *Base) BeforeCreate(_ *gorm.DB) error {
|
|
|
|
|
emptyID := uuid.UUID{}
|
|
|
|
|
if b.ID != emptyID {
|
2022-04-26 20:29:58 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
2023-07-04 14:22:41 +00:00
|
|
|
newID, err := uuid.NewRandom()
|
2022-04-28 16:13:20 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, "generating id")
|
|
|
|
|
}
|
|
|
|
|
b.ID = newID
|
2022-04-25 00:03:26 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-14 00:34:54 +00:00
|
|
|
type ControllerInfo struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
ControllerID uuid.UUID
|
|
|
|
|
|
|
|
|
|
CallbackURL string
|
|
|
|
|
MetadataURL string
|
|
|
|
|
WebhookBaseURL string
|
|
|
|
|
// MinimumJobAgeBackoff is the minimum time that a job must be in the queue
|
|
|
|
|
// before GARM will attempt to allocate a runner to service it. This backoff
|
|
|
|
|
// is useful if you have idle runners in various pools that could potentially
|
|
|
|
|
// pick up the job. GARM would allow this amount of time for runners to react
|
|
|
|
|
// before spinning up a new one and potentially having to scale down later.
|
|
|
|
|
MinimumJobAgeBackoff uint
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 00:03:26 +00:00
|
|
|
type Tag struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2022-04-26 20:29:58 +00:00
|
|
|
Name string `gorm:"type:varchar(64);uniqueIndex"`
|
2023-06-28 21:52:50 +00:00
|
|
|
Pools []*Pool `gorm:"many2many:pool_tags;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Pool struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2022-06-29 23:44:03 +00:00
|
|
|
ProviderName string `gorm:"index:idx_pool_type"`
|
2022-12-19 20:56:16 +01:00
|
|
|
RunnerPrefix string
|
2022-06-29 23:44:03 +00:00
|
|
|
MaxRunners uint
|
|
|
|
|
MinIdleRunners uint
|
|
|
|
|
RunnerBootstrapTimeout uint
|
|
|
|
|
Image string `gorm:"index:idx_pool_type"`
|
|
|
|
|
Flavor string `gorm:"index:idx_pool_type"`
|
2023-07-21 15:30:22 +00:00
|
|
|
OSType commonParams.OSType
|
|
|
|
|
OSArch commonParams.OSArch
|
2023-06-28 21:52:50 +00:00
|
|
|
Tags []*Tag `gorm:"many2many:pool_tags;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2022-06-29 23:44:03 +00:00
|
|
|
Enabled bool
|
2023-01-30 00:40:01 +00:00
|
|
|
// ExtraSpecs is an opaque json that gets sent to the provider
|
|
|
|
|
// as part of the bootstrap params for instances. It can contain
|
|
|
|
|
// any kind of data needed by providers.
|
2023-03-27 08:40:22 +00:00
|
|
|
ExtraSpecs datatypes.JSON
|
|
|
|
|
GitHubRunnerGroup string
|
2022-04-26 20:29:58 +00:00
|
|
|
|
2023-06-28 15:09:54 +00:00
|
|
|
RepoID *uuid.UUID `gorm:"index"`
|
2023-07-05 19:49:48 +00:00
|
|
|
Repository Repository `gorm:"foreignKey:RepoID;"`
|
2022-04-26 20:29:58 +00:00
|
|
|
|
2023-06-28 15:09:54 +00:00
|
|
|
OrgID *uuid.UUID `gorm:"index"`
|
2022-04-26 20:29:58 +00:00
|
|
|
Organization Organization `gorm:"foreignKey:OrgID"`
|
2022-04-27 16:56:28 +00:00
|
|
|
|
2023-06-28 15:09:54 +00:00
|
|
|
EnterpriseID *uuid.UUID `gorm:"index"`
|
2022-10-13 16:09:28 +00:00
|
|
|
Enterprise Enterprise `gorm:"foreignKey:EnterpriseID"`
|
|
|
|
|
|
2022-04-27 16:56:28 +00:00
|
|
|
Instances []Instance `gorm:"foreignKey:PoolID"`
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Priority uint `gorm:"index:idx_pool_priority"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-08 09:15:54 +00:00
|
|
|
// ScaleSet represents a github scale set. Scale sets are almost identical to pools with a few
|
|
|
|
|
// notable exceptions:
|
|
|
|
|
// - Labels are no longer relevant
|
|
|
|
|
// - Workflows will use the scaleset name to target runners.
|
|
|
|
|
// - A scale set is a stand alone unit. If a workflow targets a scale set, no other runner will pick up that job.
|
|
|
|
|
type ScaleSet struct {
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
|
|
|
|
// ScaleSetID is the github ID of the scale set. This field may not be set if
|
|
|
|
|
// the scale set was ceated in GARM but has not yet been created in GitHub.
|
2025-04-15 09:36:28 +00:00
|
|
|
// The scale set ID is also not globally unique. It is only unique within the context
|
|
|
|
|
// of an entity.
|
2025-05-03 22:49:15 +00:00
|
|
|
ScaleSetID int `gorm:"index:idx_scale_set"`
|
|
|
|
|
Name string `gorm:"unique_index:idx_name"`
|
|
|
|
|
GitHubRunnerGroup string `gorm:"unique_index:idx_name"`
|
|
|
|
|
DisableUpdate bool
|
2025-04-08 09:15:54 +00:00
|
|
|
|
|
|
|
|
// State stores the provisioning state of the scale set in GitHub
|
|
|
|
|
State params.ScaleSetState
|
|
|
|
|
// ExtendedState stores a more detailed message regarding the State.
|
|
|
|
|
// If an error occurs, the reason for the error will be stored here.
|
|
|
|
|
ExtendedState string
|
|
|
|
|
|
|
|
|
|
ProviderName string
|
|
|
|
|
RunnerPrefix string
|
|
|
|
|
MaxRunners uint
|
|
|
|
|
MinIdleRunners uint
|
|
|
|
|
RunnerBootstrapTimeout uint
|
|
|
|
|
Image string
|
|
|
|
|
Flavor string
|
|
|
|
|
OSType commonParams.OSType
|
|
|
|
|
OSArch commonParams.OSArch
|
|
|
|
|
Enabled bool
|
2025-04-16 23:07:29 +00:00
|
|
|
LastMessageID int64
|
2025-04-17 16:53:54 +00:00
|
|
|
DesiredRunnerCount int
|
2025-04-08 09:15:54 +00:00
|
|
|
// ExtraSpecs is an opaque json that gets sent to the provider
|
|
|
|
|
// as part of the bootstrap params for instances. It can contain
|
|
|
|
|
// any kind of data needed by providers.
|
2025-05-03 22:49:15 +00:00
|
|
|
ExtraSpecs datatypes.JSON
|
2025-04-08 09:15:54 +00:00
|
|
|
|
|
|
|
|
RepoID *uuid.UUID `gorm:"index"`
|
|
|
|
|
Repository Repository `gorm:"foreignKey:RepoID;"`
|
|
|
|
|
|
|
|
|
|
OrgID *uuid.UUID `gorm:"index"`
|
|
|
|
|
Organization Organization `gorm:"foreignKey:OrgID"`
|
|
|
|
|
|
|
|
|
|
EnterpriseID *uuid.UUID `gorm:"index"`
|
|
|
|
|
Enterprise Enterprise `gorm:"foreignKey:EnterpriseID"`
|
|
|
|
|
|
2025-04-24 23:29:40 +00:00
|
|
|
Instances []Instance `gorm:"foreignKey:ScaleSetFkID"`
|
2025-04-08 09:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-16 16:39:16 +00:00
|
|
|
type RepositoryEvent struct {
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
|
|
|
|
EventType params.EventType
|
|
|
|
|
EventLevel params.EventLevel
|
|
|
|
|
Message string `gorm:"type:text"`
|
|
|
|
|
|
|
|
|
|
RepoID uuid.UUID `gorm:"index:idx_repo_event"`
|
|
|
|
|
Repo Repository `gorm:"foreignKey:RepoID"`
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 00:03:26 +00:00
|
|
|
type Repository struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2024-04-15 08:32:19 +00:00
|
|
|
CredentialsID *uint `gorm:"index"`
|
|
|
|
|
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
|
2025-05-14 00:34:54 +00:00
|
|
|
GiteaCredentialsID *uint `gorm:"index"`
|
|
|
|
|
GiteaCredentials GiteaCredentials `gorm:"foreignKey:GiteaCredentialsID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Owner string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
|
|
|
|
|
Name string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
|
|
|
|
|
WebhookSecret []byte
|
|
|
|
|
Pools []Pool `gorm:"foreignKey:RepoID"`
|
2025-04-08 09:15:54 +00:00
|
|
|
ScaleSets []ScaleSet `gorm:"foreignKey:RepoID"`
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Jobs []WorkflowJob `gorm:"foreignKey:RepoID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
PoolBalancerType params.PoolBalancerType `gorm:"type:varchar(64)"`
|
2024-04-15 08:32:19 +00:00
|
|
|
|
|
|
|
|
EndpointName *string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
|
|
|
|
|
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
|
2025-04-16 16:39:16 +00:00
|
|
|
|
2025-05-22 18:43:32 +00:00
|
|
|
Events []RepositoryEvent `gorm:"foreignKey:RepoID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-16 16:39:16 +00:00
|
|
|
type OrganizationEvent struct {
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
|
|
|
|
EventType params.EventType
|
|
|
|
|
EventLevel params.EventLevel
|
|
|
|
|
Message string `gorm:"type:text"`
|
|
|
|
|
|
|
|
|
|
OrgID uuid.UUID `gorm:"index:idx_org_event"`
|
|
|
|
|
Org Organization `gorm:"foreignKey:OrgID"`
|
|
|
|
|
}
|
2022-04-25 00:03:26 +00:00
|
|
|
type Organization struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2024-04-15 08:32:19 +00:00
|
|
|
CredentialsID *uint `gorm:"index"`
|
|
|
|
|
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
|
2025-05-14 00:34:54 +00:00
|
|
|
GiteaCredentialsID *uint `gorm:"index"`
|
|
|
|
|
GiteaCredentials GiteaCredentials `gorm:"foreignKey:GiteaCredentialsID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Name string `gorm:"index:idx_org_name_nocase,collate:nocase"`
|
|
|
|
|
WebhookSecret []byte
|
|
|
|
|
Pools []Pool `gorm:"foreignKey:OrgID"`
|
2025-04-08 09:15:54 +00:00
|
|
|
ScaleSet []ScaleSet `gorm:"foreignKey:OrgID"`
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Jobs []WorkflowJob `gorm:"foreignKey:OrgID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
PoolBalancerType params.PoolBalancerType `gorm:"type:varchar(64)"`
|
2024-04-15 08:32:19 +00:00
|
|
|
|
2024-07-29 17:35:57 +00:00
|
|
|
EndpointName *string `gorm:"index:idx_org_name_nocase,collate:nocase"`
|
2024-04-15 08:32:19 +00:00
|
|
|
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
|
2025-04-16 16:39:16 +00:00
|
|
|
|
2025-05-22 18:43:32 +00:00
|
|
|
Events []OrganizationEvent `gorm:"foreignKey:OrgID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2025-04-16 16:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EnterpriseEvent struct {
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
|
|
|
|
EventType params.EventType
|
|
|
|
|
EventLevel params.EventLevel
|
|
|
|
|
Message string `gorm:"type:text"`
|
|
|
|
|
|
|
|
|
|
EnterpriseID uuid.UUID `gorm:"index:idx_enterprise_event"`
|
|
|
|
|
Enterprise Enterprise `gorm:"foreignKey:EnterpriseID"`
|
2022-04-26 20:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 16:09:28 +00:00
|
|
|
type Enterprise struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2024-04-15 08:32:19 +00:00
|
|
|
CredentialsID *uint `gorm:"index"`
|
|
|
|
|
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Name string `gorm:"index:idx_ent_name_nocase,collate:nocase"`
|
|
|
|
|
WebhookSecret []byte
|
|
|
|
|
Pools []Pool `gorm:"foreignKey:EnterpriseID"`
|
2025-04-08 09:15:54 +00:00
|
|
|
ScaleSet []ScaleSet `gorm:"foreignKey:EnterpriseID"`
|
Add pool balancing strategy
This change adds the ability to specify the pool balancing strategy to
use when processing queued jobs. Before this change, GARM would round-robin
through all pools that matched the set of tags requested by queued jobs.
When round-robin (default) is used for an entity (repo, org or enterprise)
and you have 2 pools defined for that entity with a common set of tags that
match 10 jobs (for example), then those jobs would trigger the creation of
a new runner in each of the two pools in turn. Job 1 would go to pool 1,
job 2 would go to pool 2, job 3 to pool 1, job 4 to pool 2 and so on.
When "stack" is used, those same 10 jobs would trigger the creation of a
new runner in the pool with the highest priority, every time.
In both cases, if a pool is full, the next one would be tried automatically.
For the stack case, this would mean that if pool 2 had a priority of 10 and
pool 1 would have a priority of 5, pool 2 would be saturated first, then
pool 1.
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-03-14 20:04:34 +00:00
|
|
|
Jobs []WorkflowJob `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:SET NULL"`
|
|
|
|
|
PoolBalancerType params.PoolBalancerType `gorm:"type:varchar(64)"`
|
2024-04-15 08:32:19 +00:00
|
|
|
|
2024-07-29 17:35:57 +00:00
|
|
|
EndpointName *string `gorm:"index:idx_ent_name_nocase,collate:nocase"`
|
2024-04-15 08:32:19 +00:00
|
|
|
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
|
2025-04-16 16:39:16 +00:00
|
|
|
|
2025-05-22 18:43:32 +00:00
|
|
|
Events []EnterpriseEvent `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2022-10-13 16:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 20:29:58 +00:00
|
|
|
type Address struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
Address string
|
|
|
|
|
Type string
|
2022-05-03 19:49:14 +00:00
|
|
|
|
|
|
|
|
InstanceID uuid.UUID
|
|
|
|
|
Instance Instance `gorm:"foreignKey:InstanceID"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type InstanceStatusUpdate struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2022-12-29 16:49:50 +00:00
|
|
|
EventType params.EventType `gorm:"index:eventType"`
|
|
|
|
|
EventLevel params.EventLevel
|
|
|
|
|
Message string `gorm:"type:text"`
|
2022-05-03 19:49:14 +00:00
|
|
|
|
2023-06-28 21:52:50 +00:00
|
|
|
InstanceID uuid.UUID `gorm:"index:idx_instance_status_updates_instance_id"`
|
2023-06-28 14:50:59 +00:00
|
|
|
Instance Instance `gorm:"foreignKey:InstanceID"`
|
2022-04-26 20:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Instance struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2023-03-27 08:40:22 +00:00
|
|
|
ProviderID *string `gorm:"uniqueIndex"`
|
|
|
|
|
Name string `gorm:"uniqueIndex"`
|
|
|
|
|
AgentID int64
|
2023-07-21 15:30:22 +00:00
|
|
|
OSType commonParams.OSType
|
|
|
|
|
OSArch commonParams.OSArch
|
2023-03-27 08:40:22 +00:00
|
|
|
OSName string
|
|
|
|
|
OSVersion string
|
2023-06-28 21:52:50 +00:00
|
|
|
Addresses []Address `gorm:"foreignKey:InstanceID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2023-07-21 15:30:22 +00:00
|
|
|
Status commonParams.InstanceStatus
|
|
|
|
|
RunnerStatus params.RunnerStatus
|
2023-03-27 08:40:22 +00:00
|
|
|
CallbackURL string
|
|
|
|
|
MetadataURL string
|
|
|
|
|
ProviderFault []byte `gorm:"type:longblob"`
|
|
|
|
|
CreateAttempt int
|
|
|
|
|
TokenFetched bool
|
2023-08-18 06:09:44 +00:00
|
|
|
JitConfiguration []byte `gorm:"type:longblob"`
|
2023-03-27 08:40:22 +00:00
|
|
|
GitHubRunnerGroup string
|
2023-06-24 00:22:51 +00:00
|
|
|
AditionalLabels datatypes.JSON
|
2022-04-27 16:56:28 +00:00
|
|
|
|
2025-04-20 17:39:52 +00:00
|
|
|
PoolID *uuid.UUID
|
2022-04-27 16:56:28 +00:00
|
|
|
Pool Pool `gorm:"foreignKey:PoolID"`
|
2022-05-03 19:49:14 +00:00
|
|
|
|
2025-04-08 09:15:54 +00:00
|
|
|
ScaleSetFkID *uint
|
|
|
|
|
ScaleSet ScaleSet `gorm:"foreignKey:ScaleSetFkID"`
|
|
|
|
|
|
2023-06-28 21:52:50 +00:00
|
|
|
StatusMessages []InstanceStatusUpdate `gorm:"foreignKey:InstanceID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2023-08-26 19:43:57 +00:00
|
|
|
|
|
|
|
|
Job *WorkflowJob `gorm:"foreignKey:InstanceID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
|
2022-04-25 00:03:26 +00:00
|
|
|
}
|
2022-04-28 16:13:20 +00:00
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
|
Base
|
|
|
|
|
|
2024-07-02 22:26:12 +00:00
|
|
|
Username string `gorm:"uniqueIndex;varchar(64)"`
|
|
|
|
|
FullName string `gorm:"type:varchar(254)"`
|
|
|
|
|
Email string `gorm:"type:varchar(254);unique;index:idx_email"`
|
|
|
|
|
Password string `gorm:"type:varchar(60)"`
|
|
|
|
|
Generation uint
|
|
|
|
|
IsAdmin bool
|
|
|
|
|
Enabled bool
|
2022-04-28 16:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-10 00:03:49 +00:00
|
|
|
type WorkflowJob struct {
|
|
|
|
|
// ID is the ID of the job.
|
|
|
|
|
ID int64 `gorm:"index"`
|
2025-07-18 07:51:50 +00:00
|
|
|
|
|
|
|
|
// WorkflowJobID is the ID of the workflow job.
|
|
|
|
|
WorkflowJobID int64 `gorm:"index:workflow_job_id_idx"`
|
|
|
|
|
// ScaleSetJobID is the job ID for a scaleset job.
|
|
|
|
|
ScaleSetJobID string `gorm:"index:scaleset_job_id_idx"`
|
|
|
|
|
|
2023-04-10 00:03:49 +00:00
|
|
|
// RunID is the ID of the workflow run. A run may have multiple jobs.
|
|
|
|
|
RunID int64
|
|
|
|
|
// Action is the specific activity that triggered the event.
|
|
|
|
|
Action string `gorm:"type:varchar(254);index"`
|
|
|
|
|
// Conclusion is the outcome of the job.
|
|
|
|
|
// Possible values: "success", "failure", "neutral", "cancelled", "skipped",
|
|
|
|
|
// "timed_out", "action_required"
|
|
|
|
|
Conclusion string
|
|
|
|
|
// Status is the phase of the lifecycle that the job is currently in.
|
|
|
|
|
// "queued", "in_progress" and "completed".
|
|
|
|
|
Status string
|
|
|
|
|
// Name is the name if the job that was triggered.
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
|
StartedAt time.Time
|
|
|
|
|
CompletedAt time.Time
|
|
|
|
|
|
2023-08-26 19:43:57 +00:00
|
|
|
GithubRunnerID int64
|
|
|
|
|
|
|
|
|
|
InstanceID *uuid.UUID `gorm:"index:idx_instance_job"`
|
|
|
|
|
Instance Instance `gorm:"foreignKey:InstanceID"`
|
|
|
|
|
|
2023-04-10 00:03:49 +00:00
|
|
|
RunnerGroupID int64
|
|
|
|
|
RunnerGroupName string
|
|
|
|
|
|
|
|
|
|
// repository in which the job was triggered.
|
|
|
|
|
RepositoryName string
|
|
|
|
|
RepositoryOwner string
|
|
|
|
|
|
|
|
|
|
Labels datatypes.JSON
|
|
|
|
|
|
|
|
|
|
// The entity that received the hook.
|
|
|
|
|
//
|
|
|
|
|
// Webhooks may be configured on the repo, the org and/or the enterprise.
|
|
|
|
|
// If we only configure a repo to use garm, we'll only ever receive a
|
|
|
|
|
// webhook from the repo. But if we configure the parent org of the repo and
|
|
|
|
|
// the parent enterprise of the org to use garm, a webhook will be sent for each
|
|
|
|
|
// entity type, in response to one workflow event. Thus, we will get 3 webhooks
|
|
|
|
|
// with the same run_id and job id. Record all involved entities in the same job
|
|
|
|
|
// if we have them configured in garm.
|
2023-06-28 14:50:59 +00:00
|
|
|
RepoID *uuid.UUID `gorm:"index"`
|
2023-04-10 00:03:49 +00:00
|
|
|
Repository Repository `gorm:"foreignKey:RepoID"`
|
|
|
|
|
|
2023-06-28 14:50:59 +00:00
|
|
|
OrgID *uuid.UUID `gorm:"index"`
|
2023-04-10 00:03:49 +00:00
|
|
|
Organization Organization `gorm:"foreignKey:OrgID"`
|
|
|
|
|
|
2023-06-28 14:50:59 +00:00
|
|
|
EnterpriseID *uuid.UUID `gorm:"index"`
|
2023-04-10 00:03:49 +00:00
|
|
|
Enterprise Enterprise `gorm:"foreignKey:EnterpriseID"`
|
|
|
|
|
|
|
|
|
|
LockedBy uuid.UUID
|
|
|
|
|
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
|
|
|
}
|
2024-04-15 08:32:19 +00:00
|
|
|
|
|
|
|
|
type GithubEndpoint struct {
|
|
|
|
|
Name string `gorm:"type:varchar(64) collate nocase;primary_key;"`
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
|
|
|
|
2025-05-14 00:34:54 +00:00
|
|
|
EndpointType params.EndpointType `gorm:"index:idx_endpoint_type"`
|
2025-05-12 17:32:37 +00:00
|
|
|
|
2024-04-15 08:32:19 +00:00
|
|
|
Description string `gorm:"type:text"`
|
|
|
|
|
APIBaseURL string `gorm:"type:text collate nocase"`
|
|
|
|
|
UploadBaseURL string `gorm:"type:text collate nocase"`
|
|
|
|
|
BaseURL string `gorm:"type:text collate nocase"`
|
|
|
|
|
CACertBundle []byte `gorm:"type:longblob"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GithubCredentials struct {
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
|
|
|
|
Name string `gorm:"index:idx_github_credentials,unique;type:varchar(64) collate nocase"`
|
|
|
|
|
UserID *uuid.UUID `gorm:"index:idx_github_credentials,unique"`
|
|
|
|
|
User User `gorm:"foreignKey:UserID"`
|
|
|
|
|
|
2025-05-12 21:47:13 +00:00
|
|
|
Description string `gorm:"type:text"`
|
|
|
|
|
AuthType params.ForgeAuthType `gorm:"index"`
|
|
|
|
|
Payload []byte `gorm:"type:longblob"`
|
2024-04-15 08:32:19 +00:00
|
|
|
|
|
|
|
|
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"`
|
|
|
|
|
EndpointName *string `gorm:"index"`
|
|
|
|
|
|
|
|
|
|
Repositories []Repository `gorm:"foreignKey:CredentialsID"`
|
|
|
|
|
Organizations []Organization `gorm:"foreignKey:CredentialsID"`
|
|
|
|
|
Enterprises []Enterprise `gorm:"foreignKey:CredentialsID"`
|
|
|
|
|
}
|
2025-05-14 00:34:54 +00:00
|
|
|
|
|
|
|
|
type GiteaCredentials struct {
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
|
|
|
|
Name string `gorm:"index:idx_gitea_credentials,unique;type:varchar(64) collate nocase"`
|
|
|
|
|
UserID *uuid.UUID `gorm:"index:idx_gitea_credentials,unique"`
|
|
|
|
|
User User `gorm:"foreignKey:UserID"`
|
|
|
|
|
|
|
|
|
|
Description string `gorm:"type:text"`
|
|
|
|
|
AuthType params.ForgeAuthType `gorm:"index"`
|
|
|
|
|
Payload []byte `gorm:"type:longblob"`
|
|
|
|
|
|
|
|
|
|
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"`
|
|
|
|
|
EndpointName *string `gorm:"index"`
|
|
|
|
|
|
|
|
|
|
Repositories []Repository `gorm:"foreignKey:GiteaCredentialsID"`
|
|
|
|
|
Organizations []Organization `gorm:"foreignKey:GiteaCredentialsID"`
|
|
|
|
|
}
|