-
Notifications
You must be signed in to change notification settings - Fork 58
Closed
Labels
help wantedExtra attention is neededExtra attention is needed
Description
faas-cli build ...
fails to build the image when the function contains external libraries vendored with dep
.
Steps to reproduce:
faas template pull https://github.com/openfaas-incubator/golang-http-template
faas-cli new --lang golang-http test-fn
cd test-fn
# now create a sample function (handler.go) using an external library, example below
# make sure when you save that the openfaas-incubator... import is not removed, e.g. due to go imports formating
dep init # assumption here is that dep should be run from within the handler folder (?)
tree -L 2 vendor
vendor
└── github.com
├── openfaas-incubator
└── pkg
# dep correctly did its job
cd ..
faas-cli build -f test-fn.yml
Then it fails at Dockerfile step 7:
Step 7/17 : RUN CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && go test $(go list ./... | grep -v /vendor/) -cover
---> Running in eb8face14c7b
# handler
./main.go:37:39: cannot use req (type "handler/vendor/github.com/openfaas-incubator/go-function-sdk".Request) as type "handler/function/vendor/github.com/openfaas-incubator/go-function-sdk".Request in argument to function.Handle
The command '/bin/sh -c CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && go test $(go list ./... | grep -v /vendor/) -cover' returned a non-zero code: 2
2019/01/17 22:23:33 ERROR - Could not execute command: [docker build -t test-fn:latest .]
Took me a while to figure out how to work around that. Before faas-cli build
remove the folder openfaas-incubator
in the handler.go vendor
folder. Then build works fine (as it will pull in the dependency from the template).
Example function:
package function
import (
"fmt"
"net/http"
"github.com/openfaas-incubator/go-function-sdk"
"github.com/pkg/errors"
)
// Handle a function invocation
func Handle(req handler.Request) (handler.Response, error) {
var err error
err = errors.Wrap(err, "hit a bug")
message := fmt.Sprintf("Hello world, input was: %s", string(req.Body))
return handler.Response{
Body: []byte(message),
StatusCode: http.StatusOK,
}, err
}
cc/ @alexellis
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed