Skip to content

Commit

Permalink
Added vendor folder and suggested fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Gupta<[email protected]>
  • Loading branch information
zeerorg committed Jan 15, 2019
1 parent 79be4af commit 6f97e78
Show file tree
Hide file tree
Showing 22 changed files with 735 additions and 54 deletions.
27 changes: 20 additions & 7 deletions cmd/tester/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
FROM golang:1.9.2 as builder
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector
WORKDIR /go/src/github.com/openfaas-incubator/connector
FROM golang:1.10.4 as builder
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector-sdk
WORKDIR /go/src/github.com/openfaas-incubator/connector-sdk

COPY vendor vendor
COPY main.go .

RUN go get -d -v ./...
# Run a gofmt and exclude all vendored code.
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))"

RUN go test -v ./...

# Stripping via -ldflags "-s -w"
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o ./connector

FROM alpine
FROM alpine:3.8

RUN addgroup -S app \
&& adduser -S -g app app

WORKDIR /home/app

COPY --from=builder /go/src/github.com/openfaas-incubator/connector-sdk/ .

RUN chown -R app:app ./

COPY --from=builder /go/src/github.com/openfaas-incubator/connector/connector /bin/connector
USER app

CMD ["/bin/connector"]
CMD ["./connector"]
20 changes: 12 additions & 8 deletions cmd/tester/Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM golang:1.9.2 as builder
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector
WORKDIR /go/src/github.com/openfaas-incubator/connector
FROM golang:1.10.4 as builder
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector-sdk
WORKDIR /go/src/github.com/openfaas-incubator/connector-sdk

COPY vendor vendor
COPY main.go .

RUN go get -d -v ./...
# Run a gofmt and exclude all vendored code.
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))"

RUN go test -v ./...

# Stripping via -ldflags "-s -w"
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o ./connector
RUN GOARM=7 CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o ./connector

FROM alpine
FROM alpine:3.8

COPY --from=builder /go/src/github.com/openfaas-incubator/connector/connector /bin/connector
COPY --from=builder /go/src/github.com/openfaas-incubator/connector-sdk/ .

CMD ["/bin/connector"]
CMD ["./connector"]
33 changes: 33 additions & 0 deletions cmd/tester/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions cmd/tester/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/openfaas-incubator/connector-sdk"
version = "0.2.0"

[prune]
go-tests = true
unused-packages = true
8 changes: 4 additions & 4 deletions cmd/tester/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Openfaas Sample Connector
# OpenFaas Sample Connector

This folder contains a sample openfaas connector. You can use this as a base for creating your own connectors.
This folder contains a sample OpenFaas connector. You can use this as a base for creating your own connectors.
For a more complex example checkout [kafka-connector](https://github.com/openfaas-incubator/kafka-connector)

## How to Use

1. Clone this repository: `git clone https://github.com/openfaas-incubator/connector-sdk.git`
2. Go into the directory: `cd ./connector-sdk/cmd/tester/yaml`
3. For openfaas deployed on docker swarm do: `docker stack deploy func -c ./docker-compose.yml`
4. For openfaas deployed on kubernetes do: `kubectl create -f ./kubernetes --namespace openfaas`
3. For OpenFaas deployed on Docker Swarm do: `docker stack deploy func -c ./docker-compose.yml`
4. For OpenFaas deployed on kubernetes do: `kubectl create -f ./kubernetes --namespace openfaas`

To check if it actually works and triggers a function, deploy any function with annotation `topic=faas-request`.
You can also run this command to deploy a sample function and see `trigger-func` invocation count growing in ui.
Expand Down
39 changes: 13 additions & 26 deletions cmd/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,44 @@
package main

import (
"fmt"
"log"
"errors"
"os"
"strings"
"time"

"github.com/openfaas-incubator/connector-sdk/types"
)

func main() {
creds := types.GetCredentials() // Get credentials for gateway login
config := getControllerConfig()
creds := types.GetCredentials()
config, err := getControllerConfig()
if err != nil {
panic(err)
}

controller := types.NewController(creds, config)
fmt.Println(controller)
controller.BeginMapBuilder()

topics := getTopics()
topic := "faas-request"
invokeTime := time.Second * 2

// Simulate events emitting from queue/pub-sub
for {
time.Sleep(2 * time.Second)
time.Sleep(invokeTime)
data := []byte("test " + time.Now().String())

for _, topic := range topics {
controller.Invoke(topic, &data)
}
controller.Invoke(topic, &data)
}
}

func getControllerConfig() *types.ControllerConfig {
func getControllerConfig() (*types.ControllerConfig, error) {
gURL, ok := os.LookupEnv("gateway_url")
if !ok {
gURL = "http://127.0.0.1:8080/"
return nil, errors.New("Gateway URL not set")
}
fmt.Println("Gateway Url: ", gURL)

return &types.ControllerConfig{
RebuildInterval: time.Millisecond * 1000,
GatewayURL: gURL,
PrintResponse: true,
}
}

func getTopics() []string {
topics := []string{}
t, ok := os.LookupEnv("topics")
if !ok {
log.Print("No topics given in environment variable")
}

topics = strings.Split(t, ",")
return topics
}, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6f97e78

Please sign in to comment.