Hi everyone,
I hope someone around here has dealt with a similar issue:
I am trying to run a pre-compiled Go binary on a scratch image on a RPi3, without success.
The container is stuck as “installed”
I have a simple hello world application in Go:
package main
import (
"fmt"
)
func main(){
fmt.Println("Hello world!")
}
This is pre-compiled with the following command for cross-compilation.
I have tried to use all available tricks to make the binary static, in case that was the problem, which shouldnt because of few dependancies.
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -a --installsuffix cgo -v -tags netgo -ldflags '-extldflags "-static"' .
This yields the following verbosity for the installed packages:
runtime/internal/sys
errors
math/bits
internal/cpu
unicode/utf8
runtime/internal/math
internal/bytealg
math
runtime/internal/atomic
internal/race
sync/atomic
unicode
runtime
internal/testlog
strconv
sync
io
reflect
syscall
internal/syscall/unix
time
sort
internal/poll
internal/fmtsort
os
fmt
Test
I copied the binary to the required location and then I apply the following Dockerfile
FROM resin/scratch
COPY ./app/Test /Test
CMD ["/Test"]
Of course, the structure of the directory is:
mytest/dockerfile
mytest/app/Test
Upon running, we see the holy Unicorn of success:
Unfortunaly, the container doesnt pass the installed states.
As well, I tried to read the logs of the host but I am not able to make sense out of that.
On the other hand, if I introduce an Alpine run image, it does work!
FROM balenalib/raspberrypi3-alpine:latest-run
COPY ./app/Test /Test
CMD ["bash","/usr/src/app/start.sh"]
And start.sh as
#!/bin/bash
chmod +x Test
./Test
Also, alternatively, I am able to run a nats server in the following way:
FROM balenalib/%%BALENA_MACHINE_NAME%%-golang:latest-build AS build
# get package without install -d
RUN go get -d github.com/nats-io/nats-server
WORKDIR /go/src/github.com/nats-io/nats-server
# build nats-server
RUN CGO_ENABLED=0 go build -a -tags netgo -ldflags="-w -s"
# second pass. only build the container with the go bin file
FROM resin/scratch
COPY --from=build /go/src/github.com/nats-io/nats-server/nats-server /nats-server
CMD ["/nats-server", "-p","4222", "-m","8222"]
On the internet most people would run go get from some github repository. That actually works. However, what I wanted to have is the entire project locally compiled, but I cannot understand why it doesnt work.
Anyone?