Skip to content

Commit 1db8031

Browse files
committed
add cli changes to move to v1beta1
1 parent ccc97a3 commit 1db8031

32 files changed

+538
-492
lines changed

docs/shp_build_create.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ 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
22+
--output-credentials-secret string name of the secret with output image push credentials
2623
--output-image string image employed during the building process
2724
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
2825
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
@@ -32,13 +29,13 @@ shp build create <name> [flags]
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)
32+
--source-oci-artifact-image string source oci artifact image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
33+
--source-oci-artifact-prune pruneOption source oci artifact image prune option, either Never, or AfterPull (default Never)
34+
--source-oci-artifact-pull-secret string name of the secret with credentials to pull the oci artifact image
3735
--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")
36+
--source-git-clone-secret string name of the secret with credentials to access the git repository, e.g. git credentials
37+
--source-git-revision string git repository source revision
38+
--source-git-url string git repository source URL
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

pkg/shp/bundle/bundle.go

+9-8
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

+44-11
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

+6-6
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

+3-3
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

+5-5
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
}

pkg/shp/cmd/build/run_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
9+
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
1010
shpfake "github.com/shipwright-io/build/pkg/client/clientset/versioned/fake"
1111
"github.com/shipwright-io/cli/pkg/shp/flags"
1212
"github.com/shipwright-io/cli/pkg/shp/params"
@@ -98,8 +98,8 @@ func TestStartBuildRunFollowLog(t *testing.T) {
9898
Namespace: metav1.NamespaceDefault,
9999
Name: name,
100100
Labels: map[string]string{
101-
buildv1alpha1.LabelBuild: name,
102-
buildv1alpha1.LabelBuildRun: name,
101+
buildv1beta1.LabelBuild: name,
102+
buildv1beta1.LabelBuildRun: name,
103103
},
104104
},
105105
Spec: corev1.PodSpec{
@@ -108,7 +108,7 @@ func TestStartBuildRunFollowLog(t *testing.T) {
108108
}},
109109
},
110110
}
111-
br := &buildv1alpha1.BuildRun{
111+
br := &buildv1beta1.BuildRun{
112112
ObjectMeta: metav1.ObjectMeta{
113113
Namespace: metav1.NamespaceDefault,
114114
Name: name,
@@ -153,26 +153,26 @@ func TestStartBuildRunFollowLog(t *testing.T) {
153153

154154
switch {
155155
case test.cancelled:
156-
br.Spec.State = buildv1alpha1.BuildRunRequestedStatePtr(buildv1alpha1.BuildRunStateCancel)
157-
br.Status.Conditions = []buildv1alpha1.Condition{
156+
br.Spec.State = buildv1beta1.BuildRunRequestedStatePtr(buildv1beta1.BuildRunStateCancel)
157+
br.Status.Conditions = []buildv1beta1.Condition{
158158
{
159-
Type: buildv1alpha1.Succeeded,
159+
Type: buildv1beta1.Succeeded,
160160
Status: corev1.ConditionFalse,
161161
},
162162
}
163163
case test.brDeleted:
164164
br.DeletionTimestamp = &metav1.Time{}
165-
br.Status.Conditions = []buildv1alpha1.Condition{
165+
br.Status.Conditions = []buildv1beta1.Condition{
166166
{
167-
Type: buildv1alpha1.Succeeded,
167+
Type: buildv1beta1.Succeeded,
168168
Status: corev1.ConditionFalse,
169169
},
170170
}
171171
case test.podDeleted:
172172
pod.DeletionTimestamp = &metav1.Time{}
173-
br.Status.Conditions = []buildv1alpha1.Condition{
173+
br.Status.Conditions = []buildv1beta1.Condition{
174174
{
175-
Type: buildv1alpha1.Succeeded,
175+
Type: buildv1beta1.Succeeded,
176176
Status: corev1.ConditionFalse,
177177
},
178178
}

0 commit comments

Comments
 (0)