Move SCUM lifecycle ownership to plugin

This commit is contained in:
npc0-hue
2026-08-01 09:36:12 +08:00
parent bca4f935ba
commit d1249fca85
49 changed files with 795 additions and 566 deletions
@@ -1,6 +1,8 @@
package service
import (
"encoding/base64"
"encoding/json"
"errors"
"strings"
@@ -122,12 +124,17 @@ func (svc *CoreService) platformDistributionBuildInput(job domain.Job) (domain.D
if err != nil {
return domain.DistributionBuildInput{}, err
}
profileKey, workspaceSeed, err := svc.runDistributionWorkspaceSeed(distribution)
if err != nil {
return domain.DistributionBuildInput{}, err
}
return domain.DistributionBuildInput{
JobID: job.ID,
ComponentKind: domain.DistributionComponentRun,
ServerInstanceID: distribution.ServerInstanceID,
PluginID: distribution.PluginID,
RunEndpointID: distribution.RunEndpointID,
ProfileKey: profileKey,
TargetOS: distribution.TargetOS,
TargetArch: distribution.TargetArch,
TargetRelease: distribution.ID,
@@ -138,6 +145,7 @@ func (svc *CoreService) platformDistributionBuildInput(job domain.Job) (domain.D
SecretRef: distribution.SecretRef,
KeyGeneration: distribution.KeyGeneration,
AuthKey: plainKey,
WorkspaceSeed: workspaceSeed,
}, nil
}
@@ -183,6 +191,48 @@ func (svc *CoreService) platformDistributionBuildInput(job domain.Job) (domain.D
return domain.DistributionBuildInput{}, repo.ErrNotFound
}
func (svc *CoreService) runDistributionWorkspaceSeed(distribution domain.RunDistribution) (string, string, error) {
instance, err := svc.store.ServerInstances().Get(distribution.ServerInstanceID)
if err != nil {
return "", "", err
}
plugin, err := svc.store.GamePlugins().Get(distribution.PluginID)
if err != nil {
return "", "", err
}
seed, err := encodePluginWorkspaceSeed(plugin.LifecycleAssets)
if err != nil {
return "", "", err
}
profileKey := instance.Deployment.ProfileKey
if binding, bindingErr := svc.runtimeBindingForServer(distribution.ServerInstanceID); bindingErr == nil {
profileKey = binding.ProfileKey
} else if !errors.Is(bindingErr, repo.ErrNotFound) {
return "", "", bindingErr
}
return profileKey, seed, nil
}
func encodePluginWorkspaceSeed(files []domain.PluginAssetFile) (string, error) {
if len(files) == 0 {
return "", nil
}
type seedFile struct {
Path string `json:"path"`
Content string `json:"content"`
Mode int `json:"mode,omitempty"`
}
seed := make([]seedFile, len(files))
for i, file := range files {
seed[i] = seedFile{Path: file.Path, Content: file.Content, Mode: file.Mode}
}
body, err := json.Marshal(seed)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(body), nil
}
// storeDistributionBuildArtifact records the built package under job ownership
// so the existing ArtifactOwnerKindJob scope assertions keep guarding it.
func (svc *CoreService) storeDistributionBuildArtifact(artifactID string, jobID string, payload []byte) error {