Skip to content

Commit

Permalink
feat: improve extensibility of providers (#665)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Holm <[email protected]>
  • Loading branch information
jyecusch and tjholm authored Aug 20, 2024
1 parent 2ed1381 commit e90f709
Show file tree
Hide file tree
Showing 79 changed files with 1,527 additions and 1,344 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
types: [published]

jobs:
# Bump the membrane version
# Bump the nitric server version
contract_release:
name: Add contracts to release
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- main
jobs:
# Bump the membrane version
# Bump the version
version_bump:
name: Bump Version and Create Release
runs-on: ubuntu-latest
Expand Down
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,59 @@ install-tools:

binaries: $(providers)
for dir in $(providers); do \
echo "Building $$dir"; \
$(MAKE) -C $$dir || exit 1; \
done

sec:
for dir in $(all); do \
echo "Running gosec on $$dir"; \
$(MAKE) sec -C $$dir || exit 1; \
done

check: lint test

fmt: $(all)
for dir in $(all); do \
echo "Formatting $$dir"; \
$(MAKE) fmt -C $$dir || exit 1; \
done

lint: $(all)
for dir in $(all); do \
echo "Linting $$dir"; \
$(MAKE) lint -C $$dir || exit 1; \
done

.PHONY: test
test: $(all)
for dir in $(all); do \
echo "Testing $$dir"; \
$(MAKE) test -C $$dir || exit 1; \
done

test-coverage: $(all)
for dir in $(all); do \
echo "Testing $$dir"; \
$(MAKE) test-coverage -C $$dir || exit 1; \
done

license-check: $(providers)
for dir in $(providers); do \
echo "Checking licenses for $$dir"; \
$(MAKE) license-check -C $$dir || exit 1; \
done

generate-sources: $(all)
for dir in $(all); do \
echo "Generating sources for $$dir"; \
$(MAKE) generate-sources -C $$dir || exit 1; \
done

tidy: $(all)
@go work sync
for dir in $(all); do \
echo "Tidying $$dir"; \
$(MAKE) tidy -C $$dir || exit 1; \
done

.PHONY: install-tools binaries sec check fmt lint test test-coverage license-check generate-sources tidy
16 changes: 8 additions & 8 deletions cloud/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ sec:
# 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
# More binaries can be distributed in future if required
.PHONY: runtimebin
runtimebin:
@echo Building AWS Runtime Server
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/runtime-aws -ldflags="-s -w -extldflags=-static" ./cmd/runtime

.PHONY: predeploybin
predeploybin: runtimebin
@cp bin/runtime-aws common/runtime/runtime-aws

Expand All @@ -32,7 +30,6 @@ deploybintf: generate-terraform predeploybin
@echo Building AWS Terraform Deployment Server
@CGO_ENABLED=0 go build -o bin/deploy-awstf -ldflags="-s -w -extldflags=-static" -ldflags="-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore" ./cmd/deploytf

.PHONY: install
install: deploybin deploybintf
@echo installing aws deployment server to ${HOME}/.nitric/providers/nitric/aws-0.0.1
@echo installing awstf deployment server to ${HOME}/.nitric/providers/nitric/awstf-0.0.1
Expand All @@ -49,9 +46,8 @@ install: deploybin deploybintf
cp bin/deploy-awstf "${HOME}/.nitric/providers/nitric/awstf-0.0.1"; \
fi


license-check: runtimebin
@echo Checking AWS Membrane OSS Licenses
@echo Checking AWS Runtime Server OSS Licenses
@go run github.com/uw-labs/lichen --config=./lichen.yaml ./bin/runtime-aws

sourcefiles := $(shell find . -type f -name "*.go" -o -name "*.dockerfile")
Expand All @@ -76,7 +72,6 @@ test-coverage: generate-mocks
@echo Running unit tests
@go run github.com/onsi/ginkgo/ginkgo -cover -outputdir=./ -coverprofile=all.coverprofile ./runtime/...


clean-mocks:
@rm -rf ./mocks

Expand All @@ -95,9 +90,14 @@ generate-mocks: clean-mocks
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/ifaces/secretsmanageriface SecretsManagerAPI > mocks/secrets_manager/mock.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/ifaces/s3iface S3API,PreSignAPI > mocks/s3/mock.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/ifaces/sqsiface SQSAPI > mocks/sqs/mock.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/runtime/resource AwsResourceProvider > mocks/provider/aws.go
@go run github.com/golang/mock/mockgen github.com/nitrictech/nitric/cloud/aws/runtime/resource AwsResourceResolver > mocks/provider/aws.go

generate-terraform:
@cd deploytf && npx -y [email protected] get

generate-sources: generate-mocks
generate-sources: generate-mocks

tidy:
@go mod tidy

.PHONY: binaries sec deploybin deploybintf install license-check fmt lint test test-coverage clean-mocks generate-mocks generate-terraform generate-sources tidy
6 changes: 3 additions & 3 deletions cloud/aws/cmd/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

### Requirements
- Git
- Nitric Membrane Project
- Nitric Project
- Golang
- Make
- Docker

### Getting Started

### Building Static Membrane Image
### Building Static Server Image
From the repository root run
```bash
make aws-docker-static
```

### Building Plugin Images

> __Note:__ Prior to building these plugins, the nitric pluggable membrane image must be built for local development
> __Note:__ Prior to building these plugins, the nitric pluggable server image must be built for local development

Alpine Linux
Expand Down
69 changes: 7 additions & 62 deletions cloud/aws/cmd/runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,23 @@
package main

import (
"os"
"os/signal"
"syscall"

"github.com/nitrictech/nitric/cloud/aws/runtime/api"
"github.com/nitrictech/nitric/cloud/aws/runtime/env"
lambda_service "github.com/nitrictech/nitric/cloud/aws/runtime/gateway"
dynamodb_service "github.com/nitrictech/nitric/cloud/aws/runtime/keyvalue"
sqs_service "github.com/nitrictech/nitric/cloud/aws/runtime/queue"
"github.com/nitrictech/nitric/cloud/aws/runtime"
"github.com/nitrictech/nitric/cloud/aws/runtime/resource"
secrets_manager_secret_service "github.com/nitrictech/nitric/cloud/aws/runtime/secret"
sql_service "github.com/nitrictech/nitric/cloud/aws/runtime/sql"
s3_service "github.com/nitrictech/nitric/cloud/aws/runtime/storage"
sns_service "github.com/nitrictech/nitric/cloud/aws/runtime/topic"
"github.com/nitrictech/nitric/cloud/aws/runtime/websocket"
base_http "github.com/nitrictech/nitric/cloud/common/runtime/gateway"
"github.com/nitrictech/nitric/core/pkg/logger"
"github.com/nitrictech/nitric/core/pkg/membrane"
"github.com/nitrictech/nitric/core/pkg/server"
)

func main() {
term := make(chan os.Signal, 1)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
signal.Notify(term, os.Interrupt, syscall.SIGINT)

logger.SetLogLevel(logger.INFO)

gatewayEnv := env.GATEWAY_ENVIRONMENT.String()

membraneOpts := membrane.DefaultMembraneOptions()

provider, err := resource.New()
resolver, err := resource.New()
if err != nil {
logger.Fatalf("could not create aws provider: %v", err)
logger.Fatalf("could not create aws resource resolver: %v", err)
return
}

// Load the appropriate gateway based on the environment.
switch gatewayEnv {
case "lambda":
membraneOpts.GatewayPlugin, _ = lambda_service.New(provider)
default:
membraneOpts.GatewayPlugin, _ = base_http.NewHttpGateway(nil)
}

membraneOpts.ApiPlugin = api.NewAwsApiGatewayProvider(provider)
membraneOpts.SecretManagerPlugin, _ = secrets_manager_secret_service.New(provider)
membraneOpts.KeyValuePlugin, _ = dynamodb_service.New(provider)
membraneOpts.TopicsPlugin, _ = sns_service.New(provider)
membraneOpts.StoragePlugin, _ = s3_service.New(provider)
membraneOpts.ResourcesPlugin = provider
membraneOpts.WebsocketPlugin, _ = websocket.NewAwsApiGatewayWebsocket(provider)
membraneOpts.QueuesPlugin, _ = sqs_service.New(provider)
membraneOpts.SqlPlugin = sql_service.NewRdsSqlService()

m, err := membrane.New(membraneOpts)
m, err := runtime.NewAwsRuntimeServer(resolver)
if err != nil {
logger.Fatalf("There was an error initializing the membrane server: %v", err)
}

errChan := make(chan error)
// Start the Membrane server
go func(chan error) {
errChan <- m.Start()
}(errChan)

select {
case membraneError := <-errChan:
logger.Errorf("Membrane Error: %v, exiting\n", membraneError)
case sigTerm := <-term:
logger.Infof("Received %v, exiting\n", sigTerm)
logger.Fatalf("there was an error initializing the AWS runtime server: %v", err)
}

m.Stop()
server.Run(m)
}
2 changes: 1 addition & 1 deletion cloud/aws/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (a *NitricAwsPulumiProvider) Service(ctx *pulumi.Context, parent pulumi.Res
// stackScopedNameKey := tags.GetResourceNameKey(a.stackId)

// Add resource list permissions
// Currently the membrane will use list operations
// Currently the nitric server will use list operations
tmpJSON, err = json.Marshal(map[string]interface{}{
"Version": "2012-10-17",
"Statement": []map[string]interface{}{
Expand Down
16 changes: 7 additions & 9 deletions cloud/aws/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ require (
github.com/pulumi/pulumi-awsx/sdk v1.0.6
github.com/pulumi/pulumi-docker/sdk/v4 v4.1.0
github.com/pulumi/pulumi-random/sdk/v4 v4.8.2
github.com/pulumi/pulumi/sdk/v3 v3.112.0
github.com/pulumi/pulumi/sdk/v3 v3.118.0
github.com/robfig/cron/v3 v3.0.1
github.com/samber/lo v1.38.1
github.com/uw-labs/lichen v0.1.7
github.com/valyala/fasthttp v1.45.0
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.36.4
go.opentelemetry.io/contrib/propagators/aws v1.11.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/sdk v1.22.0
google.golang.org/grpc v1.62.1
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
)

Expand All @@ -71,7 +70,7 @@ require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/alecthomas/go-check-sumtype v0.1.4 // indirect
Expand Down Expand Up @@ -135,7 +134,6 @@ require (
github.com/emirpasic/gods v1.18.1 // indirect
github.com/esimonov/ifshort v1.0.4 // indirect
github.com/ettle/strcase v0.2.0 // indirect
github.com/fasthttp/router v1.4.18 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/firefart/nonamedreturns v1.0.4 // indirect
Expand All @@ -145,7 +143,7 @@ require (
github.com/go-critic/go-critic v0.11.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
Expand Down Expand Up @@ -273,15 +271,14 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 // indirect
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
github.com/sashamelentyev/usestdlibvars v1.24.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/securego/gosec/v2 v2.18.2 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sivchari/containedctx v1.0.3 // indirect
github.com/sivchari/nosnakecase v1.7.0 // indirect
github.com/sivchari/tenv v1.7.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/sonatard/noctx v0.0.2 // indirect
github.com/sourcegraph/go-diff v0.7.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand Down Expand Up @@ -322,6 +319,7 @@ require (
go-simpler.org/musttag v0.8.0 // indirect
go-simpler.org/sloglint v0.4.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
Expand Down
Loading

0 comments on commit e90f709

Please sign in to comment.