@@ -22,7 +22,6 @@ import (
2222 "fmt"
2323 "os"
2424 "os/exec"
25- "path"
2625 "path/filepath"
2726 "runtime"
2827 "strings"
@@ -54,74 +53,78 @@ func (k *kindCluster) buildCliImage(ctx context.Context) error {
5453// only the task of a particular version. The image reference to the ec-cli
5554// image is replaced with the image reference from buildCliImage.
5655func (k * kindCluster ) buildTaskBundleImage (ctx context.Context ) error {
57- versions , err := filepath .Glob (path .Join ("tasks/verify-enterprise-contract" , "*.*" ))
56+ taskBundles := make (map [string ][]string )
57+
58+ basePath := "tasks/"
59+ taskDirs , err := os .ReadDir (basePath )
5860 if err != nil {
5961 return err
6062 }
6163
62- for _ , version := range versions {
63- if info , err := os .Stat (version ); err != nil {
64- return err
65- } else if ! info .IsDir () {
64+ for _ , task := range taskDirs {
65+ if ! task .IsDir () {
6666 continue
6767 }
68-
69- // we expect a file called `verify-enterprise-contract.yaml` in each
70- // version containing the Tekton Task definition
71- taskFile := path .Join (version , "verify-enterprise-contract.yaml" )
72-
73- if info , err := os .Stat (taskFile ); err != nil {
74- if errors .Is (err , os .ErrNotExist ) {
75- continue
76- }
77-
68+ // once all the directories under tasks/ are collected, gather all the versions
69+ versions , err := filepath .Glob (filepath .Join (basePath , task .Name (), "*.*" ))
70+ if err != nil {
7871 return err
79- } else if info .IsDir () {
80- continue
8172 }
73+ for _ , versionPath := range versions {
74+ pathSplit := strings .Split (versionPath , "/" )
75+ // there should only be versions under the task path i.e. tasks/verify-definition/0.1
76+ version := pathSplit [len (pathSplit )- 1 ]
77+ // assume the task definition file is named the same as the task directory
78+ fileName := filepath .Join (versionPath , fmt .Sprintf ("%s.yaml" , task .Name ()))
79+ if _ , err := os .Stat (fileName ); err != nil {
80+ if errors .Is (err , os .ErrNotExist ) {
81+ continue
82+ }
83+ return err
84+ }
85+ var bytes []byte
86+ if bytes , err = os .ReadFile (fileName ); err != nil {
87+ return err
88+ }
8289
83- var bytes [] byte
84- if bytes , err = os . ReadFile ( taskFile ); err != nil {
85- return err
86- }
90+ var taskDefinition v1beta1. Task
91+ if err := yaml . Unmarshal ( bytes , & taskDefinition ); err != nil {
92+ return err
93+ }
8794
88- var taskDefinition v1beta1.Task
89- if err := yaml .Unmarshal (bytes , & taskDefinition ); err != nil {
90- return err
91- }
95+ // using registry.image-registry.svc.cluster.local instead of 127.0.0.1
96+ // leads to "dial tcp: lookup registry.image-registry.svc.cluster.local:
97+ // Temporary failure in name resolution" in Tekton Pipeline controller
98+ img := fmt .Sprintf ("127.0.0.1:%d/ec-cli:latest-%s-%s" , k .registryPort , runtime .GOOS , runtime .GOARCH )
99+ steps := taskDefinition .Spec .Steps
100+ for i , step := range steps {
101+ if strings .Contains (step .Image , "/ec-cli:" ) {
102+ steps [i ].Image = img
103+ }
104+ }
92105
93- // using registry.image-registry.svc.cluster.local instead of 127.0.0.1
94- // leads to "dial tcp: lookup registry.image-registry.svc.cluster.local:
95- // Temporary failure in name resolution" in Tekton Pipeline controller
96- img := fmt .Sprintf ("127.0.0.1:%d/ec-cli:latest-%s-%s" , k .registryPort , runtime .GOOS , runtime .GOARCH )
97- steps := taskDefinition .Spec .Steps
98- for i , step := range steps {
99- if strings .Contains (step .Image , "/ec-cli:" ) {
100- steps [i ].Image = img
106+ out , err := yaml .Marshal (taskDefinition )
107+ if err != nil {
108+ return err
101109 }
102- }
103110
104- out , err := yaml .Marshal (taskDefinition )
105- if err != nil {
106- return err
107- }
111+ task , err := os .CreateTemp ("" , "v-e-c-*.yaml" )
112+ if err != nil {
113+ return err
114+ }
115+ defer os .Remove (task .Name ())
108116
109- task , err := os .CreateTemp ("" , "v-e-c-*.yaml" )
110- if err != nil {
111- return err
112- }
113- defer os .Remove (task .Name ())
117+ if _ , err = task .Write (out ); err != nil {
118+ return err
119+ }
114120
115- if _ , err = task .Write (out ); err != nil {
116- return err
121+ taskBundles [version ] = append (taskBundles [version ], task .Name ())
117122 }
123+ }
118124
119- // given a path like task/0.1 is `0.1` which gives us the version of the
120- // Task by the directory layout convention for the Tekton/Artifact Hub
121- ver := path .Base (version )
122-
123- cmd := exec .CommandContext (ctx , "make" , "task-bundle" , fmt .Sprintf ("TASK_REPO=localhost:%d/ec-task-bundle" , k .registryPort ), fmt .Sprintf ("TASK=%s" , task .Name ()), fmt .Sprintf ("TASK_TAG=%s" , ver ))
124-
125+ for version , tasks := range taskBundles {
126+ tasksPath := strings .Join (tasks , "," )
127+ cmd := exec .CommandContext (ctx , "make" , "task-bundle" , fmt .Sprintf ("TASK_REPO=localhost:%d/ec-task-bundle" , k .registryPort ), fmt .Sprintf ("TASK=%s" , tasksPath ), fmt .Sprintf ("TASK_TAG=%s" , version ))
125128 if out , err := cmd .CombinedOutput (); err != nil {
126129 fmt .Print (string (out ))
127130 return err
0 commit comments