@@ -23,13 +23,14 @@ import (
2323 "knative.dev/func/pkg/builders"
2424 "knative.dev/func/pkg/docker"
2525 fn "knative.dev/func/pkg/functions"
26+ "knative.dev/func/pkg/scaffolding"
2627)
2728
2829// DefaultName when no WithName option is provided to NewBuilder
2930const DefaultName = builders .Pack
3031
31- var DefaultBaseBuilder = "ghcr .io/knative/builder-jammy-base:latest"
32- var DefaultTinyBuilder = "ghcr .io/knative/builder-jammy-tiny:latest"
32+ var DefaultBaseBuilder = "quay .io/dfridric /knative/builder-jammy-base:latest"
33+ var DefaultTinyBuilder = "quay .io/dfridric /knative/builder-jammy-tiny:latest"
3334
3435var (
3536 DefaultBuilderImages = map [string ]string {
4647 // Ensure that all entries in this list are terminated with a trailing "/"
4748 // See GHSA-5336-2g3f-9g3m for details
4849 trustedBuilderImagePrefixes = []string {
50+ "quay.io/dfridric/" ,
4951 "quay.io/boson/" ,
5052 "gcr.io/paketo-buildpacks/" ,
5153 "docker.io/paketobuildpacks/" ,
@@ -116,7 +118,7 @@ func WithTimestamp(v bool) Option {
116118 }
117119}
118120
119- var DefaultLifecycleImage = "docker.io/buildpacksio/lifecycle:553c041 "
121+ var DefaultLifecycleImage = "docker.io/buildpacksio/lifecycle:3659764 "
120122
121123// Build the Function at path.
122124func (b * Builder ) Build (ctx context.Context , f fn.Function , platforms []fn.Platform ) (err error ) {
@@ -171,6 +173,16 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
171173 Volumes []string
172174 }{Network : "" , Volumes : nil },
173175 }
176+
177+ // NOTE: gauron99 - this might be even created into a Client function and
178+ // ran before the client.Build() all together (in the CLI). There are gonna
179+ // be commonalitites across the builders for scaffolding with some nuances
180+ // which could be handled by each "scaffolder" - similarly to builders.
181+ // scaffold
182+ if err = scaffold (f ); err != nil {
183+ return
184+ }
185+
174186 if b .withTimestamp {
175187 now := time .Now ()
176188 opts .CreationTime = & now
@@ -186,6 +198,12 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
186198 opts .Env ["BPE_DEFAULT_LISTEN_ADDRESS" ] = "[::]:8080"
187199 }
188200
201+ // go specific workdir set to where main is
202+ if f .Runtime == "go" {
203+ if _ , ok := opts .Env ["BP_GO_WORKDIR" ]; ! ok {
204+ opts .Env ["BP_GO_WORKDIR" ] = ".func/builds/last"
205+ }
206+ }
189207 var bindings = make ([]string , 0 , len (f .Build .Mounts ))
190208 for _ , m := range f .Build .Mounts {
191209 bindings = append (bindings , fmt .Sprintf ("%s:%s" , m .Source , m .Destination ))
@@ -312,3 +330,32 @@ type ErrRuntimeNotSupported struct {
312330func (e ErrRuntimeNotSupported ) Error () string {
313331 return fmt .Sprintf ("Pack builder has no default builder image for the '%v' language runtime. Please provide one." , e .Runtime )
314332}
333+
334+ // TODO: gauron99 - unify this with other builders; temporary for the go pack
335+ //
336+ // scaffold the project
337+ func scaffold (f fn.Function ) error {
338+ // Scafffolding is currently only supported by the Go runtime
339+ // Python currently uses an injector instead of this
340+ if f .Runtime != "go" {
341+ return nil
342+ }
343+
344+ contextDir := filepath .Join (".func" , "builds" , "last" )
345+ appRoot := filepath .Join (f .Root , contextDir )
346+ _ = os .RemoveAll (appRoot )
347+
348+ // The embedded repository contains the scaffolding code itself which glues
349+ // together the middleware and a function via main
350+ embeddedRepo , err := fn .NewRepository ("" , "" ) // default is the embedded fs
351+ if err != nil {
352+ return fmt .Errorf ("unable to load the embedded scaffolding. %w" , err )
353+ }
354+
355+ // Write scaffolding to .func/builds/last
356+ err = scaffolding .Write (appRoot , f .Root , f .Runtime , f .Invoke , embeddedRepo .FS ())
357+ if err != nil {
358+ return fmt .Errorf ("unable to build due to a scaffold error. %w" , err )
359+ }
360+ return nil
361+ }
0 commit comments