Skip to content

Commit 73ce011

Browse files
committed
duplicated
1 parent a23f6d8 commit 73ce011

File tree

11 files changed

+127
-27
lines changed

11 files changed

+127
-27
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ LDFLAGS += -X knative.dev/func/pkg/k8s.SocatImage=$(FUNC_UTILS_IMG)
3737
LDFLAGS += -X knative.dev/func/pkg/k8s.TarImage=$(FUNC_UTILS_IMG)
3838
LDFLAGS += -X knative.dev/func/pkg/pipelines/tekton.FuncUtilImage=$(FUNC_UTILS_IMG)
3939

40+
$(info [MAKEFILE DEBUG] FUNC_UTILS_IMG = $(FUNC_UTILS_IMG))
41+
$(info [MAKEFILE DEBUG] LDFLAGS = $(LDFLAGS))
42+
4043
GOFLAGS := "-ldflags=$(LDFLAGS)"
4144
export GOFLAGS
4245

@@ -292,11 +295,15 @@ templates/certs/ca-certificates.crt:
292295

293296
.PHONY: test-integration
294297
test-integration: ## Run integration tests using an available cluster.
298+
@echo "[TEST DEBUG] FUNC_UTILS_IMG = $(FUNC_UTILS_IMG)"
299+
@echo "[TEST DEBUG] Environment FUNC_UTILS_IMG = $$FUNC_UTILS_IMG"
295300
go test -cover -coverprofile=coverage.txt -tags integration -timeout 60m ./... -v -run TestInt_
296301

297302
.PHONY: test-e2e
298303
test-e2e: func-instrumented-bin ## Basic E2E tests (includes core, metadata and remote tests)
299304
# Runtime and other options can be configured using the FUNC_E2E_* environment variables. see e2e_test.go
305+
@echo "[TEST DEBUG] FUNC_UTILS_IMG = $(FUNC_UTILS_IMG)"
306+
@echo "[TEST DEBUG] Environment FUNC_UTILS_IMG = $$FUNC_UTILS_IMG"
300307
go test -cover -coverprofile=coverage.txt -tags e2e -timeout 60m ./e2e -v -run "TestCore_|TestMetadata_|TestRemote_"
301308

302309
.PHONY: test-e2e-podman
@@ -306,6 +313,8 @@ test-e2e-podman: func-instrumented-bin ## Run E2E Podman-specific tests
306313

307314
test-e2e-matrix: func-instrumented-bin ## Basic E2E tests (includes core, metadata and remote tests)
308315
# Runtime and other options can be configured using the FUNC_E2E_* environment variables. see e2e_test.go
316+
@echo "[TEST DEBUG] FUNC_UTILS_IMG = $(FUNC_UTILS_IMG)"
317+
@echo "[TEST DEBUG] Environment FUNC_UTILS_IMG = $$FUNC_UTILS_IMG"
309318
FUNC_E2E_MATRIX=true go test -cover -coverprofile=coverage.txt -tags e2e -timeout 120m ./e2e -v -run TestMatrix_
310319

311320

@@ -319,6 +328,8 @@ test-full-logged: func-instrumented-bin ## Run full test and log with timestamps
319328

320329
.PHONY: func-instrumented-bin
321330
func-instrumented-bin: # func binary instrumented with coverage reporting
331+
@echo "[BUILD DEBUG] Building func binary with FUNC_UTILS_IMG = $(FUNC_UTILS_IMG)"
332+
@echo "[BUILD DEBUG] GOFLAGS = $(GOFLAGS)"
322333
env CGO_ENABLED=1 go build -cover -o func ./cmd/$(BIN)
323334

324335

cmd/func-util/main.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func socat(ctx context.Context) error {
7474
}
7575

7676
func scaffold(ctx context.Context) error {
77-
77+
fmt.Println("Scaffolding duplicated")
7878
if len(os.Args) != 2 {
7979
return fmt.Errorf("expected exactly one positional argument (function project path)")
8080
}
@@ -87,7 +87,7 @@ func scaffold(ctx context.Context) error {
8787
}
8888

8989
if f.Runtime != "go" && f.Runtime != "python" {
90-
// Scaffolding is for now supported/needed only for Go.
90+
// Scaffolding is for now supported/needed only for Go&Python
9191
return nil
9292
}
9393

@@ -97,31 +97,38 @@ func scaffold(ctx context.Context) error {
9797
}
9898

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

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

107-
if err := os.MkdirAll(filepath.Join(f.Root, ".s2i", "bin"), 0755); err != nil {
108-
return fmt.Errorf("unable to create .s2i bin dir. %w", err)
109-
}
110-
111-
var asm string
112-
switch f.Runtime {
113-
case "go":
114-
asm = s2i.GoAssembler
115-
case "python":
116-
asm = s2i.PythonAssembler
117-
default:
118-
panic("unreachable")
119-
}
114+
if f.Build.Builder == "s2i" {
115+
if err := os.MkdirAll(filepath.Join(f.Root, ".s2i", "bin"), 0755); err != nil {
116+
return fmt.Errorf("unable to create .s2i bin dir. %w", err)
117+
}
118+
var asm string
119+
switch f.Runtime {
120+
case "go":
121+
asm = s2i.GoAssembler
122+
case "python":
123+
asm = s2i.PythonAssembler
124+
default:
125+
panic("unreachable")
126+
}
120127

121-
if err := os.WriteFile(filepath.Join(f.Root, ".s2i", "bin", "assemble"), []byte(asm), 0755); err != nil {
122-
return fmt.Errorf("unable to write go assembler. %w", err)
128+
if err := os.WriteFile(filepath.Join(f.Root, ".s2i", "bin", "assemble"), []byte(asm), 0755); err != nil {
129+
return fmt.Errorf("unable to write go assembler. %w", err)
130+
}
123131
}
124-
125132
return nil
126133
}
127134

hack/images.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ set -o pipefail
66

77
FUNC_UTILS_IMG="localhost:50000/knative/func-utils:v2"
88

9+
echo "[IMAGES.SH DEBUG] FUNC_UTILS_IMG = ${FUNC_UTILS_IMG}"
10+
echo "[IMAGES.SH DEBUG] Is FUNC_UTILS_IMG exported? $(env | grep FUNC_UTILS_IMG || echo 'NO')"
11+
912
CGO_ENABLED=0 go build -o "func-util" -trimpath -ldflags '-w -s' ./cmd/func-util
1013

1114
docker build . -f Dockerfile.utils -t "${FUNC_UTILS_IMG}" --build-arg FUNC_UTIL_BINARY=func-util
1215
docker push "${FUNC_UTILS_IMG}"
1316

17+
echo "[IMAGES.SH DEBUG] Finished pushing ${FUNC_UTILS_IMG}"
18+
echo "[IMAGES.SH DEBUG] Variable will NOT persist after this script exits (not exported)"
19+
1420
# Build custom buildah image for tests.
1521
# This image will accept registries ending with .cluster.local as insecure (non-TLS).
1622
go install github.com/google/go-containerregistry/cmd/crane@latest

pkg/builders/buildpacks/builder.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2930
const 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/gauron99/builder-jammy-base:latest"
33+
var DefaultTinyBuilder = "ghcr.io/gauron99/builder-jammy-tiny:latest"
3334

3435
var (
3536
DefaultBuilderImages = map[string]string{
@@ -46,6 +47,7 @@ var (
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.
122124
func (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 {
312330
func (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+
}

pkg/builders/buildpacks/builder_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ func TestBuild_BuildpacksDefault(t *testing.T) {
8686
var (
8787
i = &mockImpl{}
8888
b = NewBuilder(WithImpl(i))
89-
f = fn.Function{Runtime: "go"}
89+
f = fn.Function{Runtime: "node"}
9090
)
9191

9292
i.BuildFn = func(ctx context.Context, opts pack.BuildOptions) error {
93-
expected := defaultBuildpacks["go"]
93+
expected := defaultBuildpacks["node"]
9494
if !reflect.DeepEqual(expected, opts.Buildpacks) {
9595
t.Fatalf("expected buildpacks '%v', got '%v'", expected, opts.Buildpacks)
9696
}
@@ -141,7 +141,7 @@ func TestBuild_BuilderImageExclude(t *testing.T) {
141141
b = NewBuilder( // Func Builder logic
142142
WithName(builders.Pack), WithImpl(i))
143143
f = fn.Function{
144-
Runtime: "go",
144+
Runtime: "node",
145145
}
146146
)
147147
funcIgnoreContent := []byte(`#testing comments

pkg/k8s/dialer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ func (c *contextDialer) startDialerPod(ctx context.Context) (err error) {
275275
}
276276
}()
277277

278+
fmt.Printf("[DEBUG] pkg/k8s/dialer.go: Using SocatImage = %s\n", SocatImage)
279+
278280
pod := &coreV1.Pod{
279281
ObjectMeta: metaV1.ObjectMeta{
280282
Name: c.podName,

pkg/k8s/persistent_volumes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var TarImage = "ghcr.io/knative/func-utils:v2"
7676

7777
// UploadToVolume uploads files (passed in form of tar stream) into volume.
7878
func UploadToVolume(ctx context.Context, content io.Reader, claimName, namespace string) error {
79+
fmt.Printf("[DEBUG] pkg/k8s/persistent_volumes.go: Using TarImage = %s\n", TarImage)
7980
return runWithVolumeMounted(ctx, TarImage, []string{"sh", "-c", "umask 0000 && exec tar -xmf -"}, content, claimName, namespace)
8081
}
8182

pkg/pipelines/tekton/pipelines_provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func NewPipelinesProvider(opts ...Opt) *PipelinesProvider {
106106
// Returned is the final url, and the input Function with the final results of the run populated
107107
// (f.Deploy.Image and f.Deploy.Namespace) or an error.
108108
func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) (string, fn.Function, error) {
109+
fmt.Println("#### pp.Run")
109110
var err error
110111

111112
// Checks builder and registry:

pkg/pipelines/tekton/tasks.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import (
66
)
77

88
var (
9+
// FuncUtilImage = utilsImage()
910
FuncUtilImage = "ghcr.io/knative/func-utils:v2"
11+
//FuncUtilImageDefault = "ghcr.io/knative/func-utils:v2"
1012
DeployerImage string
1113
ScaffoldImage string
1214
S2IImage string
1315
)
1416

1517
func init() {
18+
fmt.Printf("[DEBUG] pkg/pipelines/tekton/tasks.go: Initial FuncUtilImage = %s\n", FuncUtilImage)
19+
1620
if DeployerImage == "" {
1721
DeployerImage = FuncUtilImage
1822
}
@@ -22,8 +26,21 @@ func init() {
2226
if S2IImage == "" {
2327
S2IImage = FuncUtilImage
2428
}
29+
30+
fmt.Printf("[DEBUG] pkg/pipelines/tekton/tasks.go: DeployerImage = %s\n", DeployerImage)
31+
fmt.Printf("[DEBUG] pkg/pipelines/tekton/tasks.go: ScaffoldImage = %s\n", ScaffoldImage)
32+
fmt.Printf("[DEBUG] pkg/pipelines/tekton/tasks.go: S2IImage = %s\n", S2IImage)
2533
}
2634

35+
//func utilsImage() string {
36+
// if val := os.Getenv("FUNC_UTILS_IMG"); val != "" {
37+
// fmt.Printf("Using existing '%v' utils image\n", val)
38+
// return val
39+
// }
40+
// fmt.Printf("Using default '%v' utils image\n", FuncUtilImageDefault)
41+
// return FuncUtilImageDefault
42+
//}
43+
2744
func getBuildpackTask() string {
2845
return `apiVersion: tekton.dev/v1
2946
kind: Task

pkg/pipelines/tekton/templates.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ func getTaskSpec(taskYaml string) (string, error) {
342342
// createAndApplyPipelineTemplate creates and applies Pipeline template for a standard on-cluster build
343343
// all resources are created on the fly, if there's a Pipeline defined in the project directory, it is used instead
344344
func createAndApplyPipelineTemplate(f fn.Function, namespace string, labels map[string]string) error {
345+
fmt.Println("#### createAndApplyPipelineTemplate")
345346
// If Git is set up create fetch task and reference it from build task,
346347
// otherwise sources have been already uploaded to workspace PVC.
347348
gitCloneTaskRef := ""
@@ -385,14 +386,16 @@ func createAndApplyPipelineTemplate(f fn.Function, namespace string, labels map[
385386
default:
386387
return builders.ErrBuilderNotSupported{Builder: f.Build.Builder}
387388
}
388-
389+
fmt.Printf("## BI: '%v'\n", data.BuilderImage)
389390
return createAndApplyResource(f.Root, pipelineFileName, template, "pipeline", getPipelineName(f), namespace, data)
390391
}
391392

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

419+
// add BP_GO_WORKDIR for go-build buildpack
420+
if f.Runtime == "go" {
421+
buildEnvs = append(buildEnvs, "BP_GO_WORKDIR=.func/builds/last")
422+
}
423+
416424
s2iImageScriptsUrl := defaultS2iImageScriptsUrl
417425
if f.Runtime == "quarkus" {
418426
s2iImageScriptsUrl = quarkusS2iImageScriptsUrl
@@ -445,7 +453,7 @@ func createAndApplyPipelineRunTemplate(f fn.Function, namespace string, labels m
445453
RepoUrl: f.Build.Git.URL,
446454
Revision: pipelinesTargetBranch,
447455
}
448-
456+
fmt.Printf("# data.BuilderImage: '%v'\n", data.BuilderImage)
449457
var template string
450458
switch f.Build.Builder {
451459
case builders.Pack:

0 commit comments

Comments
 (0)