Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute schema-minimal.json #4587

Merged
merged 18 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ yarn.lock

ci-scripts
provider/shim/coverage.txt
provider/**/schema-embed.json
provider/**/*-embed.json
**/version.txt
**/nuget
**/dist
Expand Down
58 changes: 41 additions & 17 deletions provider/cmd/pulumi-resource-aws/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,69 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"io/ioutil"
"log"
"os"

"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
)

func main() {
version, found := os.LookupEnv("VERSION")
if !found {
log.Fatal("version not found")
}
type compressAndVersionSchemaFileOptions struct {
sourceFile string
destFile string
version string
}

schemaContents, err := ioutil.ReadFile("./schema.json")
func compressAndVersionSchemaFile(opts compressAndVersionSchemaFileOptions) error {
schemaContents, err := os.ReadFile(opts.sourceFile)
if err != nil {
log.Fatal(err)
return fmt.Errorf("cannot read sourceFile: %w", err)
}

var packageSpec schema.PackageSpec
err = json.Unmarshal(schemaContents, &packageSpec)
if err != nil {
log.Fatalf("cannot deserialize schema: %v", err)
return fmt.Errorf("cannot deserialize schema: %w", err)
}

packageSpec.Version = version
packageSpec.Version = opts.version
versionedContents, err := json.Marshal(packageSpec)
if err != nil {
log.Fatalf("cannot reserialize schema: %v", err)
return fmt.Errorf("cannot reserialize schema: %w", err)
}
err = os.WriteFile(opts.destFile, versionedContents, 0600)
if err != nil {
return fmt.Errorf("cannot write destFile: %w", err)
}
return nil
}

func main() {
// Clean up schema.go as it may be present & gitignored and tolerate an error if the file isn't present.
err = os.Remove("./schema.go")
err := os.Remove("./schema.go")
if err != nil && !errors.Is(err, fs.ErrNotExist) {
log.Fatal(err)
}

err = ioutil.WriteFile("./schema-embed.json", versionedContents, 0600)
if err != nil {
log.Fatal(err)
version, found := os.LookupEnv("VERSION")
if !found {
log.Fatal("version not found")
}

for _, opts := range []compressAndVersionSchemaFileOptions{
{
sourceFile: "schema.json",
destFile: "schema-embed.json",
version: version,
},
{
sourceFile: "schema-light.json",
destFile: "schema-light-embed.json",
version: version,
},
} {
err = compressAndVersionSchemaFile(opts)
if err != nil {
log.Fatal(err)
}
}
}
13 changes: 12 additions & 1 deletion provider/cmd/pulumi-resource-aws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,27 @@ package main
import (
"context"
_ "embed"
"os"

aws "github.com/pulumi/pulumi-aws/provider/v6"
pf "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
)

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

//go:embed schema-light-embed.json
var pulumiSchemaLight []byte
t0yv0 marked this conversation as resolved.
Show resolved Hide resolved

func main() {
ctx := context.Background()
info := aws.Provider()
pf.MainWithMuxer(ctx, "aws", *info, pulumiSchema)

s := pulumiSchema
if cmdutil.IsTruthy(os.Getenv("PULUMI_AWS_LIGHT_SCHEMA")) {
t0yv0 marked this conversation as resolved.
Show resolved Hide resolved
s = pulumiSchemaLight
}

pf.MainWithMuxer(ctx, "aws", *info, s)
}
Loading
Loading