Skip to content
Merged
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
26 changes: 25 additions & 1 deletion pkg/builders/builders_int_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package builders_test

import (
Expand Down Expand Up @@ -35,7 +37,6 @@ import (
)

func TestPrivateGitRepository(t *testing.T) {
t.Skip("tested functionality not implemented yet")

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -65,6 +66,21 @@ func TestPrivateGitRepository(t *testing.T) {
t.Fatal(ctx.Err())
}

gitCredsDir := t.TempDir()
err := os.WriteFile(filepath.Join(gitCredsDir, "type"), []byte(`git-credentials`), 0600)
if err != nil {
t.Fatal(err)
}

gitCred := `url=https://git-private.127.0.0.1.sslip.io
username=developer
password=nbusr123
`
err = os.WriteFile(filepath.Join(gitCredsDir, "credentials"), []byte(gitCred), 0600)
if err != nil {
t.Fatal(err)
}

builder := buildpacks.NewBuilder(buildpacks.WithVerbose(true))
f, err := fn.NewFunction(filepath.Join("testdata", "go-fn-with-private-deps"))
if err != nil {
Expand All @@ -73,6 +89,14 @@ func TestPrivateGitRepository(t *testing.T) {
f.Build.Image = "localhost:50000/go-app:test"
f.Build.Builder = "pack"
f.Build.BuilderImages = map[string]string{"pack": builderImage}
f.Build.BuildEnvs = []fn.Env{{
Name: ptr("SERVICE_BINDING_ROOT"),
Value: ptr("/bindings"),
}}
f.Build.Mounts = []fn.MountSpec{{
Source: gitCredsDir,
Destination: "/bindings/git-binding",
}}
err = builder.Build(ctx, f, nil)
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 6 additions & 0 deletions pkg/builders/buildpacks/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
opts.ContainerConfig.Network = "host"
}

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))
}
opts.ContainerConfig.Volumes = bindings

// only trust our known builders
opts.TrustBuilder = TrustBuilder

Expand Down
8 changes: 8 additions & 0 deletions pkg/functions/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ type BuildSpec struct {
// Image stores last built image name NOT in func.yaml, but instead
// in .func/built-image
Image string `yaml:"-"`

// Mounts used in build phase. This is useful in particular for paketo bindings.
Mounts []MountSpec `yaml:"mounts,omitempty"`
}

type MountSpec struct {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative to this new type would be to reuse our Volume type and just add Source *string member to it.
WDYT @lkingland ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could to a degree help on cluster and local build unification.

Source string `yaml:"source"`
Destination string `yaml:"destination"`
}

// RunSpec
Expand Down
24 changes: 24 additions & 0 deletions schema/func_yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
"remoteStorageClass": {
"type": "string",
"description": "RemoteStorageClass specifies the storage class to use for the volume used\non-cluster during when built remotely."
},
"mounts": {
"items": {
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/MountSpec"
},
"type": "array",
"description": "Mounts used in build phase. This is useful in particular for paketo bindings."
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -269,6 +277,22 @@
"additionalProperties": false,
"type": "object"
},
"MountSpec": {
"required": [
"source",
"destination"
],
"properties": {
"source": {
"type": "string"
},
"destination": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"Options": {
"properties": {
"scale": {
Expand Down
Loading