Asset not found

After spending DAYS trying to get a 25 line ruby asset to work to no avail, I rewrote the damn thing in go.

My go binary works standalone, I’m not sure it’s going to pass the whole bonsai build process at this point because I had to make some mods to the upstream plivo-go package that it uses, so for now it just builds locally. I packaged it up as an “asset” and uploaded it to my github.

type: Asset
api_version: core/v2
metadata:
  name: sensu-go-plivo-handler
  namespace: default
  annotations:
    project_url: https://github.com/bmcgair/sensu-go-plivo-handler
    version: 0.0.1
spec:
  url: https://github.com/bmcgair/sensu-go-plivo-handler/releases/download/0.0.1/sensu-go-plivo-handler-0.0.1.tar.gz
  sha512: a7074d667a93b53fc30dafb1c68db2fa682c5a761f6ac2b65daef8c0b92a716969f7855c5cb50fa3a7ed8f793b732dc41ba9a1a6a784b4afc2efc618658c5502

When I try to use it all I see is:

{"assets":["sensu-go-plivo-handler"],"component":"pipelined","handler":"plivo","level":"info","msg":"event pipe handler executed","namespace":"default","output":"sh: sensu-go-plivo-handler: not found\n","status":127,"time":"2020-01-26T18:15:45Z"}
**strong text**

If I look on the container img itself it appears that my asset mounts, but my binary (which works elsewhere) just does this:

/var/cache/sensu/sensu-backend/a7074d667a93b53fc30dafb1c68db2fa682c5a761f6ac2b65daef8c0b92a716969f7855c5cb50fa3a7ed8f793b732dc41ba9a1a6a784b4afc2efc618658c5502/bin # pwd; ls -al
/var/cache/sensu/sensu-backend/a7074d667a93b53fc30dafb1c68db2fa682c5a761f6ac2b65daef8c0b92a716969f7855c5cb50fa3a7ed8f793b732dc41ba9a1a6a784b4afc2efc618658c5502/bin
total 24628
drwxr-xr-x    2 root     root          4096 Jan 26 18:14 .
drwxr-xr-x    4 root     root          4096 Jan 26 18:14 ..
-rwxrwxr-x    1 root     root      25209503 Jan 26 18:14 sensu-go-plivo-handler
/var/cache/sensu/sensu-backend/a7074d667a93b53fc30dafb1c68db2fa682c5a761f6ac2b65daef8c0b92a716969f7855c5cb50fa3a7ed8f793b732dc41ba9a1a6a784b4afc2efc618658c5502/bin # ./sensu-go-plivo-handler 
sh: ./sensu-go-plivo-handler: not found

The reason it’s not working in the container is that it’s a dynamically linked binary, but the needed libraries are not in the container image. I get the following trying to run your binary in alpine:latest.

# ./sensu-go-plivo-handler
/bin/ash: ./sensu-go-plivo-handler: not found

# file sensu-go-plivo-handler
sensu-go-plivo-handler: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=2EYWP2Yp1IVnj7acQhSg/qZuFJQSae2lRJ_jrFSFM/qB05EwUUpc7YG1wKN52e/2sws8dbvlEpFwKxNwOXn, not stripped

# ldd sensu-go-plivo-handler
	/lib64/ld-linux-x86-64.so.2 (0x7fb9cd8eb000)
	libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fb9cd8eb000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fb9cd8eb000)
Error relocating sensu-go-plivo-handler: __vfprintf_chk: symbol not found
Error relocating sensu-go-plivo-handler: __fprintf_chk: symbol not found

Also, it appears your asset contains the entire contents of your git repository. An asset should only require your bin directory (at least in the case of statically linked binaries).

@todd thanks.

go build -o bin/sensu-go-plivo-handler -ldflags "-linkmode external -extldflags -static" -a main.go

did the trick.

2 Likes