Fork me on GitHub
#babashka
<
2020-02-23
>
martinklepsch01:02:43

Is babashka expected to work on alpine linux? I just tried and ran into some weird issues

/ # which bb
/usr/local/bin/bb
/ # bb
/bin/sh: bb: not found

Cora (she/her)01:02:10

if you use the whole path does it work?

Crispin03:02:03

open a fresh shell and try again just to confirm. I've seen this issue before with other bins where the which is called, then the file is deleted, then the which is called again in the same shell, and it reports the path as there when it is not. Maybe some kind of cache.

Crispin03:02:29

secondly check the /usr/local/bin/bb location yourself. Is it a symlink? or an actual bin.

Cora (she/her)04:02:06

also run hash -r on bash your clear the binary path cache thingy

Cora (she/her)04:02:31

which might be finding it on your path but you have an old path cached in the shell

borkdude08:02:01

@martinklepsch I don’t think it works on Alpine. See an issue about the Docker image

borkdude08:02:08

Maybe it could be made to work if we compiled it with the —static option on Linux. I haven’t tried

borkdude08:02:46

Maybe worth a try

borkdude08:02:47

It requires libstdc++ which isn’t available on Alpine

borkdude10:02:34

@martinklepsch That did appear to work:

apk add curl
curl -sL  -o bb.zip
unzip bb.zip
./bb '(+ 1 2 3)'
6

borkdude10:02:21

Lemme make a release with a static build for linux

borkdude11:02:44

Nice, it seems static linking makes the startup of bb even faster:

[email protected]:/# time ./bb '(+ 1 2 3)'
6

real	0m0.006s
user	0m0.002s
sys	0m0.004s

littleli11:02:36

yeah, no symbol linking at runtime 👍

littleli11:02:49

but size of the binary suffers, isn't it?

borkdude11:02:52

it's now 43821000 for linux. let me check the previous size weirdly enough, it was 44339568 before on linux. whereas on MacOS it's smaller.

borkdude11:02:47

I guess adding 1 or 2 mbs to make it work on constrained enviroments like Alpine is worth it, but since it's even smaller and faster now, there is no disadvantage at all?

borkdude11:02:14

note: the --static option is only used for linux, not for other platforms

littleli11:02:15

probably none 🙂

borkdude11:02:31

it is not supported by GraalVM for other platforms than linux

littleli11:02:26

static linking on Win and Mac is rare, but they don't use alternative standard libraries usually, like Alpine does.

borkdude11:02:35

maybe I'll also now move the bb Docker image to alpine

littleli11:02:35

scoop updated

borkdude11:02:11

hmm, trying to move the Docker image to alpine:

/ # /usr/local/bin/bb --version
Segmentation fault
🤷

borkdude11:02:34

if anyone wants to try it, I pushed the Dockerfile to the alpine-docker branch.

littleli12:02:28

I'm unable to build the image, this is what happen during docker build:

Compiling babashka.impl.clojure.core.server
Syntax error macroexpanding at (server.clj:12:1).
Execution error (FileNotFoundException) at babashka.impl.clojure.core.server/loading (server.clj:12).
Could not locate sci/core__init.class, sci/core.clj or sci/core.cljc on classpath.

borkdude12:02:03

@ales.najmann You need to git clone/pull the repo --recursive

borkdude12:02:10

because it has a submodule

littleli13:02:14

I'm still not successful, I endup here:

[bb:148]    classlist:  13,095.04 ms
[bb:148]        (cap):   1,584.37 ms
[bb:148]        setup:   3,906.97 ms
[Use -Dgraal.LogFile=<path> to redirect Graal log output to a file.]
[thread:18] scope: ForkJoinPool-4-worker-1
  [thread:18] scope: ForkJoinPool-4-worker-1.registerResource
  ServiceLoaderFeature: registerResource: META-INF/services/com.fasterxml.jackson.core.JsonFactory
  [thread:18] scope: ForkJoinPool-4-worker-1.registerResource
  ServiceLoaderFeature: registerResource: META-INF/services/java.nio.file.spi.FileSystemProvider
  [thread:18] scope: ForkJoinPool-4-worker-1.registerResource
  Resources have been added by ServiceLoaderFeature. Automatic registration can be disabled with -H:-UseServiceLoaderFeature
  [thread:18] scope: ForkJoinPool-4-worker-1.registerResource
  ResourcesFeature: registerResource: SCI_VERSION
  [thread:18] scope: ForkJoinPool-4-worker-1.registerResource
  ResourcesFeature: registerResource: BABASHKA_VERSION
Error: Image build request failed with exit status 137
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 137
	at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1482)
	at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1260)
	at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1222)
	at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1181)
The command '/bin/sh -c ./script/compile' returned a non-zero code: 1
have you seen anything like this before?

borkdude13:02:29

yeah, that's an out of memory I think

borkdude13:02:42

you may need to up Docker's memory if you're not building on linux

borkdude13:02:11

like 4gb should do it (same as on CircleCI)

littleli13:02:00

okay, that makes sense. I would rather see meaningful error message from native image 🙂 but it's what it is.

borkdude13:02:56

don't know really, but I just looked up 137 😉

littleli13:02:17

I see. Native-image didn't have a chance, killed in action. RIP 😄

martinklepsch17:02:39

it would be really nice if bb had a built in http client, using stuff via deps is ok but it’s definitely less portable than just having it built in

martinklepsch17:02:00

@borkdude thanks for the alpine pointers, I’ll give that another try

borkdude17:02:25

@martinklepsch including an http client is certainly the plan - I am currently considering on including a JDK11-based http client (hato), but we'll have to wait for at least GraalVM 20.1 for this

borkdude17:02:53

using (clojure.java.shell/sh "curl" ...) or even slurp is also an option

martinklepsch17:02:58

sweet, i’ve started using hato for it’s support of PATCH requests, wich surprisingly is missing from clj-http-lite it seems

borkdude17:02:52

I haven't tested hato with graalvm yet btw, so there's still some research to be done

borkdude17:02:44

if hato doesn't work out at all I might go for clj-http-lite which definitely works

borkdude17:02:06

@martinklepsch btw, there is also the --uberscript option to morph all your dependencies + script into one file

martinklepsch17:02:49

oh interesting

jjttjj21:02:30

On windows, in powershell, with babashka installed via scoop, I'm getting the following when I try to use regexes:

ls | bb -i '(re-find #"hi" *input*)'
clojure.lang.ExceptionInfo: [line 1, col 21] No reader function for tag hi.
Is there something I'm missing?

borkdude21:02:05

it might be something with Windows shell quoting. can you try this from a foo.clj file?

borkdude21:02:01

the examples in the readme are based on bash, not tested with powershell

borkdude21:02:18

there might be subtle differences between how powershell handles quoting

jjttjj21:02:22

gotcha yeah it definitely seems to have to do with quoting you're right, having other issues with the clj file, but think I just need to play around a bit more, (or just use bash)

borkdude21:02:55

@jjttjj what issues are you having with the .clj file?

jjttjj21:02:26

ls | bb -f tst.clj                                                                        
clojure.lang.ExceptionInfo: java.lang.RuntimeException: Invalid token: Directory: [at C:\Users\justin\Downloads\tst.clj, line 1, column 1]

borkdude21:02:29

oh, I see. can you try ls | bb -i -f tst.clj?

jjttjj21:02:22

clojure.lang.ExceptionInfo: clojure.lang.Cons cannot be cast to java.lang.CharSequence [at C:\Users\justin\Downloads\tst.clj, line 1, column 1]

borkdude21:02:59

what does ls produce on your system?

jjttjj21:02:00

what usually looks like a detailed ls output in linux i believe (file mode,last write, length, name)

borkdude21:02:21

ls on linux or mac only produces the filenames if you don't provide any other options

jjttjj21:02:47

ok actually yeah I think I got it now

jjttjj21:02:59

*input* is a sequence

borkdude21:02:01

you can also just do (line-seq (io/reader *in*)) instead of *input*, that makes it more explicit

jjttjj21:02:18

ok perfect, thanks! Got it working now

borkdude21:02:49

@martinklepsch Note: I reverted the linux build for bb to a dynamically linked one and will provide a separate statically linked one that you can use in Alpine. See https://github.com/borkdude/babashka/#download

borkdude21:02:49

I was experiencing some weirdness when building the static image on Ubuntu, this cannot be run on Alpine, but if you start from Debian you can. I was further informed by @rahul080327 that static linking can lead to unforeseen trouble, this is why I reverted it and will now provide it separately.