Skip to content
Draft
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
39 changes: 23 additions & 16 deletions cmd/func-util/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,38 @@ func scaffold(ctx context.Context) error {
}

appRoot := filepath.Join(f.Root, ".s2i", "builds", "last")
if f.Build.Builder != "s2i" {
// TODO: gauron99 - change this completely
// non-s2i override
appRoot = filepath.Join(f.Root, ".func", "builds", "last")
}
fmt.Printf("appRoot is '%s'\n", appRoot)
_ = os.RemoveAll(appRoot)

// build step now includes scaffolding for go-pack
err = scaffolding.Write(appRoot, f.Root, f.Runtime, f.Invoke, embeddedRepo.FS())
if err != nil {
return fmt.Errorf("cannot write the scaffolding: %w", err)
}

if err := os.MkdirAll(filepath.Join(f.Root, ".s2i", "bin"), 0755); err != nil {
return fmt.Errorf("unable to create .s2i bin dir. %w", err)
}

var asm string
switch f.Runtime {
case "go":
asm = s2i.GoAssembler
case "python":
asm = s2i.PythonAssembler
default:
panic("unreachable")
}
if f.Build.Builder == "s2i" {
if err := os.MkdirAll(filepath.Join(f.Root, ".s2i", "bin"), 0755); err != nil {
return fmt.Errorf("unable to create .s2i bin dir. %w", err)
}
var asm string
switch f.Runtime {
case "go":
asm = s2i.GoAssembler
case "python":
asm = s2i.PythonAssembler
default:
panic("unreachable")
}

if err := os.WriteFile(filepath.Join(f.Root, ".s2i", "bin", "assemble"), []byte(asm), 0755); err != nil {
return fmt.Errorf("unable to write go assembler. %w", err)
if err := os.WriteFile(filepath.Join(f.Root, ".s2i", "bin", "assemble"), []byte(asm), 0755); err != nil {
return fmt.Errorf("unable to write go assembler. %w", err)
}
}

return nil
}

Expand Down
8,769 changes: 4,384 additions & 4,385 deletions generate/zz_filesystem_generated.go

Large diffs are not rendered by default.

53 changes: 50 additions & 3 deletions pkg/builders/buildpacks/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
"knative.dev/func/pkg/builders"
"knative.dev/func/pkg/docker"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/scaffolding"
)

// 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 = "quay.io/dfridric/knative/builder-jammy-base:latest"
var DefaultTinyBuilder = "quay.io/dfridric/knative/builder-jammy-tiny:latest"

var (
DefaultBuilderImages = map[string]string{
Expand All @@ -46,6 +47,7 @@ var (
// Ensure that all entries in this list are terminated with a trailing "/"
// See GHSA-5336-2g3f-9g3m for details
trustedBuilderImagePrefixes = []string{
"quay.io/dfridric/",
"quay.io/boson/",
"gcr.io/paketo-buildpacks/",
"docker.io/paketobuildpacks/",
Expand Down Expand Up @@ -116,7 +118,7 @@ func WithTimestamp(v bool) Option {
}
}

var DefaultLifecycleImage = "docker.io/buildpacksio/lifecycle:553c041"
var DefaultLifecycleImage = "docker.io/buildpacksio/lifecycle:3659764"

// Build the Function at path.
func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platform) (err error) {
Expand Down Expand Up @@ -171,6 +173,16 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
Volumes []string
}{Network: "", Volumes: nil},
}

// NOTE: gauron99 - this might be even created into a Client function and
// ran before the client.Build() all together (in the CLI). There are gonna
// be commonalitites across the builders for scaffolding with some nuances
// which could be handled by each "scaffolder" - similarly to builders.
// scaffold
if err = scaffold(f); err != nil {
return
}

if b.withTimestamp {
now := time.Now()
opts.CreationTime = &now
Expand All @@ -186,6 +198,12 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
opts.Env["BPE_DEFAULT_LISTEN_ADDRESS"] = "[::]:8080"
}

// go specific workdir set to where main is
if f.Runtime == "go" {
if _, ok := opts.Env["BP_GO_WORKDIR"]; !ok {
opts.Env["BP_GO_WORKDIR"] = ".func/builds/last"
}
}
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))
Expand Down Expand Up @@ -312,3 +330,32 @@ type ErrRuntimeNotSupported struct {
func (e ErrRuntimeNotSupported) Error() string {
return fmt.Sprintf("Pack builder has no default builder image for the '%v' language runtime. Please provide one.", e.Runtime)
}

// TODO: gauron99 - unify this with other builders; temporary for the go pack
//
// scaffold the project
func scaffold(f fn.Function) error {
// Scafffolding is currently only supported by the Go runtime
// Python currently uses an injector instead of this
if f.Runtime != "go" {
return nil
}

contextDir := filepath.Join(".func", "builds", "last")
appRoot := filepath.Join(f.Root, contextDir)
_ = os.RemoveAll(appRoot)

// The embedded repository contains the scaffolding code itself which glues
// together the middleware and a function via main
embeddedRepo, err := fn.NewRepository("", "") // default is the embedded fs
if err != nil {
return fmt.Errorf("unable to load the embedded scaffolding. %w", err)
}

// Write scaffolding to .func/builds/last
err = scaffolding.Write(appRoot, f.Root, f.Runtime, f.Invoke, embeddedRepo.FS())
if err != nil {
return fmt.Errorf("unable to build due to a scaffold error. %w", err)
}
return nil
}
6 changes: 3 additions & 3 deletions pkg/builders/buildpacks/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func TestBuild_BuildpacksDefault(t *testing.T) {
var (
i = &mockImpl{}
b = NewBuilder(WithImpl(i))
f = fn.Function{Runtime: "go"}
f = fn.Function{Runtime: "node"}
)

i.BuildFn = func(ctx context.Context, opts pack.BuildOptions) error {
expected := defaultBuildpacks["go"]
expected := defaultBuildpacks["node"]
if !reflect.DeepEqual(expected, opts.Buildpacks) {
t.Fatalf("expected buildpacks '%v', got '%v'", expected, opts.Buildpacks)
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestBuild_BuilderImageExclude(t *testing.T) {
b = NewBuilder( // Func Builder logic
WithName(builders.Pack), WithImpl(i))
f = fn.Function{
Runtime: "go",
Runtime: "node",
}
)
funcIgnoreContent := []byte(`#testing comments
Expand Down
1 change: 1 addition & 0 deletions pkg/pipelines/tekton/pipelines_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func NewPipelinesProvider(opts ...Opt) *PipelinesProvider {
// Returned is the final url, and the input Function with the final results of the run populated
// (f.Deploy.Image and f.Deploy.Namespace) or an error.
func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) (string, fn.Function, error) {
fmt.Println("#### pp.Run")
var err error

// Checks builder and registry:
Expand Down
3 changes: 2 additions & 1 deletion pkg/pipelines/tekton/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

var (
FuncUtilImage = "ghcr.io/knative/func-utils:v2"
//FuncUtilImage = "ghcr.io/knative/func-utils:v2"
FuncUtilImage = "quay.io/dfridric/my-func-util"
DeployerImage string
ScaffoldImage string
S2IImage string
Expand Down
12 changes: 10 additions & 2 deletions pkg/pipelines/tekton/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func getTaskSpec(taskYaml string) (string, error) {
// createAndApplyPipelineTemplate creates and applies Pipeline template for a standard on-cluster build
// all resources are created on the fly, if there's a Pipeline defined in the project directory, it is used instead
func createAndApplyPipelineTemplate(f fn.Function, namespace string, labels map[string]string) error {
fmt.Println("#### createAndApplyPipelineTemplate")
// If Git is set up create fetch task and reference it from build task,
// otherwise sources have been already uploaded to workspace PVC.
gitCloneTaskRef := ""
Expand Down Expand Up @@ -385,14 +386,16 @@ func createAndApplyPipelineTemplate(f fn.Function, namespace string, labels map[
default:
return builders.ErrBuilderNotSupported{Builder: f.Build.Builder}
}

fmt.Printf("## BI: '%v'\n", data.BuilderImage)
return createAndApplyResource(f.Root, pipelineFileName, template, "pipeline", getPipelineName(f), namespace, data)
}

// createAndApplyPipelineRunTemplate creates and applies PipelineRun template for a standard on-cluster build
// all resources are created on the fly, if there's a PipelineRun defined in the project directory, it is used instead
func createAndApplyPipelineRunTemplate(f fn.Function, namespace string, labels map[string]string) error {
fmt.Println("createAndApplyPipelineRunTemplate")
contextDir := f.Build.Git.ContextDir
fmt.Printf("contextDir: '%v'\n", contextDir)
if contextDir == "" && f.Build.Builder == builders.S2I {
// TODO(lkingland): could instead update S2I to interpret empty string
// as cwd, such that builder-specific code can be kept out of here.
Expand All @@ -413,6 +416,11 @@ func createAndApplyPipelineRunTemplate(f fn.Function, namespace string, labels m
}
}

// add BP_GO_WORKDIR for go-build buildpack
if f.Runtime == "go" {
buildEnvs = append(buildEnvs, "BP_GO_WORKDIR=.func/builds/last")
}

s2iImageScriptsUrl := defaultS2iImageScriptsUrl
if f.Runtime == "quarkus" {
s2iImageScriptsUrl = quarkusS2iImageScriptsUrl
Expand Down Expand Up @@ -445,7 +453,7 @@ func createAndApplyPipelineRunTemplate(f fn.Function, namespace string, labels m
RepoUrl: f.Build.Git.URL,
Revision: pipelinesTargetBranch,
}

fmt.Printf("# data.BuilderImage: '%v'\n", data.BuilderImage)
var template string
switch f.Build.Builder {
case builders.Pack:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffolding/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// fs: filesytem which contains scaffolding at '[runtime]/scaffolding'
// (exclusive with 'repo')
func Write(out, src, runtime, invoke string, fs filesystem.Filesystem) (err error) {

fmt.Println("#### scaffolding.Write")
// detect the signature of the source code in the given location, presuming
// a runtime and invocation hint (default "http")
s, err := detectSignature(src, runtime, invoke)
Expand Down
2 changes: 0 additions & 2 deletions templates/springboot/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ buildEnvs:
value: "false"
- name: BP_JVM_VERSION
value: "21"
- name: BP_MAVEN_ACTIVE_PROFILES
value: "native"
healthEndpoints:
liveness: /actuator/health
readiness: /actuator/health
Loading