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

add support setting cache image of buildpacks #444

Merged
merged 1 commit into from
May 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions apis/core/v1beta1/builder_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package v1beta1
standard packages.
*/
import (
shipwrightv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"github.com/openfunction/apis/core/v1beta2"
Expand Down Expand Up @@ -83,8 +82,8 @@ func (src *Builder) ConvertTo(dstRaw conversion.Hub) error {
if src.Spec.Params != nil {
for k, v := range src.Spec.Params {
value := v
dst.Spec.Shipwright.Params = append(dst.Spec.Shipwright.Params, shipwrightv1alpha1.ParamValue{
SingleValue: &shipwrightv1alpha1.SingleValue{
dst.Spec.Shipwright.Params = append(dst.Spec.Shipwright.Params, &v1beta2.ParamValue{
SingleValue: &v1beta2.SingleValue{
Value: &value,
},
Name: k,
Expand Down
5 changes: 2 additions & 3 deletions apis/core/v1beta1/function_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package v1beta1

import (
componentsv1alpha1 "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
shipwrightv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"gopkg.in/yaml.v3"
"sigs.k8s.io/controller-runtime/pkg/conversion"

Expand Down Expand Up @@ -151,8 +150,8 @@ func (src *Function) convertBuildTo(dst *v1beta2.Function) error {
if src.Spec.Build.Params != nil {
for k, v := range src.Spec.Build.Params {
value := v
dst.Spec.Build.Shipwright.Params = append(dst.Spec.Build.Shipwright.Params, shipwrightv1alpha1.ParamValue{
SingleValue: &shipwrightv1alpha1.SingleValue{
dst.Spec.Build.Shipwright.Params = append(dst.Spec.Build.Shipwright.Params, &v1beta2.ParamValue{
SingleValue: &v1beta2.SingleValue{
Value: &value,
},
Name: k,
Expand Down
36 changes: 35 additions & 1 deletion apis/core/v1beta2/builder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,40 @@ type Strategy struct {
Kind *string `json:"kind,omitempty"`
}

// The value type contains the properties for a value, this allows for an
// easy extension in the future to support more kinds
type SingleValue struct {

// The value of the parameter
// +optional
Value *string `json:"value"`

// The ConfigMap value of the parameter
// +optional
ConfigMapValue *shipwrightv1alpha1.ObjectKeyRef `json:"configMapValue,omitempty"`

// The secret value of the parameter
// +optional
SecretValue *shipwrightv1alpha1.ObjectKeyRef `json:"secretValue,omitempty"`
}

// ParamValue is a key/value that populates a strategy parameter
// used in the execution of the strategy steps
type ParamValue struct {

// Inline the properties of a value
// +optional
*SingleValue `json:",inline"`

// Name of the parameter
// +required
Name string `json:"name"`

// Values of an array parameter
// +optional
Values []SingleValue `json:"values,omitempty"`
}

type ShipwrightEngine struct {
// Strategy references the BuildStrategy to use to build the image.
// +optional
Expand All @@ -50,7 +84,7 @@ type ShipwrightEngine struct {
// When using _params_, users should avoid:
// Defining a parameter name that doesn't match one of the `spec.parameters` defined in the `BuildStrategy`.
// Defining a parameter name that collides with the Shipwright reserved parameters including BUILDER_IMAGE,DOCKERFILE,CONTEXT_DIR and any name starting with shp-.
Params []shipwrightv1alpha1.ParamValue `json:"params,omitempty"`
Params []*ParamValue `json:"params,omitempty"`
// Timeout defines the maximum amount of time the Build should take to execute.
//
// +optional
Expand Down
65 changes: 63 additions & 2 deletions apis/core/v1beta2/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions config/strategy/build-strategy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
- args:
- -app=/workspace/source/$(params.CONTEXT_DIR)
- -cache-dir=/cache
- -cache-image=$(params.CACHE_IMAGE)
- -uid=$(params.USER_ID)
- -gid=$(params.GROUP_ID)
- -layers=/layers
Expand Down
33 changes: 32 additions & 1 deletion pkg/core/builder/shipwright/builderrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (r *builderRun) createShipwrightBuild(builder *openfunction.Builder) *shipw
}

if builder.Spec.Shipwright != nil {
shipwrightBuild.Spec.ParamValues = append(shipwrightBuild.Spec.ParamValues, builder.Spec.Shipwright.Params...)
appendParams(shipwrightBuild, builder)
}

for k, v := range builder.Labels {
Expand Down Expand Up @@ -379,6 +379,37 @@ func (r *builderRun) createShipwrightBuild(builder *openfunction.Builder) *shipw
return shipwrightBuild
}

func appendParams(shipwrightBuild *shipwrightv1alpha1.Build, b *openfunction.Builder) {
for _, p := range b.Spec.Shipwright.Params {
if p == nil {
continue
}

param := shipwrightv1alpha1.ParamValue{
SingleValue: nil,
Name: p.Name,
}

if p.SingleValue != nil {
param.SingleValue = &shipwrightv1alpha1.SingleValue{
Value: p.Value,
ConfigMapValue: p.ConfigMapValue,
SecretValue: p.SecretValue,
}
}

for _, v := range p.Values {
param.Values = append(param.Values, shipwrightv1alpha1.SingleValue{
Value: v.Value,
ConfigMapValue: v.ConfigMapValue,
SecretValue: v.SecretValue,
})
}

shipwrightBuild.Spec.ParamValues = append(shipwrightBuild.Spec.ParamValues, param)
}
}

func (r *builderRun) createShipwrightBuildRun(builder *openfunction.Builder, name string) *shipwrightv1alpha1.BuildRun {
generateSA := shipwrightGenerateSA
shipwrightBuildRun := &shipwrightv1alpha1.BuildRun{
Expand Down
Loading