From 92f8c040b6cdfcfc9493e96dcdd66747ee6a39a3 Mon Sep 17 00:00:00 2001 From: zc Date: Wed, 20 Mar 2024 21:25:01 +0800 Subject: [PATCH] complete some internal build settings --- core/handler/client/handle.go | 1 + core/worker/worker.go | 2 +- pkg/api/core/v1/data.go | 1 + pkg/api/core/v1/status.go | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/handler/client/handle.go b/core/handler/client/handle.go index 6dfcc0b..bb093f2 100644 --- a/core/handler/client/handle.go +++ b/core/handler/client/handle.go @@ -173,6 +173,7 @@ func handleInfo() http.HandlerFunc { } data := &v1.Data{ + Box: box, Build: build, Workflow: stage, Status: status, diff --git a/core/worker/worker.go b/core/worker/worker.go index e249764..7c1ef98 100644 --- a/core/worker/worker.go +++ b/core/worker/worker.go @@ -154,7 +154,7 @@ func Run(ctx context.Context, client clients.WorkerV1, hook Hook) error { var settings map[string]string if data.Build != nil { - settings = data.Build.Settings + settings = data.Build.CompleteSettings(data.Box) } ctx = wslog.WithContext(ctx, log) diff --git a/pkg/api/core/v1/data.go b/pkg/api/core/v1/data.go index 5fc0407..3665861 100644 --- a/pkg/api/core/v1/data.go +++ b/pkg/api/core/v1/data.go @@ -15,6 +15,7 @@ package v1 type Data struct { + Box *Box `json:"box,omitempty"` Build *Build `json:"build,omitempty"` Workflow *Workflow `json:"workflow,omitempty"` Status *Stage `json:"status,omitempty"` diff --git a/pkg/api/core/v1/status.go b/pkg/api/core/v1/status.go index 427be50..9a073ba 100644 --- a/pkg/api/core/v1/status.go +++ b/pkg/api/core/v1/status.go @@ -14,6 +14,11 @@ package v1 +import ( + "maps" + "strconv" +) + type Build struct { ID uint64 `json:"id" yaml:"id"` BoxID uint64 `json:"boxID" yaml:"boxID"` @@ -28,6 +33,19 @@ type Build struct { Stages []*Stage `json:"stages,omitempty" yaml:"stages,omitempty"` } +func (b *Build) CompleteSettings(box *Box) map[string]string { + settings := make(map[string]string) + maps.Copy(settings, b.Settings) + + if box != nil { + settings["DYNASTY_BOX_NAME"] = box.Name + settings["DYNASTY_BOX_NAMESPACE"] = box.Namespace + } + settings["DYNASTY_BUILD_NUMBER"] = strconv.FormatUint(b.Number, 10) + + return settings +} + type Stage struct { ID uint64 `json:"id" yaml:"id"` BoxID uint64 `json:"boxID" yaml:"boxID"`