1

I am having some troubles to run a golang package on OpenWhisk (IBM Cloud Functions).

I ran the following on my local computer and it works without any problems (go run sample.go):

package main


import (
    "fmt"
    "encoding/json"
    "github.com/go-redis/redis"
)


func main() {

    var redisClient *redis.Client = redis.NewClient(&redis.Options{
        Addr: "...",
        Password: "...",
        DB: 0,
    })

    redisClient.Set("foo", "bar", 0)

    defer redisClient.Close()

    msg := map[string]string{"msg": ("Done !")}
    res, _ := json.Marshal(msg)
    fmt.Println(string(res))

}

But i didn't find any way to make it working on OpenWhisk. I ran the following:

GOOS=linux GOARCH=amd64 go build -o exec sample.go

zip exec.zip exec

bx wsk action update myfunction --native exec.zip

bx wsk action invoke myfunction -r
bx wsk activation logs --last --strip

"error": "The action did not return a dictionary."

"2018-02-21T01:21:05.962244788Z stdout: [Errno 2] No such file or directory: '/action/exec'"

The problem is related to the github.com/go-redis/redis package, when i remove it and its code then the function is running well. I met the same problem with the mgo package (MongoDB)...

I am new in Golang so it may be obvious, but for now i am stuck :/

Cinn
  • 4,281
  • 2
  • 20
  • 32
  • I just tried this and I didn't have any problems. It could be the activation record you are seeing is for an old run, do bx wsk activation list to be sure you see the latest run. Also try to build locally and run it on your computer to make sure the executable works, then re-compile for linux and deploy again and run it again $ GOARCH=amd64 go build -o exec sample.go ~/dev/whisk/demos/godemo $ ./exec {"msg":"Done !"} – csantanapr Feb 21 '18 at 05:56
  • I've also tried the instructions above and it runs without issue. Can you try @csantanapr's instructions above to check this works? What operating system are you using? Could you post your zip file somewhere for us to try? – James Thomas Feb 21 '18 at 10:31
  • Sorry for the delay in helping with this but I've now found the issue! See below. – James Thomas Mar 13 '18 at 16:02

2 Answers2

3

The binary in the zip file is dynamically linked against shared libraries not available on the platform.

Using file and ldd confirms this:

$ file exec 
exec: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not stripped 
$ ldd exec
/lib64/ld-linux-x86-64.so.2 (0x7f3f63f10000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f3f63f10000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f3f63f10000)

Build a static binary or build a dynamically linked binary inside the Docker image used by the platform (openwhisk/dockerskeleton).

The file not found error is misleading but reported by bash when executing files with this issue.

James Thomas
  • 4,303
  • 1
  • 20
  • 26
  • James what would be the command to build a static that includes everything? – csantanapr Mar 13 '18 at 17:15
  • 1
    It depends on the external libraries used. There isn't a single command for this AFAIK. This blog post goes into details https://medium.com/@diogok/on-golang-static-binaries-cross-compiling-and-plugins-1aed33499671 Compiling using the Docker runtime is the best option. – James Thomas Mar 14 '18 at 08:46
  • oh I I think I miss undertood. Yes 100% agree compile, zip, npm install all the things inside the docker runtime using `docker run --rm -v $(pwd):/owexec ....` – csantanapr Mar 15 '18 at 05:01
-1

"error": "The action did not return a dictionary."

This is an open wsk error message. It means that you did not return a dictionary on stdout

below is a valid return as it returns a json object

{"error":"something broke!"}

below would be invalid

"something broke!"

suggestions: check to see if there is any errors when you build ( normally ) the file in your dropbox doesnt look like a binary file...I suggest checking you can build the binary first

joe
  • 2,468
  • 2
  • 12
  • 19
jamie
  • 1