diff --git a/cloud/common/deploy/image/image.go b/cloud/common/deploy/image/image.go index e580c25a4..7b8deddb3 100644 --- a/cloud/common/deploy/image/image.go +++ b/cloud/common/deploy/image/image.go @@ -83,7 +83,7 @@ func NewImage(ctx *pulumi.Context, name string, args *ImageArgs, opts ...pulumi. } buildContext := fmt.Sprintf("%s/build-%s", os.TempDir(), name) - err = os.MkdirAll(buildContext, os.ModePerm) + err = os.MkdirAll(buildContext, 0o750) if err != nil { return nil, err } diff --git a/cloud/gcp/deploy/api.go b/cloud/gcp/deploy/api.go index 59a97b92a..88c30edda 100644 --- a/cloud/gcp/deploy/api.go +++ b/cloud/gcp/deploy/api.go @@ -41,6 +41,7 @@ import ( type nameUrlPair struct { name string invokeUrl string + timeout int } func (p *NitricGcpPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resource, name string, apiConfig *deploymentspb.Api) error { @@ -124,9 +125,16 @@ func (p *NitricGcpPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc // collect name arn pairs for output iteration for k, v := range services { - nameUrlPairs = append(nameUrlPairs, pulumi.All(k, v.Url).ApplyT(func(args []interface{}) (nameUrlPair, error) { + nameUrlPairs = append(nameUrlPairs, pulumi.All(k, v.Url, v.Service.Template.Spec().TimeoutSeconds()).ApplyT(func(args []interface{}) (nameUrlPair, error) { name, nameOk := args[0].(string) url, urlOk := args[1].(string) + timeoutPtr, timeoutOk := args[2].(*int) + + timeout := 15 + + if timeoutOk && timeoutPtr != nil { + timeout = *timeoutPtr + } if !nameOk || !urlOk { return nameUrlPair{}, fmt.Errorf("invalid data %T %v", args, args) @@ -135,6 +143,7 @@ func (p *NitricGcpPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc return nameUrlPair{ name: name, invokeUrl: url, + timeout: timeout, }, nil })) } @@ -144,22 +153,24 @@ func (p *NitricGcpPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc // Replace Nitric API Extensions with google api gateway extensions doc := pulumi.All(nameUrlPairs...).ApplyT(func(pairs []interface{}) (string, error) { naps := make(map[string]string) + timeouts := make(map[string]int) for _, p := range pairs { if pair, ok := p.(nameUrlPair); ok { naps[pair.name] = pair.invokeUrl + timeouts[pair.name] = pair.timeout } else { return "", fmt.Errorf("failed to resolve Cloud Run container URL for api %s, invalid name URL pair value %T %v, %s", name, p, p, help.BugInNitricHelpText()) } } for k, p := range v2doc.Paths { - p.Get = gcpOperation(name, p.Get, naps) - p.Post = gcpOperation(name, p.Post, naps) - p.Patch = gcpOperation(name, p.Patch, naps) - p.Put = gcpOperation(name, p.Put, naps) - p.Delete = gcpOperation(name, p.Delete, naps) - p.Options = gcpOperation(name, p.Options, naps) + p.Get = gcpOperation(name, p.Get, naps, timeouts) + p.Post = gcpOperation(name, p.Post, naps, timeouts) + p.Patch = gcpOperation(name, p.Patch, naps, timeouts) + p.Put = gcpOperation(name, p.Put, naps, timeouts) + p.Delete = gcpOperation(name, p.Delete, naps, timeouts) + p.Options = gcpOperation(name, p.Options, naps, timeouts) v2doc.Paths[k] = p } @@ -266,7 +277,7 @@ func keepOperation(opExt map[string]interface{}) (string, bool) { return name, true } -func gcpOperation(apiName string, op *openapi2.Operation, urls map[string]string) *openapi2.Operation { +func gcpOperation(apiName string, op *openapi2.Operation, urls map[string]string, timeouts map[string]int) *openapi2.Operation { if op == nil { return nil } @@ -298,10 +309,11 @@ func gcpOperation(apiName string, op *openapi2.Operation, urls map[string]string } } - op.Extensions["x-google-backend"] = map[string]string{ + op.Extensions["x-google-backend"] = map[string]any{ // Append the name of the target origin api gateway to the target address "address": fmt.Sprintf("%s/x-nitric-api/%s", urls[name], apiName), "path_translation": "APPEND_PATH_TO_ADDRESS", + "deadline": timeouts[name], } return op