Add runtime.options.binary to Pulumi.yaml to make prebuilt go binaries opt-in (#4338)
This commit is contained in:
parent
ec9eba63ba
commit
cfea357cda
|
@ -29,6 +29,9 @@ CHANGELOG
|
|||
- Add overloads to Output.All in .NET
|
||||
[#4321](https://github.com/pulumi/pulumi/pull/4321)
|
||||
|
||||
- Make prebuilt executables opt-in only for the Go SDK
|
||||
[#4338](https://github.com/pulumi/pulumi/pull/4338)
|
||||
|
||||
- Add helper methods for stack outputs in the Go SDK
|
||||
[#4341](https://github.com/pulumi/pulumi/pull/4341)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ func NewLanguageRuntime(host Host, ctx *Context, runtime string,
|
|||
|
||||
var args []string
|
||||
for k, v := range options {
|
||||
args = append(args, fmt.Sprintf("-%s=%t", k, v))
|
||||
args = append(args, fmt.Sprintf("-%s=%v", k, v))
|
||||
}
|
||||
args = append(args, host.ServerAddr())
|
||||
|
||||
|
|
|
@ -42,12 +42,10 @@ import (
|
|||
pulumirpc "github.com/pulumi/pulumi/sdk/proto/go"
|
||||
)
|
||||
|
||||
const unableToFindProgramTemplate = "unable to find program: %s"
|
||||
|
||||
// findExecutable attempts to find the needed executable in various locations on the
|
||||
// filesystem, eventually resorting to searching in $PATH.
|
||||
func findExecutable(program string) (string, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
if runtime.GOOS == "windows" && !strings.HasSuffix(program, ".exe") {
|
||||
program = fmt.Sprintf("%s.exe", program)
|
||||
}
|
||||
// look in the same directory
|
||||
|
@ -77,28 +75,28 @@ func findExecutable(program string) (string, error) {
|
|||
return fullPath, nil
|
||||
}
|
||||
|
||||
return "", errors.Errorf(unableToFindProgramTemplate, program)
|
||||
return "", errors.Errorf("unable to find program: %s", program)
|
||||
}
|
||||
|
||||
func findProgram(project string) (*exec.Cmd, error) {
|
||||
// The program to execute is simply the name of the project. This ensures good Go toolability, whereby
|
||||
// you can simply run `go install .` to build a Pulumi program prior to running it, among other benefits.
|
||||
// For ease of use, if we don't find a pre-built program, we attempt to invoke via 'go run' on behalf of the user.
|
||||
program, err := findExecutable(project)
|
||||
if err == nil {
|
||||
func findProgram(binary string) (*exec.Cmd, error) {
|
||||
// we default to execution via `go run`
|
||||
// the user can explicitly opt in to using a binary executable by specifying
|
||||
// runtime.options.binary in the Pulumi.yaml
|
||||
if binary != "" {
|
||||
program, err := findExecutable(binary)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "expected to find prebuilt executable")
|
||||
}
|
||||
return exec.Command(program), nil
|
||||
}
|
||||
|
||||
const message = "problem executing program (could not run language executor)"
|
||||
if err.Error() == fmt.Sprintf(unableToFindProgramTemplate, project) {
|
||||
logging.V(5).Infof("Unable to find program %s in $PATH, attempting invocation via 'go run'", program)
|
||||
program, err = findExecutable("go")
|
||||
}
|
||||
// Fall back to 'go run' style executions
|
||||
logging.V(5).Infof("No prebuilt executable specified, attempting invocation via 'go run'")
|
||||
program, err := findExecutable("go")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, message)
|
||||
return nil, errors.Wrap(err, "problem executing program (could not run language executor)")
|
||||
}
|
||||
|
||||
// Fall back to 'go run' style execution
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to get current working directory")
|
||||
|
@ -115,7 +113,9 @@ func findProgram(project string) (*exec.Cmd, error) {
|
|||
// Launches the language host, which in turn fires up an RPC server implementing the LanguageRuntimeServer endpoint.
|
||||
func main() {
|
||||
var tracing string
|
||||
var binary string
|
||||
flag.StringVar(&tracing, "tracing", "", "Emit tracing to a Zipkin-compatible tracing endpoint")
|
||||
flag.StringVar(&binary, "binary", "", "Look on path for a binary executable with this name")
|
||||
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
|
@ -131,7 +131,7 @@ func main() {
|
|||
// Fire up a gRPC server, letting the kernel choose a free port.
|
||||
port, done, err := rpcutil.Serve(0, nil, []func(*grpc.Server) error{
|
||||
func(srv *grpc.Server) error {
|
||||
host := newLanguageHost(engineAddress, tracing)
|
||||
host := newLanguageHost(engineAddress, tracing, binary)
|
||||
pulumirpc.RegisterLanguageRuntimeServer(srv, host)
|
||||
return nil
|
||||
},
|
||||
|
@ -153,12 +153,14 @@ func main() {
|
|||
type goLanguageHost struct {
|
||||
engineAddress string
|
||||
tracing string
|
||||
binary string
|
||||
}
|
||||
|
||||
func newLanguageHost(engineAddress, tracing string) pulumirpc.LanguageRuntimeServer {
|
||||
func newLanguageHost(engineAddress, tracing, binary string) pulumirpc.LanguageRuntimeServer {
|
||||
return &goLanguageHost{
|
||||
engineAddress: engineAddress,
|
||||
tracing: tracing,
|
||||
binary: binary,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,7 +278,7 @@ func (host *goLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest)
|
|||
return nil, errors.Wrap(err, "failed to prepare environment")
|
||||
}
|
||||
|
||||
cmd, err := findProgram(req.GetProject())
|
||||
cmd, err := findProgram(host.binary)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue