Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions docs/shp_build_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@ shp build create <name> [flags]
### Options

```
--builder-credentials-secret string name of the secret with builder-image pull credentials
--builder-image string image employed during the building process
--dockerfile string path to dockerfile relative to repository
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
-h, --help help for create
--output-credentials-secret string name of the secret with builder-image pull credentials
--output-image string image employed during the building process
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
--output-image-push-secret string name of the secret with output image push credentials
--output-insecure flag to indicate an insecure container registry
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
--retention-failed-limit uint number of failed BuildRuns to be kept (default 65535)
--retention-succeeded-limit uint number of succeeded BuildRuns to be kept (default 65535)
--retention-ttl-after-failed duration duration to delete a failed BuildRun after completion
--retention-ttl-after-succeeded duration duration to delete a succeeded BuildRun after completion
--source-bundle-image string source bundle image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
--source-bundle-prune pruneOption source bundle prune option, either Never, or AfterPull (default Never)
--source-context-dir string use a inner directory as context directory
--source-credentials-secret string name of the secret with credentials to access the source, e.g. git or registry credentials
--source-revision string git repository source revision
--source-url string git repository source URL
--strategy-apiversion string kubernetes api-version of the build-strategy resource (default "v1alpha1")
--source-git-clone-secret string name of the secret with credentials to access the git source, e.g. git credentials
--source-git-revision string git repository source revision
--source-git-url string git repository source URL
--source-oci-artifact-image string source OCI artifact image reference, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
--source-oci-artifact-prune pruneOption source OCI artifact image prune option, either Never, or AfterPull (default Never)
--source-oci-artifact-pull-secret string name of the secret with credentials to access the OCI artifact image, e.g. registry credentials
--strategy-kind string build-strategy kind (default "ClusterBuildStrategy")
--strategy-name string build-strategy name (default "buildpacks-v3")
--timeout duration build process timeout
Expand Down
4 changes: 1 addition & 3 deletions docs/shp_build_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ shp build run <name> [flags]
### Options

```
--buildref-apiversion string API version of build resource to reference
--buildref-name string name of build resource to reference
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
-F, --follow Start a build and watch its log until it completes or fails.
-h, --help help for run
--output-credentials-secret string name of the secret with builder-image pull credentials
--output-image string image employed during the building process
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
--output-image-push-secret string name of the secret with output image push credentials
--output-insecure flag to indicate an insecure container registry
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
--sa-generate generate a Kubernetes service-account for the build
--sa-name string Kubernetes service-account name
--timeout duration build process timeout
```
Expand Down
4 changes: 1 addition & 3 deletions docs/shp_build_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ shp build upload <build-name> [path/to/source|.] [flags]
### Options

```
--buildref-apiversion string API version of build resource to reference
--buildref-name string name of build resource to reference
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
-F, --follow Start a build and watch its log until it completes or fails.
-h, --help help for upload
--output-credentials-secret string name of the secret with builder-image pull credentials
--output-image string image employed during the building process
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
--output-image-push-secret string name of the secret with output image push credentials
--output-insecure flag to indicate an insecure container registry
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
--sa-generate generate a Kubernetes service-account for the build
--sa-name string Kubernetes service-account name
--timeout duration build process timeout
```
Expand Down
4 changes: 1 addition & 3 deletions docs/shp_buildrun_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ shp buildrun create <name> [flags]
### Options

```
--buildref-apiversion string API version of build resource to reference
--buildref-name string name of build resource to reference
-e, --env stringArray specify a key-value pair for an environment variable to set for the build container (default [])
-h, --help help for create
--output-credentials-secret string name of the secret with builder-image pull credentials
--output-image string image employed during the building process
--output-image-annotation stringArray specify a set of key-value pairs that correspond to annotations to set on the output image (default [])
--output-image-label stringArray specify a set of key-value pairs that correspond to labels to set on the output image (default [])
--output-image-push-secret string name of the secret with output image push credentials
--output-insecure flag to indicate an insecure container registry
--param-value stringArray set of key-value pairs to pass as parameters to the buildStrategy (default [])
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
--sa-generate generate a Kubernetes service-account for the build
--sa-name string Kubernetes service-account name
--timeout duration build process timeout
```
Expand Down
17 changes: 9 additions & 8 deletions pkg/shp/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
progressbar "github.com/schollz/progressbar/v3"
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
buildbundle "github.com/shipwright-io/build/pkg/bundle"
buildclientset "github.com/shipwright-io/build/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -20,21 +20,22 @@ import (
// GetSourceBundleImage returns the source bundle image of the build that is
// associated with the provided buildrun, an empty string if source bundle is
// not used, or an error in case the build cannot be obtained
func GetSourceBundleImage(ctx context.Context, client buildclientset.Interface, buildRun *buildv1alpha1.BuildRun) (string, error) {
func GetSourceBundleImage(ctx context.Context, client buildclientset.Interface, buildRun *buildv1beta1.BuildRun) (string, error) {
if buildRun == nil {
return "", fmt.Errorf("no buildrun provided, given reference is nil")
}

if buildRun.Spec.BuildRef != nil {
name, namespace := buildRun.Spec.BuildRef.Name, buildRun.Namespace
if buildRun.Spec.Build.Name != nil && *buildRun.Spec.Build.Name != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - ditto on use of len:

Suggested change
if buildRun.Spec.Build.Name != nil && *buildRun.Spec.Build.Name != "" {
if len(buildRun.Spec.Build.Name) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.

name, namespace := buildRun.Spec.Build.Name, buildRun.Namespace

build, err := client.ShipwrightV1alpha1().Builds(namespace).Get(ctx, name, metav1.GetOptions{})
build, err := client.ShipwrightV1beta1().Builds(namespace).Get(ctx, *name, metav1.GetOptions{})
if err != nil {
return "", err
}

if build.Spec.Source.BundleContainer != nil && build.Spec.Source.BundleContainer.Image != "" {
return build.Spec.Source.BundleContainer.Image, nil
if build.Spec.Source != nil {
if build.Spec.Source.OCIArtifact != nil && build.Spec.Source.OCIArtifact.Image != "" {
return build.Spec.Source.OCIArtifact.Image, nil
}
}
}

Expand Down
55 changes: 44 additions & 11 deletions pkg/shp/cmd/build/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package build
import (
"fmt"

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

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

name string // build resource's name
buildSpec *buildv1alpha1.BuildSpec // stores command-line flags
name string // build resource's name
buildSpec *buildv1beta1.BuildSpec // stores command-line flags
dockerfile *string // For dockerfile parameter
builderImage *string // For builder image parameter

}

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

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

flags.SanitizeBuildSpec(&b.Spec)

// print warning with regards to source bundle image being used
if b.Spec.Source.BundleContainer != nil && b.Spec.Source.BundleContainer.Image != "" {
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)
if b.Spec.Source != nil {
if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.Image != "" {
b.Spec.Source.Type = buildv1beta1.OCIArtifactType
} else if b.Spec.Source.Git != nil && b.Spec.Source.Git.URL != "" {
b.Spec.Source.Type = buildv1beta1.GitType
}

// print warning with regards to source bundle image being used
if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.Image != "" {
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)
}
}

if c.dockerfile != nil && *c.dockerfile != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (not going to block on this) - you can do both checks in golang using len, since it is safe to use on nil pointers:

Suggested change
if c.dockerfile != nil && *c.dockerfile != "" {
if len(c.dockerfile) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.

dockerfileParam := buildv1beta1.ParamValue{
Name: "dockerfile",
SingleValue: &buildv1beta1.SingleValue{
Value: c.dockerfile,
},
}
c.buildSpec.ParamValues = append(c.buildSpec.ParamValues, dockerfileParam)
}

if c.builderImage != nil && *c.builderImage != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (not blocking) - ditto on using len:

Suggested change
if c.builderImage != nil && *c.builderImage != "" {
if len(c.builderImage) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.

builderParam := buildv1beta1.ParamValue{
Name: "builder-image",
SingleValue: &buildv1beta1.SingleValue{
Value: c.builderImage,
},
}
c.buildSpec.ParamValues = append(c.buildSpec.ParamValues, builderParam)
}

clientset, err := params.ShipwrightClientSet()
if err != nil {
return err
}
if _, err := clientset.ShipwrightV1alpha1().Builds(params.Namespace()).Create(c.cmd.Context(), b, metav1.CreateOptions{}); err != nil {
if _, err := clientset.ShipwrightV1beta1().Builds(params.Namespace()).Create(c.cmd.Context(), b, metav1.CreateOptions{}); err != nil {
return err
}
fmt.Fprintf(io.Out, "Created build %q\n", c.name)
Expand All @@ -89,13 +120,15 @@ func createCmd() runner.SubCommand {

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

return &CreateCommand{
cmd: cmd,
buildSpec: buildSpecFlags,
cmd: cmd,
buildSpec: buildSpecFlags,
dockerfile: dockerfileFlag,
builderImage: builderImageFlag,
}
}
12 changes: 6 additions & 6 deletions pkg/shp/cmd/build/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package build
import (
"fmt"

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

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

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

for _, buildrun := range brList.Items {
if err := clientset.ShipwrightV1alpha1().BuildRuns(params.Namespace()).Delete(c.cmd.Context(), buildrun.Name, v1.DeleteOptions{}); err != nil {
if err := clientset.ShipwrightV1beta1().BuildRuns(params.Namespace()).Delete(c.cmd.Context(), buildrun.Name, v1.DeleteOptions{}); err != nil {
fmt.Fprintf(io.ErrOut, "Error deleting BuildRun %q: %v\n", buildrun.Name, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/shp/cmd/build/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"text/tabwriter"

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

var buildList *buildv1alpha1.BuildList
var buildList *buildv1beta1.BuildList
clientset, err := params.ShipwrightClientSet()
if err != nil {
return err
Expand All @@ -78,7 +78,7 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
return err
}

if buildList, err = clientset.ShipwrightV1alpha1().Builds(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
if buildList, err = clientset.ShipwrightV1beta1().Builds(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
return err
}
if len(buildList.Items) == 0 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/shp/cmd/build/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

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

buildName string
namespace string
buildRunSpec *buildv1alpha1.BuildRunSpec // stores command-line flags
follow bool // flag to tail pod logs
buildRunSpec *buildv1beta1.BuildRunSpec // stores command-line flags
follow bool // flag to tail pod logs
follower *follower.Follower
followerReady chan bool
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func (r *RunCommand) FollowerReady() bool {
// Run creates a BuildRun resource based on Build's name informed on arguments.
func (r *RunCommand) Run(params *params.Params, ioStreams *genericclioptions.IOStreams) error {
// resource using GenerateName, which will provide a unique instance
br := &buildv1alpha1.BuildRun{
br := &buildv1beta1.BuildRun{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-", r.buildName),
},
Expand All @@ -100,7 +100,7 @@ func (r *RunCommand) Run(params *params.Params, ioStreams *genericclioptions.IOS
if err != nil {
return err
}
br, err = clientset.ShipwrightV1alpha1().BuildRuns(r.namespace).Create(ctx, br, metav1.CreateOptions{})
br, err = clientset.ShipwrightV1beta1().BuildRuns(r.namespace).Create(ctx, br, metav1.CreateOptions{})
if err != nil {
return err
}
Expand Down
Loading