Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support build from local source code #411

Merged
merged 1 commit into from
Jan 31, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion apis/core/v1beta1/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// BundleContainer describes the source code bundle container to pull
type BundleContainer struct {
// Image reference, i.e. quay.io/org/image:tag
Image string `json:"image"`
}

type GitRepo struct {
// Git url to clone
Url string `json:"url"`
Url string `json:"url,omitempty"`
// BundleContainer
//
// +optional
BundleContainer *BundleContainer `json:"bundleContainer,omitempty"`
// Git revision to check out (branch, tag, sha, ref…) (default:"")
Revision *string `json:"revision,omitempty"`
// A subpath within the `source` input where the source to build is located.
Expand Down
11 changes: 8 additions & 3 deletions apis/core/v1beta1/function_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,14 @@ func (r *Function) ValidateBuild() error {
"must be specified when `spec.build.dockerfile` is not enabled")
}

if r.Spec.Build.SrcRepo != nil && r.Spec.Build.SrcRepo.Url == "" {
return field.Required(field.NewPath("spec", "build", "srcRepo", "url"),
"must be specified when `spec.build.srcRepo` enabled")
if r.Spec.Build.SrcRepo == nil {
return field.Required(field.NewPath("spec", "build", "srcRepo"),
"must be specified when `spec.build` enabled")
}

if r.Spec.Build.SrcRepo.Url == "" && r.Spec.Build.SrcRepo.BundleContainer == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to add a check to ensure only one of the URL or bundleContainer can be specified?
Not all of them can be set simultaneously.

Copy link
Member Author

Choose a reason for hiding this comment

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

If bundleContainer and url are set at the same time, bundleContainer will be used first.

Copy link
Member

Choose a reason for hiding this comment

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

ok

return field.Required(field.NewPath("spec", "build", "srcRepo"),
"must specify one of: `url` or `bundleContainer`")
}

if r.Spec.Build.Timeout != nil && r.Spec.Build.Timeout.Duration < 0 {
Expand Down
21 changes: 21 additions & 0 deletions apis/core/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions config/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ spec:
type: object
srcRepo:
properties:
bundleContainer:
properties:
image:
type: string
required:
- image
type: object
credentials:
properties:
name:
Expand All @@ -219,8 +226,6 @@ spec:
type: string
url:
type: string
required:
- url
type: object
state:
type: string
Expand Down Expand Up @@ -730,6 +735,13 @@ spec:
type: object
srcRepo:
properties:
bundleContainer:
properties:
image:
type: string
required:
- image
type: object
credentials:
properties:
name:
Expand All @@ -741,8 +753,6 @@ spec:
type: string
url:
type: string
required:
- url
type: object
successfulBuildsHistoryLimit:
format: int32
Expand Down Expand Up @@ -4618,6 +4628,13 @@ spec:
type: object
srcRepo:
properties:
bundleContainer:
properties:
image:
type: string
required:
- image
type: object
credentials:
properties:
name:
Expand All @@ -4629,8 +4646,6 @@ spec:
type: string
url:
type: string
required:
- url
type: object
successfulBuildsHistoryLimit:
format: int32
Expand Down
9 changes: 7 additions & 2 deletions config/crd/bases/core.openfunction.io_builders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ spec:
type: object
srcRepo:
properties:
bundleContainer:
properties:
image:
type: string
required:
- image
type: object
credentials:
properties:
name:
Expand All @@ -215,8 +222,6 @@ spec:
type: string
url:
type: string
required:
- url
type: object
state:
type: string
Expand Down
9 changes: 7 additions & 2 deletions config/crd/bases/core.openfunction.io_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,13 @@ spec:
type: object
srcRepo:
properties:
bundleContainer:
properties:
image:
type: string
required:
- image
type: object
credentials:
properties:
name:
Expand All @@ -3578,8 +3585,6 @@ spec:
type: string
url:
type: string
required:
- url
type: object
successfulBuildsHistoryLimit:
format: int32
Expand Down
9 changes: 7 additions & 2 deletions config/crd/bases/events.openfunction.io_eventsources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ spec:
type: object
srcRepo:
properties:
bundleContainer:
properties:
image:
type: string
required:
- image
type: object
credentials:
properties:
name:
Expand All @@ -92,8 +99,6 @@ spec:
type: string
url:
type: string
required:
- url
type: object
successfulBuildsHistoryLimit:
format: int32
Expand Down
12 changes: 10 additions & 2 deletions pkg/core/builder/shipwright/builderrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func (r *builderRun) Cancel(builder *openfunction.Builder) error {
}

func (r *builderRun) createShipwrightBuild(builder *openfunction.Builder) *shipwrightv1alpha1.Build {
url := builder.Spec.SrcRepo.Url
shipwrightBuild := &shipwrightv1alpha1.Build{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-build-", builder.Name),
Expand All @@ -298,7 +297,6 @@ func (r *builderRun) createShipwrightBuild(builder *openfunction.Builder) *shipw
},
Spec: shipwrightv1alpha1.BuildSpec{
Source: shipwrightv1alpha1.Source{
URL: &url,
Revision: builder.Spec.SrcRepo.Revision,
ContextDir: builder.Spec.SrcRepo.SourceSubPath,
Credentials: builder.Spec.SrcRepo.Credentials,
Expand All @@ -315,6 +313,16 @@ func (r *builderRun) createShipwrightBuild(builder *openfunction.Builder) *shipw
},
}

switch {
case builder.Spec.SrcRepo.BundleContainer != nil:
shipwrightBuild.Spec.Source.BundleContainer = &shipwrightv1alpha1.BundleContainer{
Image: builder.Spec.SrcRepo.BundleContainer.Image,
}
case builder.Spec.SrcRepo.Url != "":
url := builder.Spec.SrcRepo.Url
shipwrightBuild.Spec.Source.URL = &url
}

if builder.Spec.Timeout != nil {
shipwrightBuild.Spec.Timeout = &metav1.Duration{
Duration: builder.Spec.Timeout.Duration - time.Since(builder.CreationTimestamp.Time),
Expand Down