Skip to content

Commit 0a94dc6

Browse files
author
Kenneth Rosario
authored
fix: use gcf runtime specific builder instead of unified builder (#120)
1 parent 252914c commit 0a94dc6

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

client/buildpacks.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"os/exec"
2525
"path/filepath"
26+
"regexp"
2627
"time"
2728

2829
pack "github.com/buildpacks/pack/pkg/client"
@@ -31,7 +32,7 @@ import (
3132

3233
const (
3334
image = "conformance-test-func"
34-
builderURL = "gcr.io/buildpacks/builder:%s"
35+
builderURL = "gcr.io/gae-runtimes/buildpacks/%s/builder:%s"
3536
gcfTargetPlatform = "gcf"
3637
)
3738

@@ -82,7 +83,10 @@ func (b *buildpacksFunctionServer) OutputFile() ([]byte, error) {
8283
}
8384

8485
func (b *buildpacksFunctionServer) build(ctx context.Context) error {
85-
builder := fmt.Sprintf(builderURL, b.tag)
86+
builder, err := b.buildpackBuilderImage()
87+
if err != nil {
88+
return err
89+
}
8690

8791
cmd := exec.Command("docker", "pull", builder)
8892
output, err := cmd.CombinedOutput()
@@ -114,6 +118,16 @@ func (b *buildpacksFunctionServer) build(ctx context.Context) error {
114118
return nil
115119
}
116120

121+
var runtimeLanguageRegexp = regexp.MustCompile(`^[a-zA-Z]+`)
122+
123+
func (b *buildpacksFunctionServer) buildpackBuilderImage() (string, error) {
124+
runtimeLanguage := runtimeLanguageRegexp.FindString(b.runtime)
125+
if runtimeLanguage == "" {
126+
return "", fmt.Errorf("Invalid runtime format. Runtime should start with language followed by version. Example: go119, python311. Got %q", b.runtime)
127+
}
128+
return fmt.Sprintf(builderURL, runtimeLanguage, b.tag), nil
129+
}
130+
117131
func (b *buildpacksFunctionServer) run() (func(), error) {
118132
// Create logs output files.
119133
var err error

client/buildpacks_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestBuildpackBuilderImage(t *testing.T) {
9+
testCases := []struct {
10+
name string
11+
runtime string
12+
tag string
13+
wantError bool
14+
wantBuilderURL string
15+
}{
16+
{
17+
name: "Extracts go from go119",
18+
runtime: "go119",
19+
tag: "1.2.3",
20+
wantBuilderURL: fmt.Sprintf(builderURL, "go", "1.2.3"),
21+
},
22+
{
23+
name: "Fails with incorrect runtime format",
24+
runtime: "11go",
25+
tag: "latest",
26+
wantError: true,
27+
},
28+
{
29+
name: "Extracts php from php82",
30+
runtime: "php82",
31+
tag: "latest",
32+
wantBuilderURL: fmt.Sprintf(builderURL, "php", "latest"),
33+
},
34+
{
35+
name: "Extracts nodejs from nodejs18",
36+
runtime: "nodejs18",
37+
tag: "18",
38+
wantBuilderURL: fmt.Sprintf(builderURL, "nodejs", "18"),
39+
},
40+
{
41+
name: "Extracts dotnet from dotnet6",
42+
runtime: "dotnet6",
43+
tag: "123",
44+
wantBuilderURL: fmt.Sprintf(builderURL, "dotnet", "123"),
45+
},
46+
}
47+
48+
for _, tc := range testCases {
49+
t.Run(tc.name, func(t *testing.T) {
50+
b := &buildpacksFunctionServer{
51+
runtime: tc.runtime,
52+
tag: tc.tag,
53+
}
54+
55+
builderImage, err := b.buildpackBuilderImage()
56+
57+
if err != nil && !tc.wantError {
58+
t.Fatalf("Got unexpected error: %v", err)
59+
}
60+
61+
if builderImage != tc.wantBuilderURL {
62+
t.Errorf("buildpackBuilderImage() = %q, want %q", builderImage, tc.wantBuilderURL)
63+
}
64+
})
65+
}
66+
}

0 commit comments

Comments
 (0)