@@ -3,7 +3,7 @@ package build
3
3
import (
4
4
"fmt"
5
5
6
- buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1 "
6
+ buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1 "
7
7
"github.com/spf13/cobra"
8
8
9
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -18,8 +18,11 @@ import (
18
18
type CreateCommand struct {
19
19
cmd * cobra.Command // cobra command instance
20
20
21
- name string // build resource's name
22
- buildSpec * buildv1alpha1.BuildSpec // stores command-line flags
21
+ name string // build resource's name
22
+ buildSpec * buildv1beta1.BuildSpec // stores command-line flags
23
+ dockerfile * string // For dockerfile parameter
24
+ builderImage * string // For builder image parameter
25
+
23
26
}
24
27
25
28
const buildCreateLongDesc = `
@@ -54,7 +57,7 @@ func (c *CreateCommand) Validate() error {
54
57
55
58
// Run executes the creation of a new Build instance using flags to fill up the details.
56
59
func (c * CreateCommand ) Run (params * params.Params , io * genericclioptions.IOStreams ) error {
57
- b := & buildv1alpha1 .Build {
60
+ b := & buildv1beta1 .Build {
58
61
ObjectMeta : metav1.ObjectMeta {
59
62
Name : c .name ,
60
63
},
@@ -63,16 +66,44 @@ func (c *CreateCommand) Run(params *params.Params, io *genericclioptions.IOStrea
63
66
64
67
flags .SanitizeBuildSpec (& b .Spec )
65
68
66
- // print warning with regards to source bundle image being used
67
- if b .Spec .Source .BundleContainer != nil && b .Spec .Source .BundleContainer .Image != "" {
68
- fmt .Fprintf (io .Out , "Build %q uses a source bundle image, which means source code will be transferred to a container registry. It is advised to use private images to ensure the security of the source code being uploaded.\n " , c .name )
69
+ if b .Spec .Source != nil {
70
+ if b .Spec .Source .OCIArtifact != nil && b .Spec .Source .OCIArtifact .Image != "" {
71
+ b .Spec .Source .Type = buildv1beta1 .OCIArtifactType
72
+ } else if b .Spec .Source .Git != nil && b .Spec .Source .Git .URL != "" {
73
+ b .Spec .Source .Type = buildv1beta1 .GitType
74
+ }
75
+
76
+ // print warning with regards to source bundle image being used
77
+ if b .Spec .Source .OCIArtifact != nil && b .Spec .Source .OCIArtifact .Image != "" {
78
+ fmt .Fprintf (io .Out , "Build %q uses a source bundle image, which means source code will be transferred to a container registry. It is advised to use private images to ensure the security of the source code being uploaded.\n " , c .name )
79
+ }
80
+ }
81
+
82
+ if c .dockerfile != nil && * c .dockerfile != "" {
83
+ dockerfileParam := buildv1beta1.ParamValue {
84
+ Name : "dockerfile" ,
85
+ SingleValue : & buildv1beta1.SingleValue {
86
+ Value : c .dockerfile ,
87
+ },
88
+ }
89
+ c .buildSpec .ParamValues = append (c .buildSpec .ParamValues , dockerfileParam )
90
+ }
91
+
92
+ if c .builderImage != nil && * c .builderImage != "" {
93
+ builderParam := buildv1beta1.ParamValue {
94
+ Name : "builder-image" ,
95
+ SingleValue : & buildv1beta1.SingleValue {
96
+ Value : c .builderImage ,
97
+ },
98
+ }
99
+ c .buildSpec .ParamValues = append (c .buildSpec .ParamValues , builderParam )
69
100
}
70
101
71
102
clientset , err := params .ShipwrightClientSet ()
72
103
if err != nil {
73
104
return err
74
105
}
75
- if _ , err := clientset .ShipwrightV1alpha1 ().Builds (params .Namespace ()).Create (c .cmd .Context (), b , metav1.CreateOptions {}); err != nil {
106
+ if _ , err := clientset .ShipwrightV1beta1 ().Builds (params .Namespace ()).Create (c .cmd .Context (), b , metav1.CreateOptions {}); err != nil {
76
107
return err
77
108
}
78
109
fmt .Fprintf (io .Out , "Created build %q\n " , c .name )
@@ -89,13 +120,15 @@ func createCmd() runner.SubCommand {
89
120
90
121
// instantiating command-line flags and the build-spec structure which receives the informed flag
91
122
// values, also marking certain flags as mandatory
92
- buildSpecFlags := flags .BuildSpecFromFlags (cmd .Flags ())
123
+ buildSpecFlags , dockerfileFlag , builderImageFlag := flags .BuildSpecFromFlags (cmd .Flags ())
93
124
if err := cmd .MarkFlagRequired (flags .OutputImageFlag ); err != nil {
94
125
panic (err )
95
126
}
96
127
97
128
return & CreateCommand {
98
- cmd : cmd ,
99
- buildSpec : buildSpecFlags ,
129
+ cmd : cmd ,
130
+ buildSpec : buildSpecFlags ,
131
+ dockerfile : dockerfileFlag ,
132
+ builderImage : builderImageFlag ,
100
133
}
101
134
}
0 commit comments