-
Notifications
You must be signed in to change notification settings - Fork 176
refactor: Extract scaffolding as per-builder, new buildpacks default builder and sync Go version #3237
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
Merged
Merged
refactor: Extract scaffolding as per-builder, new buildpacks default builder and sync Go version #3237
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,8 @@ import ( | |
| // DefaultName when no WithName option is provided to NewBuilder | ||
| const DefaultName = builders.Pack | ||
|
|
||
| var DefaultBaseBuilder = "ghcr.io/knative/builder-jammy-base:latest" | ||
| var DefaultTinyBuilder = "ghcr.io/knative/builder-jammy-tiny:latest" | ||
| var DefaultBaseBuilder = "ghcr.io/knative/builder-jammy-base:v2" | ||
| var DefaultTinyBuilder = "ghcr.io/knative/builder-jammy-tiny:v2" | ||
|
|
||
| var ( | ||
| DefaultBuilderImages = map[string]string{ | ||
|
|
@@ -186,6 +186,11 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf | |
| opts.Env["BPE_DEFAULT_LISTEN_ADDRESS"] = "[::]:8080" | ||
| } | ||
|
|
||
| // set scaffolding path to buildpacks builder | ||
| if f.Runtime == "go" { | ||
| opts.Env["BP_GO_WORKDIR"] = ".func/build" | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the magic for buildpacks now as part of buildpacks package (replaces custom buildpack) |
||
|
|
||
| var bindings = make([]string, 0, len(f.Build.Mounts)) | ||
| for _, m := range f.Build.Mounts { | ||
| bindings = append(bindings, fmt.Sprintf("%s:%s", m.Source, m.Destination)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package buildpacks | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| fn "knative.dev/func/pkg/functions" | ||
| "knative.dev/func/pkg/scaffolding" | ||
| ) | ||
|
|
||
| const defaultPath = ".func/build" | ||
|
|
||
| // Scaffolder for buildpacks builder | ||
| type Scaffolder struct { | ||
| verbose bool | ||
| } | ||
|
|
||
| func NewScaffolder(verbose bool) *Scaffolder { | ||
| return &Scaffolder{verbose: verbose} | ||
| } | ||
|
|
||
| // Scaffold the function so that it can be built via buildpacks builder. | ||
| // 'path' is an optional override. Assign "" (empty string) most of the time | ||
| func (s Scaffolder) Scaffold(ctx context.Context, f fn.Function, path string) error { | ||
| // Because of Python injector we currently dont scaffold python. | ||
| // Add it here once the injector is removed | ||
| if f.Runtime != "go" { | ||
| if s.verbose { | ||
| fmt.Println("Scaffolding skipped. Currently available for runtime go") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| appRoot := path | ||
| if appRoot == "" { | ||
| appRoot = filepath.Join(f.Root, defaultPath) | ||
| } | ||
| if s.verbose { | ||
| fmt.Printf("Writing buildpacks scaffolding at path '%v'\n", appRoot) | ||
| } | ||
|
|
||
| embeddedRepo, err := fn.NewRepository("", "") | ||
| if err != nil { | ||
| return fmt.Errorf("unable to load embedded scaffolding: %w", err) | ||
| } | ||
| _ = os.RemoveAll(appRoot) | ||
| return scaffolding.Write(appRoot, f.Root, f.Runtime, f.Invoke, embeddedRepo.FS()) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing this default switch. The
v2no longer contains the good&old custom buildpack for go.