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

refactor: remove runtime binaries from main deployment package paths #595

Merged
merged 14 commits into from
Apr 5, 2024
16 changes: 8 additions & 8 deletions cloud/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ GOLANGCI_LINT ?= GOLANGCI_LINT_CACHE=$(GOLANGCI_LINT_CACHE) go run github.com/go
binaries: deploybin

sec:
@touch deploy/runtime-aws
@touch deploy/runtime/runtime-aws
@go run github.com/securego/gosec/v2/cmd/gosec@latest -exclude-dir=tools ./...
@rm deploy/runtime-aws
@rm deploy/runtime/runtime-aws

# build runtime binary directly into the deploy director so it can be embedded directly into the deployment engine binary
# We only build a linux amd64 binary here to be packaged for cloud runtimes with docker
Expand All @@ -20,12 +20,12 @@ runtimebin:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/runtime-aws -ldflags="-s -w -extldflags=-static" ./cmd/runtime

predeploybin: runtimebin
@cp bin/runtime-aws deploy/runtime-aws
@cp bin/runtime-aws deploy/runtime/runtime-aws

deploybin: predeploybin
@echo Building AWS Deployment Server
@CGO_ENABLED=0 go build -o bin/deploy-aws -ldflags="-s -w -extldflags=-static" -ldflags="-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore" ./cmd/deploy
@rm deploy/runtime-aws
@rm deploy/runtime/runtime-aws

.PHONY: install
install: deploybin
Expand All @@ -42,15 +42,15 @@ sourcefiles := $(shell find . -type f -name "*.go" -o -name "*.dockerfile")

fmt:
@go run github.com/google/addlicense -c "Nitric Technologies Pty Ltd." -y "2021" $(sourcefiles)
@touch deploy/runtime-aws
@touch deploy/runtime/runtime-aws
$(GOLANGCI_LINT) run --fix
@rm deploy/runtime-aws
@rm deploy/runtime/runtime-aws

lint:
@go run github.com/google/addlicense -check -c "Nitric Technologies Pty Ltd." -y "2021" $(sourcefiles)
@touch deploy/runtime-aws
@touch deploy/runtime/runtime-aws
$(GOLANGCI_LINT) run
@rm deploy/runtime-aws
@rm deploy/runtime/runtime-aws

test: generate-mocks
@echo Running unit tests
Expand Down
3 changes: 2 additions & 1 deletion cloud/aws/cmd/deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package main

import (
"github.com/nitrictech/nitric/cloud/aws/deploy"
"github.com/nitrictech/nitric/cloud/aws/deploy/runtime"
"github.com/nitrictech/nitric/cloud/common/deploy/provider"
)

// Start the deployment server
func main() {
awsStack := deploy.NewNitricAwsProvider()

providerServer := provider.NewPulumiProviderServer(awsStack)
providerServer := provider.NewPulumiProviderServer(awsStack, runtime.NitricAwsRuntime)

providerServer.Start()
}
20 changes: 10 additions & 10 deletions cloud/aws/deploy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type nameArnPair struct {
func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resource, name string, config *deploymentspb.Api) error {
opts := []pulumi.ResourceOption{pulumi.Parent(parent)}

nameArnPairs := make([]interface{}, 0, len(a.lambdas))
nameArnPairs := make([]interface{}, 0, len(a.Lambdas))

if config.GetOpenapi() == "" {
return fmt.Errorf("aws provider can only deploy OpenAPI specs")
Expand Down Expand Up @@ -114,7 +114,7 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
if v, ok := op.Extensions["x-nitric-target"]; ok {
if targetMap, isMap := v.(map[string]any); isMap {
serviceName := targetMap["name"].(string)
nitricServiceTargets[serviceName] = a.lambdas[serviceName]
nitricServiceTargets[serviceName] = a.Lambdas[serviceName]
}
}
}
Expand All @@ -133,7 +133,7 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
}))
}

apiGatewayTags := tags.Tags(a.stackId, name, resources.API)
apiGatewayTags := tags.Tags(a.StackId, name, resources.API)

doc := pulumi.All(nameArnPairs...).ApplyT(func(pairs []interface{}) (string, error) {
naps := make(map[string]string)
Expand Down Expand Up @@ -175,7 +175,7 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
return string(b), nil
}).(pulumi.StringOutput)

a.apis[name], err = apigatewayv2.NewApi(ctx, name, &apigatewayv2.ApiArgs{
a.Apis[name], err = apigatewayv2.NewApi(ctx, name, &apigatewayv2.ApiArgs{
Body: doc,
// Name fixed to title in the spec, if these mismatch the name will change on the second deployment.
Name: pulumi.String(openapiDoc.Info.Title),
Expand All @@ -190,7 +190,7 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
apiStage, err := apigatewayv2.NewStage(ctx, name+"DefaultStage", &apigatewayv2.StageArgs{
AutoDeploy: pulumi.BoolPtr(true),
Name: pulumi.String("$default"),
ApiId: a.apis[name].ID(),
ApiId: a.Apis[name].ID(),
// Tags: pulumi.ToStringMap(common.Tags(args.StackID, name+"DefaultStage", resources.API)),
}, opts...)
if err != nil {
Expand All @@ -203,23 +203,23 @@ func (a *NitricAwsPulumiProvider) Api(ctx *pulumi.Context, parent pulumi.Resourc
Function: fun.Name,
Action: pulumi.String("lambda:InvokeFunction"),
Principal: pulumi.String("apigateway.amazonaws.com"),
SourceArn: pulumi.Sprintf("%s/*/*/*", a.apis[name].ExecutionArn),
SourceArn: pulumi.Sprintf("%s/*/*/*", a.Apis[name].ExecutionArn),
}, opts...)
if err != nil {
return err
}
}

endPoint := a.apis[name].ApiEndpoint.ApplyT(func(ep string) string {
endPoint := a.Apis[name].ApiEndpoint.ApplyT(func(ep string) string {
return ep
}).(pulumi.StringInput)

if a.config.Apis[name] != nil {
if a.AwsConfig.Apis[name] != nil {
// For each specified domain name
for _, domainName := range a.config.Apis[name].Domains {
for _, domainName := range a.AwsConfig.Apis[name].Domains {
_, err := newDomainName(ctx, name, domainNameArgs{
domainName: domainName,
api: a.apis[name],
api: a.Apis[name],
stage: apiStage,
})
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions cloud/aws/deploy/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ func (a *NitricAwsPulumiProvider) Bucket(ctx *pulumi.Context, parent pulumi.Reso
opts := []pulumi.ResourceOption{pulumi.Parent(parent)}

bucket, err := s3.NewBucket(ctx, name, &s3.BucketArgs{
Tags: pulumi.ToStringMap(common.Tags(a.stackId, name, resources.Bucket)),
Tags: pulumi.ToStringMap(common.Tags(a.StackId, name, resources.Bucket)),
}, opts...)
if err != nil {
return err
}

a.buckets[name] = bucket
a.Buckets[name] = bucket

if len(config.Listeners) > 0 {
notificationName := fmt.Sprintf("notification-%s", name)
notification, err := createNotification(ctx, notificationName, &S3NotificationArgs{
StackID: a.stackId,
Location: a.region,
StackID: a.StackId,
Location: a.Region,
Bucket: bucket,
Lambdas: a.lambdas,
Lambdas: a.Lambdas,
Listeners: config.Listeners,
}, opts...)
if err != nil {
return err
}

a.bucketNotifications[name] = notification
a.BucketNotifications[name] = notification
}

return nil
Expand Down
Loading
Loading