Skip to content

Commit

Permalink
Remove embed wildcard (#4867)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
t0yv0 authored Dec 2, 2024
1 parent 9d0a03f commit acef7ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ yarn.lock
ci-scripts
provider/shim/coverage.txt
provider/**/*-embed.json
provider/**/schema-minimal.json
**/version.txt
**/nuget
**/dist
Expand Down
25 changes: 13 additions & 12 deletions .mk/minimal_schema.mk
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
minimal_schema: tfgen minimal_schema_no_deps
minimal_schema: provider/cmd/pulumi-resource-aws/schema-minimal-embed.json

minimal_schema_no_deps:
.PHONY: minimal_schema

provider/cmd/pulumi-resource-aws/schema-minimal-embed.json: provider/cmd/pulumi-resource-aws/schema.json
echo "Computing minimal schema"
cd provider/cmd/pulumi-resource-aws && PULUMI_AWS_MINIMAL_SCHEMA=true VERSION=$(VERSION_GENERIC) go generate
.PHONY: minimal_schema minimal_schema_no_deps

# To work around CI limitations, ensure that minimal schema is rebuilt for embedding right before the provider binary is
# built for a given platform.
bin/linux-amd64/$(PROVIDER): minimal_schema_no_deps
bin/linux-arm64/$(PROVIDER): minimal_schema_no_deps
bin/darwin-amd64/$(PROVIDER): minimal_schema_no_deps
bin/darwin-arm64/$(PROVIDER): minimal_schema_no_deps
bin/windows-amd64/$(PROVIDER).exe: minimal_schema_no_deps
provider_no_deps: minimal_schema_no_deps
provider: minimal_schema_no_deps
# In build_provider.yml workflow, minimal schema needs to be rebuilt right before the provider binary.
bin/linux-amd64/$(PROVIDER): minimal_schema
bin/linux-arm64/$(PROVIDER): minimal_schema
bin/darwin-amd64/$(PROVIDER): minimal_schema
bin/darwin-arm64/$(PROVIDER): minimal_schema
bin/windows-amd64/$(PROVIDER).exe: minimal_schema

# In prerequisites.yml workflow, minimal schema needs to be rebuilt right before the provider binary.
bin/pulumi-resource-aws: minimal_schema
19 changes: 9 additions & 10 deletions provider/cmd/pulumi-resource-aws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package main

import (
"bytes"
"compress/gzip"
"context"
"embed"
_ "embed"
"io"
"os"

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

//go:embed schema*embed.json
var schemas embed.FS
//go:embed schema-embed.json
var pulumiSchema []byte

//go:embed schema-minimal-embed.json
var pulumiMinimalSchema []byte

// The data in the minimal schema is compressed with GZIP to avoid bloating the provider size at the cost of slightly
// slower init for uses of the feature.
func decompressMinimalSchema() []byte {
reader0, err := schemas.Open("schema-minimal-embed.json")
contract.AssertNoErrorf(err, "Failed to open a reader into the embedded schema-minimal-embed.json")
reader, err := gzip.NewReader(reader0)
reader, err := gzip.NewReader(bytes.NewReader(pulumiMinimalSchema))
contract.AssertNoErrorf(err, "Failed to open a reader into schema-minimal-embed.json")
bytes, err := io.ReadAll(reader)
contract.AssertNoErrorf(err, "Failed to read schema-minimal-embed.json")
Expand All @@ -52,10 +54,7 @@ func main() {
if cmdutil.IsTruthy(os.Getenv("PULUMI_AWS_MINIMAL_SCHEMA")) {
schemaBytes = decompressMinimalSchema()
} else {
schemaReader, err := schemas.Open("schema-embed.json")
contract.AssertNoErrorf(err, "Failed to open a reader into the embedded schema-embed.json")
schemaBytes, err = io.ReadAll(schemaReader)
contract.AssertNoErrorf(err, "Failed to read schema-embed.json")
schemaBytes = pulumiSchema
}

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

0 comments on commit acef7ee

Please sign in to comment.