Skip to content

Commit 0fe28ba

Browse files
Merge pull request #304 from karanibm6/update-cli-params
add cli changes to move to v1beta1
2 parents ccc97a3 + 0afb42b commit 0fe28ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+571
-505
lines changed

docs/shp_build_create.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,25 @@ shp build create <name> [flags]
1717
### Options
1818

1919
```
20-
--builder-credentials-secret string name of the secret with builder-image pull credentials
21-
--builder-image string image employed during the building process
22-
--dockerfile string path to dockerfile relative to repository
2320
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
2421
-h, --help help for create
25-
--output-credentials-secret string name of the secret with builder-image pull credentials
2622
--output-image string image employed during the building process
2723
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2824
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
25+
--output-image-push-secret string name of the secret with output image push credentials
2926
--output-insecure flag to indicate an insecure container registry
3027
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
3128
--retention-failed-limit uint number of failed BuildRuns to be kept (default 65535)
3229
--retention-succeeded-limit uint number of succeeded BuildRuns to be kept (default 65535)
3330
--retention-ttl-after-failed duration duration to delete a failed BuildRun after completion
3431
--retention-ttl-after-succeeded duration duration to delete a succeeded BuildRun after completion
35-
--source-bundle-image string source bundle image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
36-
--source-bundle-prune pruneOption source bundle prune option, either Never, or AfterPull (default Never)
3732
--source-context-dir string use a inner directory as context directory
38-
--source-credentials-secret string name of the secret with credentials to access the source, e.g. git or registry credentials
39-
--source-revision string git repository source revision
40-
--source-url string git repository source URL
41-
--strategy-apiversion string kubernetes api-version of the build-strategy resource (default "v1alpha1")
33+
--source-git-clone-secret string name of the secret with credentials to access the git source, e.g. git credentials
34+
--source-git-revision string git repository source revision
35+
--source-git-url string git repository source URL
36+
--source-oci-artifact-image string source OCI artifact image reference, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
37+
--source-oci-artifact-prune pruneOption source OCI artifact image prune option, either Never, or AfterPull (default Never)
38+
--source-oci-artifact-pull-secret string name of the secret with credentials to access the OCI artifact image, e.g. registry credentials
4239
--strategy-kind string build-strategy kind (default "ClusterBuildStrategy")
4340
--strategy-name string build-strategy name (default "buildpacks-v3")
4441
--timeout duration build process timeout

docs/shp_build_run.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ shp build run <name> [flags]
1818
### Options
1919

2020
```
21-
--buildref-apiversion string API version of build resource to reference
2221
--buildref-name string name of build resource to reference
2322
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
2423
-F, --follow Start a build and watch its log until it completes or fails.
2524
-h, --help help for run
26-
--output-credentials-secret string name of the secret with builder-image pull credentials
2725
--output-image string image employed during the building process
2826
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2927
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
28+
--output-image-push-secret string name of the secret with output image push credentials
3029
--output-insecure flag to indicate an insecure container registry
3130
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
3231
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
3332
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
34-
--sa-generate generate a Kubernetes service-account for the build
3533
--sa-name string Kubernetes service-account name
3634
--timeout duration build process timeout
3735
```

docs/shp_build_upload.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,18 @@ shp build upload <build-name> [path/to/source|.] [flags]
2828
### Options
2929

3030
```
31-
--buildref-apiversion string API version of build resource to reference
3231
--buildref-name string name of build resource to reference
3332
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
3433
-F, --follow Start a build and watch its log until it completes or fails.
3534
-h, --help help for upload
36-
--output-credentials-secret string name of the secret with builder-image pull credentials
3735
--output-image string image employed during the building process
3836
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
3937
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
38+
--output-image-push-secret string name of the secret with output image push credentials
4039
--output-insecure flag to indicate an insecure container registry
4140
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
4241
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
4342
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
44-
--sa-generate generate a Kubernetes service-account for the build
4543
--sa-name string Kubernetes service-account name
4644
--timeout duration build process timeout
4745
```

docs/shp_buildrun_create.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ shp buildrun create <name> [flags]
1818
### Options
1919

2020
```
21-
--buildref-apiversion string API version of build resource to reference
2221
--buildref-name string name of build resource to reference
2322
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
2423
-h, --help help for create
25-
--output-credentials-secret string name of the secret with builder-image pull credentials
2624
--output-image string image employed during the building process
2725
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2826
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
27+
--output-image-push-secret string name of the secret with output image push credentials
2928
--output-insecure flag to indicate an insecure container registry
3029
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
3130
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
3231
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
33-
--sa-generate generate a Kubernetes service-account for the build
3432
--sa-name string Kubernetes service-account name
3533
--timeout duration build process timeout
3634
```

pkg/shp/bundle/bundle.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
v1 "github.com/google/go-containerregistry/pkg/v1"
1212
"github.com/google/go-containerregistry/pkg/v1/remote"
1313
progressbar "github.com/schollz/progressbar/v3"
14-
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
14+
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
1515
buildbundle "github.com/shipwright-io/build/pkg/bundle"
1616
buildclientset "github.com/shipwright-io/build/pkg/client/clientset/versioned"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -20,21 +20,22 @@ import (
2020
// GetSourceBundleImage returns the source bundle image of the build that is
2121
// associated with the provided buildrun, an empty string if source bundle is
2222
// not used, or an error in case the build cannot be obtained
23-
func GetSourceBundleImage(ctx context.Context, client buildclientset.Interface, buildRun *buildv1alpha1.BuildRun) (string, error) {
23+
func GetSourceBundleImage(ctx context.Context, client buildclientset.Interface, buildRun *buildv1beta1.BuildRun) (string, error) {
2424
if buildRun == nil {
2525
return "", fmt.Errorf("no buildrun provided, given reference is nil")
2626
}
2727

28-
if buildRun.Spec.BuildRef != nil {
29-
name, namespace := buildRun.Spec.BuildRef.Name, buildRun.Namespace
28+
if buildRun.Spec.Build.Name != nil && *buildRun.Spec.Build.Name != "" {
29+
name, namespace := buildRun.Spec.Build.Name, buildRun.Namespace
3030

31-
build, err := client.ShipwrightV1alpha1().Builds(namespace).Get(ctx, name, metav1.GetOptions{})
31+
build, err := client.ShipwrightV1beta1().Builds(namespace).Get(ctx, *name, metav1.GetOptions{})
3232
if err != nil {
3333
return "", err
3434
}
35-
36-
if build.Spec.Source.BundleContainer != nil && build.Spec.Source.BundleContainer.Image != "" {
37-
return build.Spec.Source.BundleContainer.Image, nil
35+
if build.Spec.Source != nil {
36+
if build.Spec.Source.OCIArtifact != nil && build.Spec.Source.OCIArtifact.Image != "" {
37+
return build.Spec.Source.OCIArtifact.Image, nil
38+
}
3839
}
3940
}
4041

pkg/shp/cmd/build/create.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package build
33
import (
44
"fmt"
55

6-
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
6+
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
77
"github.com/spf13/cobra"
88

99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -18,8 +18,11 @@ import (
1818
type CreateCommand struct {
1919
cmd *cobra.Command // cobra command instance
2020

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+
2326
}
2427

2528
const buildCreateLongDesc = `
@@ -54,7 +57,7 @@ func (c *CreateCommand) Validate() error {
5457

5558
// Run executes the creation of a new Build instance using flags to fill up the details.
5659
func (c *CreateCommand) Run(params *params.Params, io *genericclioptions.IOStreams) error {
57-
b := &buildv1alpha1.Build{
60+
b := &buildv1beta1.Build{
5861
ObjectMeta: metav1.ObjectMeta{
5962
Name: c.name,
6063
},
@@ -63,16 +66,44 @@ func (c *CreateCommand) Run(params *params.Params, io *genericclioptions.IOStrea
6366

6467
flags.SanitizeBuildSpec(&b.Spec)
6568

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)
69100
}
70101

71102
clientset, err := params.ShipwrightClientSet()
72103
if err != nil {
73104
return err
74105
}
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 {
76107
return err
77108
}
78109
fmt.Fprintf(io.Out, "Created build %q\n", c.name)
@@ -89,13 +120,15 @@ func createCmd() runner.SubCommand {
89120

90121
// instantiating command-line flags and the build-spec structure which receives the informed flag
91122
// values, also marking certain flags as mandatory
92-
buildSpecFlags := flags.BuildSpecFromFlags(cmd.Flags())
123+
buildSpecFlags, dockerfileFlag, builderImageFlag := flags.BuildSpecFromFlags(cmd.Flags())
93124
if err := cmd.MarkFlagRequired(flags.OutputImageFlag); err != nil {
94125
panic(err)
95126
}
96127

97128
return &CreateCommand{
98-
cmd: cmd,
99-
buildSpec: buildSpecFlags,
129+
cmd: cmd,
130+
buildSpec: buildSpecFlags,
131+
dockerfile: dockerfileFlag,
132+
builderImage: builderImageFlag,
100133
}
101134
}

pkg/shp/cmd/build/delete.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package build
33
import (
44
"fmt"
55

6-
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
6+
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
77
"github.com/spf13/cobra"
88

99
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -58,20 +58,20 @@ func (c *DeleteCommand) Run(params *params.Params, io *genericclioptions.IOStrea
5858
if err != nil {
5959
return err
6060
}
61-
if err := clientset.ShipwrightV1alpha1().Builds(params.Namespace()).Delete(c.Cmd().Context(), c.name, v1.DeleteOptions{}); err != nil {
61+
if err := clientset.ShipwrightV1beta1().Builds(params.Namespace()).Delete(c.Cmd().Context(), c.name, v1.DeleteOptions{}); err != nil {
6262
return err
6363
}
6464

6565
if c.deleteRuns {
66-
var brList *buildv1alpha1.BuildRunList
67-
if brList, err = clientset.ShipwrightV1alpha1().BuildRuns(params.Namespace()).List(c.cmd.Context(), v1.ListOptions{
68-
LabelSelector: fmt.Sprintf("%v/name=%v", buildv1alpha1.BuildDomain, c.name),
66+
var brList *buildv1beta1.BuildRunList
67+
if brList, err = clientset.ShipwrightV1beta1().BuildRuns(params.Namespace()).List(c.cmd.Context(), v1.ListOptions{
68+
LabelSelector: fmt.Sprintf("%v/name=%v", buildv1beta1.BuildDomain, c.name),
6969
}); err != nil {
7070
return err
7171
}
7272

7373
for _, buildrun := range brList.Items {
74-
if err := clientset.ShipwrightV1alpha1().BuildRuns(params.Namespace()).Delete(c.cmd.Context(), buildrun.Name, v1.DeleteOptions{}); err != nil {
74+
if err := clientset.ShipwrightV1beta1().BuildRuns(params.Namespace()).Delete(c.cmd.Context(), buildrun.Name, v1.DeleteOptions{}); err != nil {
7575
fmt.Fprintf(io.ErrOut, "Error deleting BuildRun %q: %v\n", buildrun.Name, err)
7676
}
7777
}

pkg/shp/cmd/build/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"text/tabwriter"
66

7-
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
7+
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
88
"github.com/shipwright-io/cli/pkg/shp/cmd/runner"
99
"github.com/shipwright-io/cli/pkg/shp/params"
1010
"github.com/spf13/cobra"
@@ -59,7 +59,7 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
5959
columnNames := "NAME\tOUTPUT\tSTATUS"
6060
columnTemplate := "%s\t%s\t%s\n"
6161

62-
var buildList *buildv1alpha1.BuildList
62+
var buildList *buildv1beta1.BuildList
6363
clientset, err := params.ShipwrightClientSet()
6464
if err != nil {
6565
return err
@@ -78,7 +78,7 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
7878
return err
7979
}
8080

81-
if buildList, err = clientset.ShipwrightV1alpha1().Builds(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
81+
if buildList, err = clientset.ShipwrightV1beta1().Builds(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
8282
return err
8383
}
8484
if len(buildList.Items) == 0 {

pkg/shp/cmd/build/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
7+
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
88
"github.com/shipwright-io/cli/pkg/shp/cmd/follower"
99
"github.com/shipwright-io/cli/pkg/shp/cmd/runner"
1010
"github.com/shipwright-io/cli/pkg/shp/flags"
@@ -24,8 +24,8 @@ type RunCommand struct {
2424

2525
buildName string
2626
namespace string
27-
buildRunSpec *buildv1alpha1.BuildRunSpec // stores command-line flags
28-
follow bool // flag to tail pod logs
27+
buildRunSpec *buildv1beta1.BuildRunSpec // stores command-line flags
28+
follow bool // flag to tail pod logs
2929
follower *follower.Follower
3030
followerReady chan bool
3131
}
@@ -87,7 +87,7 @@ func (r *RunCommand) FollowerReady() bool {
8787
// Run creates a BuildRun resource based on Build's name informed on arguments.
8888
func (r *RunCommand) Run(params *params.Params, ioStreams *genericclioptions.IOStreams) error {
8989
// resource using GenerateName, which will provide a unique instance
90-
br := &buildv1alpha1.BuildRun{
90+
br := &buildv1beta1.BuildRun{
9191
ObjectMeta: metav1.ObjectMeta{
9292
GenerateName: fmt.Sprintf("%s-", r.buildName),
9393
},
@@ -100,7 +100,7 @@ func (r *RunCommand) Run(params *params.Params, ioStreams *genericclioptions.IOS
100100
if err != nil {
101101
return err
102102
}
103-
br, err = clientset.ShipwrightV1alpha1().BuildRuns(r.namespace).Create(ctx, br, metav1.CreateOptions{})
103+
br, err = clientset.ShipwrightV1beta1().BuildRuns(r.namespace).Create(ctx, br, metav1.CreateOptions{})
104104
if err != nil {
105105
return err
106106
}

0 commit comments

Comments
 (0)