Skip to content

Commit 64d4646

Browse files
author
Kenneth Rosario
authored
feat: add support for specifying what builder to use (#125)
1 parent fae8c2f commit 64d4646

File tree

12 files changed

+56
-12
lines changed

12 files changed

+56
-12
lines changed

.github/workflows/buildpack-integration-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ on:
2727
type: string
2828
default: ''
2929
required: false
30+
builder-url:
31+
description: Builder image including builder tag to use while building. (e.g. gcr.io/gae-runtimes/buildpacks/go/builder:latest or gcr.io/buildpacks/builder:latest )
32+
type: string
33+
default: ''
34+
required: false
3035
event-builder-source:
3136
description: Background function source; relative to repo root
3237
type: string
@@ -162,6 +167,7 @@ jobs:
162167
-builder-runtime=${{ inputs.builder-runtime }} \
163168
-builder-runtime-version=${{ inputs.builder-runtime-version }} \
164169
-builder-tag=${{ inputs.builder-tag }} \
170+
-builder-url=${{ inputs.builder-url }} \
165171
-start-delay=${{ inputs.start-delay }} \
166172
-output-file=${{ inputs.output-file }} \
167173
-validate-mapping=false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Buildpack Integration Test Workflow Validation
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
validate-workflow:
9+
strategy:
10+
matrix:
11+
builder-url: ['gcr.io/gae-runtimes/buildpacks/go/builder:latest', '']
12+
uses: ./.github/workflows/buildpack-integration-test.yml
13+
with:
14+
builder-runtime: 'go113'
15+
builder-runtime-version: '1.13'
16+
http-builder-source: 'testdata'
17+
http-builder-target: 'HTTP'
18+
cloudevent-builder-source: ''
19+
cloudevent-builder-target: ''
20+
builder-url: ${{ matrix.builder-url }}
21+
conformance-client-version: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ jobs:
4040
-builder-source='testdata' \
4141
-builder-target='HTTP' \
4242
-builder-runtime='go113' \
43-
-builder-runtime-version='1.13'
43+
-builder-runtime-version='1.13' \
44+
-builder-url='gcr.io/gae-runtimes/buildpacks/go/builder:latest'

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ Frameworks to the Functions Framework contract.
9090
| `-builder-target` | string | `""` | Function target to use in building. Required if `-buildpacks=true`. |
9191
| `-builder-runtime` | string | `""` | Runtime to use in building. Required if `-buildpacks=true`. |
9292
| `-builder-runtime-version` | string | `""` | Runtime version used while building. Buildpack will use the latest version if flag is not specified. |
93-
| `-builder-tag` | string | `"latest"` | Builder image tag to use in building. |
93+
| `-builder-tag` | string | `"latest"` | Builder image tag to use in building. Ignored if `-builder-url` is specified. |
94+
| `-builder-url` | string | `""` | Builder image url to use in building including tag. Client defaults to `gcr.io/gae-runtimes/buildpacks/<language>/builder:<builder-tag>` if none is specified. |
9495
| `-start-delay` | uint | `1` | Seconds to wait before sending HTTP request to command process. |
9596
| `-envs` | string | `""` | A comma separated string of additional runtime environment variables. |
9697

action/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ inputs:
3131
runtimeVersion:
3232
description: 'function runtime version, uses the latest version if not specified (e.g. 3.7.4 for python37 runtime)'
3333
default: ''
34+
builderURL:
35+
description: 'builder url to use when building'
36+
default: ''
3437
tag:
3538
description: 'GCR tag to use for builder image'
3639
default: 'latest'

action/dist/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async function run() {
2727
const target = core.getInput('target');
2828
const runtime = core.getInput('runtime');
2929
const runtimeVersion = core.getInput('runtimeVersion');
30+
const builderURL = core.getInput('builderURL');
3031
const tag = core.getInput('tag');
3132
const useBuildpacks = core.getInput('useBuildpacks');
3233
const cmd = core.getInput('cmd');
@@ -67,6 +68,7 @@ async function run() {
6768
`-builder-runtime=${runtime}`,
6869
`-builder-runtime-version=${runtimeVersion}`,
6970
`-builder-tag=${tag}`,
71+
`-builder-url=${builderURL}`,
7072
`-buildpacks=${useBuildpacks}`,
7173
`-cmd=${cmd}`,
7274
`-start-delay=${startDelay}`,

client/buildpacks.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131
)
3232

3333
const (
34-
image = "conformance-test-func"
35-
builderURL = "gcr.io/gae-runtimes/buildpacks/%s/builder:%s"
36-
gcfTargetPlatform = "gcf"
34+
image = "conformance-test-func"
35+
defaultBuilderURLTemplate = "gcr.io/gae-runtimes/buildpacks/%s/builder:%s"
36+
gcfTargetPlatform = "gcf"
3737
)
3838

3939
type buildpacksFunctionServer struct {
@@ -49,6 +49,7 @@ type buildpacksFunctionServer struct {
4949
logStderr *os.File
5050
stdoutFile string
5151
stderrFile string
52+
builderURL string
5253
envs []string
5354
}
5455

@@ -123,11 +124,14 @@ func (b *buildpacksFunctionServer) build(ctx context.Context) error {
123124
var runtimeLanguageRegexp = regexp.MustCompile(`^[a-zA-Z]+`)
124125

125126
func (b *buildpacksFunctionServer) buildpackBuilderImage() (string, error) {
127+
if b.builderURL != "" {
128+
return b.builderURL, nil
129+
}
126130
runtimeLanguage := runtimeLanguageRegexp.FindString(b.runtime)
127131
if runtimeLanguage == "" {
128-
return "", fmt.Errorf("Invalid runtime format. Runtime should start with language followed by version. Example: go119, python311. Got %q", b.runtime)
132+
return "", fmt.Errorf("invalid runtime format. Runtime should start with language followed by version. Example: go119, python311. Got %q", b.runtime)
129133
}
130-
return fmt.Sprintf(builderURL, runtimeLanguage, b.tag), nil
134+
return fmt.Sprintf(defaultBuilderURLTemplate, runtimeLanguage, b.tag), nil
131135
}
132136

133137
func (b *buildpacksFunctionServer) run() (func(), error) {

client/buildpacks_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestBuildpackBuilderImage(t *testing.T) {
1717
name: "Extracts go from go119",
1818
runtime: "go119",
1919
tag: "1.2.3",
20-
wantBuilderURL: fmt.Sprintf(builderURL, "go", "1.2.3"),
20+
wantBuilderURL: fmt.Sprintf(defaultBuilderURLTemplate, "go", "1.2.3"),
2121
},
2222
{
2323
name: "Fails with incorrect runtime format",
@@ -29,19 +29,19 @@ func TestBuildpackBuilderImage(t *testing.T) {
2929
name: "Extracts php from php82",
3030
runtime: "php82",
3131
tag: "latest",
32-
wantBuilderURL: fmt.Sprintf(builderURL, "php", "latest"),
32+
wantBuilderURL: fmt.Sprintf(defaultBuilderURLTemplate, "php", "latest"),
3333
},
3434
{
3535
name: "Extracts nodejs from nodejs18",
3636
runtime: "nodejs18",
3737
tag: "18",
38-
wantBuilderURL: fmt.Sprintf(builderURL, "nodejs", "18"),
38+
wantBuilderURL: fmt.Sprintf(defaultBuilderURLTemplate, "nodejs", "18"),
3939
},
4040
{
4141
name: "Extracts dotnet from dotnet6",
4242
runtime: "dotnet6",
4343
tag: "123",
44-
wantBuilderURL: fmt.Sprintf(builderURL, "dotnet", "123"),
44+
wantBuilderURL: fmt.Sprintf(defaultBuilderURLTemplate, "dotnet", "123"),
4545
},
4646
}
4747

0 commit comments

Comments
 (0)