Skip to content

Commit

Permalink
complete some internal build settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Mar 20, 2024
1 parent df8c04d commit 92f8c04
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/handler/client/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func handleInfo() http.HandlerFunc {
}

data := &v1.Data{
Box: box,
Build: build,
Workflow: stage,
Status: status,
Expand Down
2 changes: 1 addition & 1 deletion core/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/api/core/v1/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 18 additions & 0 deletions pkg/api/core/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

package v1

import (
"maps"
"strconv"
)

type Build struct {
ID uint64 `json:"id" yaml:"id"`
BoxID uint64 `json:"boxID" yaml:"boxID"`
Expand All @@ -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"`
Expand Down

0 comments on commit 92f8c04

Please sign in to comment.