-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02be178
commit eedefc0
Showing
3 changed files
with
80 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/streamingfast/cli" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
pbbuild "github.com/streamingfast/substreams/remotebuild/pb/sf/remotebuild/v1" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(remoteBuildCmd) | ||
} | ||
|
||
var remoteBuildCmd = &cobra.Command{ | ||
Use: "remote-build <remote-build-url> <zipped_source_code>", | ||
Short: "Send request to remote build server to build and package a substreams", | ||
Long: cli.Dedent(` | ||
Call the remote build server to build and package a substream. | ||
Examples: substreams remote-build https://substreams-remotebuild-endpoint:443 my-substream.zip | ||
`), | ||
RunE: remoteBuildE, | ||
Args: cobra.ExactArgs(2), | ||
SilenceUsage: true, | ||
} | ||
|
||
func remoteBuildE(cmd *cobra.Command, args []string) error { | ||
remoteBuildURL := args[0] | ||
filepath := args[2] | ||
|
||
fmt.Println("Connecting to remote build server...") | ||
conn, err := grpc.NewClient(remoteBuildURL, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
return fmt.Errorf("failed to connect: %w", err) | ||
} | ||
|
||
fmt.Println("Reading file...") | ||
b, err := os.ReadFile(filepath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read file: %w", err) | ||
} | ||
|
||
client := pbbuild.NewBuildServiceClient(conn) | ||
buildResponse, err := client.Build(context.Background(), &pbbuild.BuildRequest{ | ||
SourceCode: b, | ||
Env: []string{"ENV1=test", ""}, | ||
CollectPattern: "substreams.spkg", | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("failed to build: %w", err) | ||
} | ||
|
||
for _, artifact := range buildResponse.Artifacts { | ||
fmt.Printf("Writing file %s...\n", artifact.Filename) | ||
err = os.WriteFile(artifact.Filename, artifact.Content, 0644) | ||
if err != nil { | ||
return fmt.Errorf("failed to write file: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters