Skip to content

Commit 6f97e78

Browse files
committed
Added vendor folder and suggested fixes
Signed-off-by: Rishabh Gupta<r.g.gupta@outlook.com>
1 parent 79be4af commit 6f97e78

File tree

22 files changed

+735
-54
lines changed

22 files changed

+735
-54
lines changed

cmd/tester/Dockerfile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
FROM golang:1.9.2 as builder
2-
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector
3-
WORKDIR /go/src/github.com/openfaas-incubator/connector
1+
FROM golang:1.10.4 as builder
2+
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector-sdk
3+
WORKDIR /go/src/github.com/openfaas-incubator/connector-sdk
44

5+
COPY vendor vendor
56
COPY main.go .
67

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

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

12-
FROM alpine
16+
FROM alpine:3.8
17+
18+
RUN addgroup -S app \
19+
&& adduser -S -g app app
20+
21+
WORKDIR /home/app
22+
23+
COPY --from=builder /go/src/github.com/openfaas-incubator/connector-sdk/ .
24+
25+
RUN chown -R app:app ./
1326

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

16-
CMD ["/bin/connector"]
29+
CMD ["./connector"]

cmd/tester/Dockerfile.armhf

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
FROM golang:1.9.2 as builder
2-
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector
3-
WORKDIR /go/src/github.com/openfaas-incubator/connector
1+
FROM golang:1.10.4 as builder
2+
RUN mkdir -p /go/src/github.com/openfaas-incubator/connector-sdk
3+
WORKDIR /go/src/github.com/openfaas-incubator/connector-sdk
44

5+
COPY vendor vendor
56
COPY main.go .
67

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

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

12-
FROM alpine
16+
FROM alpine:3.8
1317

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

16-
CMD ["/bin/connector"]
20+
CMD ["./connector"]

cmd/tester/Gopkg.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/Gopkg.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/openfaas-incubator/connector-sdk"
30+
version = "0.2.0"
31+
32+
[prune]
33+
go-tests = true
34+
unused-packages = true

cmd/tester/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Openfaas Sample Connector
1+
# OpenFaas Sample Connector
22

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

66
## How to Use
77

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

1313
To check if it actually works and triggers a function, deploy any function with annotation `topic=faas-request`.
1414
You can also run this command to deploy a sample function and see `trigger-func` invocation count growing in ui.

cmd/tester/main.go

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,44 @@
55
package main
66

77
import (
8-
"fmt"
9-
"log"
8+
"errors"
109
"os"
11-
"strings"
1210
"time"
1311

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

1715
func main() {
18-
creds := types.GetCredentials() // Get credentials for gateway login
19-
config := getControllerConfig()
16+
creds := types.GetCredentials()
17+
config, err := getControllerConfig()
18+
if err != nil {
19+
panic(err)
20+
}
2021

2122
controller := types.NewController(creds, config)
22-
fmt.Println(controller)
2323
controller.BeginMapBuilder()
2424

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

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

32-
for _, topic := range topics {
33-
controller.Invoke(topic, &data)
34-
}
33+
controller.Invoke(topic, &data)
3534
}
3635
}
3736

38-
func getControllerConfig() *types.ControllerConfig {
37+
func getControllerConfig() (*types.ControllerConfig, error) {
3938
gURL, ok := os.LookupEnv("gateway_url")
4039
if !ok {
41-
gURL = "http://127.0.0.1:8080/"
40+
return nil, errors.New("Gateway URL not set")
4241
}
43-
fmt.Println("Gateway Url: ", gURL)
4442

4543
return &types.ControllerConfig{
4644
RebuildInterval: time.Millisecond * 1000,
4745
GatewayURL: gURL,
4846
PrintResponse: true,
49-
}
50-
}
51-
52-
func getTopics() []string {
53-
topics := []string{}
54-
t, ok := os.LookupEnv("topics")
55-
if !ok {
56-
log.Print("No topics given in environment variable")
57-
}
58-
59-
topics = strings.Split(t, ",")
60-
return topics
47+
}, nil
6148
}

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/types/controller.go

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/types/credentials.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)