2
0
Эх сурвалжийг харах

[POR-1990] add app instance table; reference app instance id in app revision; add vanity name and metadata to deployment target (#3841)

Co-authored-by: David Townley <davidtownley@Davids-MacBook-Air.local>
d-g-town 2 жил өмнө
parent
commit
1f7e999045

+ 7 - 5
Tiltfile

@@ -2,15 +2,17 @@ load('ext://restart_process', 'docker_build_with_restart')
 
 
 secret_settings(disable_scrub=True)
 secret_settings(disable_scrub=True)
 
 
-if not os.path.exists("vendor"):
-    local(command="go mod vendor")
-
 if config.tilt_subcommand == "up":
 if config.tilt_subcommand == "up":
+    if not os.path.exists("vendor"):
+        local(command="go mod vendor")
+
     local(command="cd dashboard; npm i --legacy-peer-deps")
     local(command="cd dashboard; npm i --legacy-peer-deps")
 
 
 if config.tilt_subcommand == "down":
 if config.tilt_subcommand == "down":
-    local(command="rm -rf vendor")
-    local(command="rm -rf dashboard/node_modules")
+    if os.path.exists("vendor"):
+        local(command="rm -rf vendor")
+    if os.path.exists("dashboard/node_modules"):
+        local(command="rm -rf dashboard/node_modules")
 
 
 build_args = "GOOS=linux GOARCH=arm64"
 build_args = "GOOS=linux GOARCH=arm64"
 if os.getenv("PLATFORM") == "amd64":
 if os.getenv("PLATFORM") == "amd64":

+ 31 - 0
internal/models/app_instance.go

@@ -0,0 +1,31 @@
+package models
+
+import (
+	"time"
+
+	"github.com/google/uuid"
+	"gorm.io/gorm"
+)
+
+// AppInstance extends gorm.Model to represent an instance of an app (source information + deployment target)
+type AppInstance struct {
+	gorm.Model
+
+	// ID is a unique identifier for a given app instance
+	ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
+	// Name is the name of the app instance. This is unique across a given deployment target
+	Name string `json:"name"  gorm:"uniqueIndex:idx_name_deployment_target"`
+	// ProjectID is the ID of the project that the app instance belongs to
+	ProjectID uint `json:"project_id"`
+	// CreatedAt is the time (UTC) that a given app instance was created. This should not change
+	CreatedAt time.Time `json:"created_at"`
+	// UpdatedAt is the time (UTC) that an app instance was last updated.
+	UpdatedAt time.Time `json:"updated_at"`
+	// PorterAppID is the ID of the app (source information) that the given app instance relates to
+	PorterAppID uint `json:"porter_app_id"`
+	// DeploymentTargetID is the ID of the deployment target that the event relates to
+	DeploymentTargetID uuid.UUID `json:"deployment_target_id" gorm:"uniqueIndex:idx_name_deployment_target;type:uuid"`
+
+	// PorterYamlPath is the path to the porter.yaml file in the git repo
+	PorterYamlPath string
+}

+ 4 - 1
internal/models/app_revision.go

@@ -47,9 +47,12 @@ type AppRevision struct {
 	// ProjectID is the ID of the project that the revision belongs to.
 	// ProjectID is the ID of the project that the revision belongs to.
 	ProjectID int `json:"project_id"`
 	ProjectID int `json:"project_id"`
 
 
-	// PorterAppID is the ID of the PorterApp that the revision belongs to.
+	// PorterAppID is the ID of the PorterApp that the revision belongs to. This will be deprecated in favor of AppInstanceID (tracking: POR-1992)
 	PorterAppID int `json:"porter_app_id"`
 	PorterAppID int `json:"porter_app_id"`
 
 
 	// RevisionNumber is the number of the revision respective to that porter_app_id and deployment_target_id
 	// RevisionNumber is the number of the revision respective to that porter_app_id and deployment_target_id
 	RevisionNumber int `json:"revision_number"`
 	RevisionNumber int `json:"revision_number"`
+
+	// AppInstanceID is the ID of the AppInstance that the revision belongs to. This will be null while the app instance table is being seeded (tracking: POR-1991)
+	AppInstanceID uuid.UUID `json:"app_instance_id" gorm:"type:uuid;default:00000000-0000-0000-0000-000000000000"`
 }
 }

+ 6 - 0
internal/models/deployment_target.go

@@ -27,6 +27,9 @@ type DeploymentTarget struct {
 	// ProjectID is the ID of the project that the target belongs to.
 	// ProjectID is the ID of the project that the target belongs to.
 	ProjectID int `json:"project_id"`
 	ProjectID int `json:"project_id"`
 
 
+	// VanityName is a human-readable name for the deployment target.  It will be unique within a project once all existing deployment targets have been backfilled (tracking: POR-1991)
+	VanityName string `json:"vanity_name" gorm:"default:''"`
+
 	// Selector is the identifier to target.
 	// Selector is the identifier to target.
 	Selector string `json:"selector"`
 	Selector string `json:"selector"`
 
 
@@ -35,6 +38,9 @@ type DeploymentTarget struct {
 
 
 	// Preview is a boolean indicating whether this target is a preview target.
 	// Preview is a boolean indicating whether this target is a preview target.
 	Preview bool `gorm:"default:false" json:"preview"`
 	Preview bool `gorm:"default:false" json:"preview"`
+
+	// Metadata is a JSONB column that stores arbitrary metadata about the deployment target
+	Metadata JSONB `json:"metadata" sql:"type:jsonb" gorm:"type:jsonb;default:'{}'"`
 }
 }
 
 
 // ToDeploymentTargetType generates an external types.PorterApp to be shared over REST
 // ToDeploymentTargetType generates an external types.PorterApp to be shared over REST

+ 1 - 0
internal/repository/gorm/migrate.go

@@ -63,6 +63,7 @@ func AutoMigrate(db *gorm.DB, debug bool) error {
 		&models.PorterApp{},
 		&models.PorterApp{},
 		&models.PorterAppEvent{},
 		&models.PorterAppEvent{},
 		&models.AppRevision{},
 		&models.AppRevision{},
+		&models.AppInstance{},
 		&models.DeploymentTarget{},
 		&models.DeploymentTarget{},
 		&models.AppTemplate{},
 		&models.AppTemplate{},
 		&models.GithubWebhook{},
 		&models.GithubWebhook{},