Skip to content

Commit

Permalink
chore: Additional fixes and cleaning up. Tested with aws-debian build.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Dec 21, 2020
1 parent ba079cb commit 6f63c70
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.git/
docker.sh
bin/
plugins/
*.dockerfile
*.dockerfile
lib/
10 changes: 3 additions & 7 deletions alpine.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
# Once the plugin SDK is visible for building

FROM golang:alpine as build
ARG NITRIC_GITHUB_TOKEN

RUN apk update
RUN apk upgrade

# RUN apk add --update go=1.8.3-r0 gcc=6.3.0-r4 g++=6.3.0-r4
RUN apk add --no-cache git gcc g++ make
RUN apk add --no-cache git curl gcc g++ make
# build-base autoconf automake libtool

WORKDIR /

# XXX: Setup private github repo access
RUN go env -w GOPRIVATE="github.com/nitric-dev"
RUN git config --global url.https://$NITRIC_GITHUB_TOKEN:[email protected]/.insteadOf https://github.com/

# Cache dependencies in seperate layer
COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN make build
RUN make membrane

FROM alpine

Expand Down
7 changes: 1 addition & 6 deletions debian.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
# Once the plugin SDK is visible for building

FROM golang:buster as build
ARG NITRIC_GITHUB_TOKEN

WORKDIR /

# XXX: Setup private github repo access
RUN go env -w GOPRIVATE="github.com/nitric-dev"
RUN git config --global url.https://$NITRIC_GITHUB_TOKEN:[email protected]/.insteadOf https://github.com/

# Cache dependencies in seperate layer
COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN make build
RUN make membrane

FROM debian:buster-slim

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/aws/aws-lambda-go v1.20.0
github.com/aws/aws-sdk-go v1.36.12
github.com/golang/protobuf v1.4.3
github.com/nitric-dev/membrane-plugin-sdk v0.0.0-20201203211256-c0260bb38f1d
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.1
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/nitric-dev/membrane-plugin-sdk v0.0.0-20201203020315-b1163dfd8dcf h1:E/MQFe8GOqDZ+2LFq11MZery0YnzikiL4Ig1rBcleU4=
github.com/nitric-dev/membrane-plugin-sdk v0.0.0-20201203211256-c0260bb38f1d h1:uv3gnLQSwZTmqXhNxNst+AaHzkdhRgpG5s7BWpVqGWk=
github.com/nitric-dev/membrane-plugin-sdk v0.0.0-20201203211256-c0260bb38f1d/go.mod h1:WsGYXGMYeoOgw4HOkM5a5DiI1U2s89ewcD7281ymNVs=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"log"
"strconv"

"github.com/nitric-dev/membrane-plugin-sdk/utils"
"nitric.io/membrane/membrane"
"github.com/nitric-dev/membrane/membrane"
"github.com/nitric-dev/membrane/utils"
)

func main() {
Expand Down
15 changes: 9 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
membrane: install generate-proto
membrane: install
@echo Building Go Project...
@CGO_ENABLED=1 GOOS=linux go build -o bin/membrane main.go

Expand All @@ -19,20 +19,23 @@ test: install-tools

generate-proto:
@echo Generating Proto Sources
@mkdir ./interfaces/
@mkdir -p ./interfaces/
@protoc --go_out=./interfaces/ --go-grpc_out=./interfaces/ -I ./contracts/proto/ ./contracts/proto/**/*.proto

aws-plugins:
@echo Building AWS plugins
@go build -buildmode=plugin -o lib/documents/dynamo-db.so ./plugins/aws/documents/dynamodb.go
@go build -buildmode=plugin -o lib/documents/dynamodb.so ./plugins/aws/documents/dynamodb.go
@go build -buildmode=plugin -o lib/eventing/sns.so ./plugins/aws/eventing/sns.go
@go build -buildmode=plugin -o lib/gateway/lambda.so ./plugins/aws/gateway/lambda.go
@go build -buildmode=plugin -o lib/storage/s3.so ./plugins/aws/storage/s3.go

aws-docker-debian:
@docker build . -f ./plugins/aws/debian.dockerfile -t nitric:membrane-debian-aws

build-docker-alpine:
@docker build . -f alpine.dockerfile -t nitric:membrane-alpine --build-arg NITRIC_GITHUB_TOKEN=${NITRIC_GITHUB_TOKEN}
@docker build . -f alpine.dockerfile -t nitric:membrane-alpine
build-docker-debian:
@docker build . -f debian.dockerfile -t nitric:membrane-debian --build-arg NITRIC_GITHUB_TOKEN=${NITRIC_GITHUB_TOKEN}
@docker build . -f debian.dockerfile -t nitric:membrane-debian

build-docker: build-docker-alpine build-docker-debian
membrane-docker: generate-proto build-docker-alpine build-docker-debian
@echo Built Docker Images
4 changes: 2 additions & 2 deletions membrane/membrane.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func (s *Membrane) createDocumentsServer() (documentsPb.DocumentsServer, error)

// Cast to the new documents server function
if newPluginFunc, ok := newDocumentsPlugin.(func() (sdk.DocumentsPlugin, error)); ok {
if documentsPlugin, err = newPluginFunc(); err == nil {
return services.NewDocumentsServer(documentsPlugin)
if docsPlugin, err := newPluginFunc(); err == nil {
return services.NewDocumentsServer(docsPlugin), nil
} else {
return nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions plugins/aws/debian.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# FIXME: Build with docker context in future
# Once the plugin SDK is visible for building
FROM golang:buster as build

WORKDIR /

# Cache dependencies in seperate layer
COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN make aws-plugins

# Default dockerfile for the Nitric AWS base image
FROM nitric:membrane-debian

# FIXME: Build these in a build stage during the docker build
# for now will just be copied post local build
# and execute these stages through a local shell script
COPY --from=build ./lib/documents/dynamodb.so /plugins/documents.so
COPY --from=build ./lib/eventing/sns.so /plugins/eventing.so
COPY --from=build ./lib/storage/s3.so /plugins/storage.so
COPY --from=build ./lib/gateway/lambda.so /plugins/gateway.so

RUN chmod +rx /plugins/*

# FIXME: Do we need this here?
ENTRYPOINT [ "/membrane" ]
2 changes: 1 addition & 1 deletion plugins/aws/gateway/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
events "github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"nitric.io/membrane/plugins/sdk"
"github.com/nitric-dev/membrane/plugins/sdk"
)

type eventType int
Expand Down
2 changes: 1 addition & 1 deletion plugins/aws/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func New() (sdk.StoragePlugin, error) {

s3Client := s3.New(sess)

return &S3Server{
return &S3Plugin{
client: s3Client,
}, nil
}
4 changes: 2 additions & 2 deletions plugins/sdk/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ type UnimplementedStoragePlugin struct {
StoragePlugin
}

func(*UnimplementedStoragePlugin) Get(bucket string, key string) []byte, error {
func (*UnimplementedStoragePlugin) Get(bucket string, key string) ([]byte, error) {
return nil, fmt.Errorf("UNIMPLEMENTED")
}

func(*UnimplementedStoragePlugin) Put(bucket string, key string, object []byte) error {
func (*UnimplementedStoragePlugin) Put(bucket string, key string, object []byte) error {
return fmt.Errorf("UNIMPLEMENTED")
}
2 changes: 1 addition & 1 deletion services/eventing_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *EventingServer) GetTopics(context.Context, *empty.Empty) (*pb.GetTopics
}
}

func NewEventingServer(eventingPlugin sdk.EventingPlugin) {
func NewEventingServer(eventingPlugin sdk.EventingPlugin) pb.EventingServer {
return &EventingServer{
eventingPlugin: eventingPlugin,
}
Expand Down
10 changes: 5 additions & 5 deletions services/storage_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type StorageServer struct {
}

func (s *StorageServer) checkPluginRegistered() (bool, error) {
if s.eventingPlugin == nil {
if s.storagePlugin == nil {
return false, status.Errorf(codes.Unimplemented, "Eventing plugin not registered")
}

Expand All @@ -28,7 +28,7 @@ func (s *StorageServer) Put(ctx context.Context, req *pb.PutRequest) (*pb.PutRep
if err := s.storagePlugin.Put(req.GetBucketName(), req.GetKey(), req.GetBody()); err == nil {
return &pb.PutReply{
Success: true,
}
}, nil
} else {
return nil, err
}
Expand All @@ -37,12 +37,12 @@ func (s *StorageServer) Put(ctx context.Context, req *pb.PutRequest) (*pb.PutRep
}
}

func (s *StorageServer) Get(context.Context, *pb.GetRequest) (*pb.GetReply, error) {
func (s *StorageServer) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetReply, error) {
if ok, err := s.checkPluginRegistered(); ok {
if object, err := s.storagePlugin.Get(req.GetBucketName(), req.GetKey()); err == nil {
return &pb.GetReply{
Body: object,
}
}, nil
} else {
return nil, err
}
Expand All @@ -51,7 +51,7 @@ func (s *StorageServer) Get(context.Context, *pb.GetRequest) (*pb.GetReply, erro
}
}

func NewStorageServer(storagePlugin sdk.StoragePlugin) {
func NewStorageServer(storagePlugin sdk.StoragePlugin) pb.StorageServer {
return &StorageServer{
storagePlugin: storagePlugin,
}
Expand Down

0 comments on commit 6f63c70

Please sign in to comment.