@@ -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 = "ghcr.io/knative/builder-jammy-base:v2 "
33+ var DefaultTinyBuilder = "ghcr.io/knative/builder-jammy-tiny:v2 "
3334
3435var (
3536 DefaultBuilderImages = map [string ]string {
@@ -116,7 +117,7 @@ func WithTimestamp(v bool) Option {
116117 }
117118}
118119
119- var DefaultLifecycleImage = "docker.io/buildpacksio/lifecycle:553c041 "
120+ var DefaultLifecycleImage = "docker.io/buildpacksio/lifecycle:3659764 "
120121
121122// Build the Function at path.
122123func (b * Builder ) Build (ctx context.Context , f fn.Function , platforms []fn.Platform ) (err error ) {
@@ -171,6 +172,12 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
171172 Volumes []string
172173 }{Network : "" , Volumes : nil },
173174 }
175+
176+ // TODO: gauron99 this will be extracted into separate client.Scaffold method
177+ if err = scaffold (f ); err != nil {
178+ return
179+ }
180+
174181 if b .withTimestamp {
175182 now := time .Now ()
176183 opts .CreationTime = & now
@@ -186,6 +193,12 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
186193 opts .Env ["BPE_DEFAULT_LISTEN_ADDRESS" ] = "[::]:8080"
187194 }
188195
196+ // go specific workdir set to directory of main
197+ if f .Runtime == "go" {
198+ if _ , ok := opts .Env ["BP_GO_WORKDIR" ]; ! ok {
199+ opts .Env ["BP_GO_WORKDIR" ] = ".func/builds/last"
200+ }
201+ }
189202 var bindings = make ([]string , 0 , len (f .Build .Mounts ))
190203 for _ , m := range f .Build .Mounts {
191204 bindings = append (bindings , fmt .Sprintf ("%s:%s" , m .Source , m .Destination ))
@@ -312,3 +325,33 @@ type ErrRuntimeNotSupported struct {
312325func (e ErrRuntimeNotSupported ) Error () string {
313326 return fmt .Sprintf ("Pack builder has no default builder image for the '%v' language runtime. Please provide one." , e .Runtime )
314327}
328+
329+ // TODO: gauron99 - unify this with other builders
330+ // This is temporary for the go pack
331+ //
332+ // scaffold the project
333+ func scaffold (f fn.Function ) error {
334+ // Scaffolding is currently only supported by the Go runtime
335+ // Python currently uses an injector instead of this
336+ if f .Runtime != "go" {
337+ return nil
338+ }
339+
340+ contextDir := filepath .Join (".func" , "builds" , "last" )
341+ appRoot := filepath .Join (f .Root , contextDir )
342+ _ = os .RemoveAll (appRoot )
343+
344+ // The embedded repository contains the scaffolding code itself which glues
345+ // together the middleware and a function via main
346+ embeddedRepo , err := fn .NewRepository ("" , "" ) // default is the embedded fs
347+ if err != nil {
348+ return fmt .Errorf ("unable to load the embedded scaffolding. %w" , err )
349+ }
350+
351+ // Write scaffolding to .func/builds/last
352+ err = scaffolding .Write (appRoot , f .Root , f .Runtime , f .Invoke , embeddedRepo .FS ())
353+ if err != nil {
354+ return fmt .Errorf ("unable to build due to a scaffold error. %w" , err )
355+ }
356+ return nil
357+ }
0 commit comments