From c6eb25f39faaa7d15bfda3c3218fc185621dc439 Mon Sep 17 00:00:00 2001 From: zc Date: Wed, 10 Jan 2024 20:10:10 +0800 Subject: [PATCH] fixed the problem of incorrect number of generated stages for resource in the box --- Makefile | 2 +- core/service/build/build.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 934562d..bef69d5 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ packages = `go list ./... | grep -v github.com/zc2638/ink/test` build-%: @CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix cgo -o _output/$* ./cmd/$* -docker-build-%: build-% +docker-build-%: @docker build -t zc2638/$* -f docker/$*.dockerfile . docker-tag-%: diff --git a/core/service/build/build.go b/core/service/build/build.go index 86a0aac..44a86e1 100644 --- a/core/service/build/build.go +++ b/core/service/build/build.go @@ -154,15 +154,27 @@ func (s *srv) Create(ctx context.Context, namespace, name string, settings map[s return 0, err } + workflowNames := make([]string, 0, len(box.Resources)) + for _, v := range box.Resources { + if v.Kind != v1.KindWorkflow { + continue + } + workflowNames = append(workflowNames, v.Name) + } + if len(workflowNames) == 0 { + return 0, errors.New("workflow resource not found") + } + err = db.Transaction(func(tx *gorm.DB) error { if err := tx.Create(&buildS).Error; err != nil { return err } - for k, v := range box.Resources { + for k, v := range workflowNames { + sd := &storageV1.Workflow{ Namespace: box.Namespace, - Name: v.Name, + Name: v, } if err := tx.Where(sd).First(sd).Error; err != nil { return err