Skip to content

Commit acef7ee

Browse files
authored
Remove embed wildcard (#4867)
In ea37dae an error was introduced invalidating the production provider build - a subtle error by moving a `go:embed` directory to wildcards and FS type. Per https://pkg.go.dev/embed#hdr-Strings_and_Bytes the path to a go:embed directory is a pattern. Apparently in the case of pulumi-aws CI the binary is built twice, once for testing and once for production release. In the for-testing build environment, schema-embed.json is a file which works as expected. In the for-production build environment, schema-embed.json is a folder created by the download-artifacts action that contains a single file. Before the change, this code worked correctly in both cases: ``` //go:embed schema-embed.json var pulumiSchema []byte ``` After the change, unfortunately the replacement code worked only for the for-test build scenario where schema-embed.json is a straight file, while failing in production. This change goes back to using the `[]byte` version of go:embed and makes sure the builds recompute the minimal schema as necessary for both builds to succeed. This fixes #4863 We still should address the root cause and refactor the builds to reduce double-building the provider, so that the exact release build is qualified by integration tests; which is tracked in pulumi/ci-mgmt#967
1 parent 9d0a03f commit acef7ee

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ yarn.lock
2020
ci-scripts
2121
provider/shim/coverage.txt
2222
provider/**/*-embed.json
23+
provider/**/schema-minimal.json
2324
**/version.txt
2425
**/nuget
2526
**/dist

.mk/minimal_schema.mk

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
minimal_schema: tfgen minimal_schema_no_deps
1+
minimal_schema: provider/cmd/pulumi-resource-aws/schema-minimal-embed.json
22

3-
minimal_schema_no_deps:
3+
.PHONY: minimal_schema
4+
5+
provider/cmd/pulumi-resource-aws/schema-minimal-embed.json: provider/cmd/pulumi-resource-aws/schema.json
46
echo "Computing minimal schema"
57
cd provider/cmd/pulumi-resource-aws && PULUMI_AWS_MINIMAL_SCHEMA=true VERSION=$(VERSION_GENERIC) go generate
6-
.PHONY: minimal_schema minimal_schema_no_deps
78

8-
# To work around CI limitations, ensure that minimal schema is rebuilt for embedding right before the provider binary is
9-
# built for a given platform.
10-
bin/linux-amd64/$(PROVIDER): minimal_schema_no_deps
11-
bin/linux-arm64/$(PROVIDER): minimal_schema_no_deps
12-
bin/darwin-amd64/$(PROVIDER): minimal_schema_no_deps
13-
bin/darwin-arm64/$(PROVIDER): minimal_schema_no_deps
14-
bin/windows-amd64/$(PROVIDER).exe: minimal_schema_no_deps
15-
provider_no_deps: minimal_schema_no_deps
16-
provider: minimal_schema_no_deps
9+
# In build_provider.yml workflow, minimal schema needs to be rebuilt right before the provider binary.
10+
bin/linux-amd64/$(PROVIDER): minimal_schema
11+
bin/linux-arm64/$(PROVIDER): minimal_schema
12+
bin/darwin-amd64/$(PROVIDER): minimal_schema
13+
bin/darwin-arm64/$(PROVIDER): minimal_schema
14+
bin/windows-amd64/$(PROVIDER).exe: minimal_schema
15+
16+
# In prerequisites.yml workflow, minimal schema needs to be rebuilt right before the provider binary.
17+
bin/pulumi-resource-aws: minimal_schema

provider/cmd/pulumi-resource-aws/main.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package main
1818

1919
import (
20+
"bytes"
2021
"compress/gzip"
2122
"context"
22-
"embed"
23+
_ "embed"
2324
"io"
2425
"os"
2526

@@ -29,15 +30,16 @@ import (
2930
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
3031
)
3132

32-
//go:embed schema*embed.json
33-
var schemas embed.FS
33+
//go:embed schema-embed.json
34+
var pulumiSchema []byte
35+
36+
//go:embed schema-minimal-embed.json
37+
var pulumiMinimalSchema []byte
3438

3539
// The data in the minimal schema is compressed with GZIP to avoid bloating the provider size at the cost of slightly
3640
// slower init for uses of the feature.
3741
func decompressMinimalSchema() []byte {
38-
reader0, err := schemas.Open("schema-minimal-embed.json")
39-
contract.AssertNoErrorf(err, "Failed to open a reader into the embedded schema-minimal-embed.json")
40-
reader, err := gzip.NewReader(reader0)
42+
reader, err := gzip.NewReader(bytes.NewReader(pulumiMinimalSchema))
4143
contract.AssertNoErrorf(err, "Failed to open a reader into schema-minimal-embed.json")
4244
bytes, err := io.ReadAll(reader)
4345
contract.AssertNoErrorf(err, "Failed to read schema-minimal-embed.json")
@@ -52,10 +54,7 @@ func main() {
5254
if cmdutil.IsTruthy(os.Getenv("PULUMI_AWS_MINIMAL_SCHEMA")) {
5355
schemaBytes = decompressMinimalSchema()
5456
} else {
55-
schemaReader, err := schemas.Open("schema-embed.json")
56-
contract.AssertNoErrorf(err, "Failed to open a reader into the embedded schema-embed.json")
57-
schemaBytes, err = io.ReadAll(schemaReader)
58-
contract.AssertNoErrorf(err, "Failed to read schema-embed.json")
57+
schemaBytes = pulumiSchema
5958
}
6059

6160
pf.MainWithMuxer(ctx, "aws", *info, schemaBytes)

0 commit comments

Comments
 (0)