Skip to content
Closed
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
18 changes: 8 additions & 10 deletions docs/shp_build_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,26 @@ 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
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
--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
5 changes: 2 additions & 3 deletions docs/shp_build_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ 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
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
--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
5 changes: 2 additions & 3 deletions docs/shp_build_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ 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
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
--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
5 changes: 2 additions & 3 deletions docs/shp_buildrun_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ 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
--node-selector stringArray set of key-value pairs that correspond to labels of a node to match (default [])
--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: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.0

require (
github.com/google/go-containerregistry v0.20.3
github.com/onsi/gomega v1.36.3
github.com/onsi/gomega v1.37.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/schollz/progressbar/v3 v3.18.0
github.com/shipwright-io/build v0.15.0
Expand Down Expand Up @@ -105,7 +105,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/oauth2 v0.26.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0=
github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM=
github.com/onsi/gomega v1.36.3 h1:hID7cr8t3Wp26+cYnfcjR6HpJ00fdogN6dqZ1t6IylU=
github.com/onsi/gomega v1.36.3/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down Expand Up @@ -522,8 +522,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
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 != "" {
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 != "" {
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 != "" {
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
Loading
Loading