babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-04-14T12:49:45.146300Z

I’m looking for an example of setting up babashka (including paths and such) on CircleCI. Anyone have such an example?

borkdude 2021-04-14T12:50:40.146800Z

@jeroenvandijk I think you should just be able to do this:

bash &lt; &lt;(curl -s <https://raw.githubusercontent.com/babashka/babashka/master/install>)
you might need sudo

2021-04-14T12:52:27.148300Z

I’ll give it a try! Thanks. I found this example as well https://github.com/babashka/pod-babashka-aws/blob/main/.circleci/config.yml#L93 But I figured there might be a more complete one where babashka is used for all scripts

borkdude 2021-04-14T12:53:30.149300Z

@jeroenvandijk you can use bb.edn :paths. rewrite-clj is using this extensively now (look at all those bb scrips in the script dir) https://github.com/clj-commons/rewrite-clj

borkdude 2021-04-14T12:55:00.151Z

he managed to pull off 100% Clojure in that repo ;) (kudos @lee)

❤️ 1
🙌 2
2021-04-14T12:55:05.151200Z

ah yeah. That’s a very complete example 🙂

Jakub Holý 2021-04-14T12:57:15.153400Z

Hi! I struggle with combining -m with a custom script. I have ~/Library/me/bin/mb-callls.bb that starts with (ns mb-calls ...) and invoke bb --classpath ~/Library/me/bin -m mb-calls/testit "hi" but it fails with > Message: Could not find namespace: mb-calls. (ideally, I would be able to run bb -f ~/Library/me/bin/mb-calls.bb -m mb-calls/testit "hi" IMHO) What do I do wrong? (I do not use bb.edn) Thank you!

borkdude 2021-04-14T12:58:43.153700Z

you should probably use an underscore in the file structure

✅ 1
borkdude 2021-04-14T12:59:37.154100Z

~/Library/me/bin/mb_callls.bb

borkdude 2021-04-14T12:59:47.154300Z

also probably use one less l

borkdude 2021-04-14T13:00:02.154500Z

~/Library/me/bin/mb_calls.bb

Jakub Holý 2021-04-14T13:06:06.154800Z

Thanks, it works!

2021-04-14T13:13:53.154900Z

Had to use sudo indeed

2021-04-14T13:14:21.155100Z

@borkdude minimal example of .circleci/config.yml:

version: 2
jobs:
  build:
    docker:
      - image: circleci/clojure:lein-2.7.1

    working_directory: ~/repo

    steps:
      - run:
          name: Install bb
          command: |
            sudo bash &lt; &lt;(curl -sL <https://raw.githubusercontent.com/borkdude/babashka/master/install>)
              
      - run:
          name: Test bb
          command: |
            bb version

2021-04-14T13:14:48.155300Z

Thanks!

👍 1
wilkerlucio 2021-04-14T14:56:35.156800Z

with babashka tasks, I’m often feeling the need to use bash things (like VAR=SOMETHING command ... or do-soething &gt; save-here.file), and given the shell doesn’t have those, I wonder about having another helper to handle these common cases, maybe: (bash "NOW_VARS=likeThis will-work")

wilkerlucio 2021-04-14T14:57:12.156900Z

the env var need is more common than the others, so there is also the option to maybe provide :env to shell in some way

borkdude 2021-04-14T14:58:06.157100Z

@wilkerlucio This is already supported :)

(shell {:out "the-file.txt" :extra-env {"NOW_VARS" "likeThis"}} "dude")

🆒 2
wilkerlucio 2021-04-14T14:58:33.157300Z

oh, awesome! I wasn’t aware 🙂

borkdude 2021-04-14T14:58:43.157500Z

probably needs documenting

borkdude 2021-04-14T14:58:58.157700Z

it takes the same options as babashka.process, but as the first arg

wilkerlucio 2021-04-14T14:59:50.157900Z

thats nice, glad to learn this, gonna use often 🙂

borkdude 2021-04-14T15:00:12.158100Z

:env is also supported, this replaces all the env vars

🆒 1
pez 2021-04-14T16:08:02.158900Z

Is it possible to use babashka with AWS lambdas?

borkdude 2021-04-14T16:08:45.159400Z

@pez sure! @lukaszkorecki can tell you more maybe. there is also this blog: https://www.jocas.lt/blog/post/babashka-aws-lambda/

pez 2021-04-14T16:12:33.160200Z

That’s awesome.

lukasz 2021-04-14T16:15:23.161500Z

@pez I built a POC for Lambda+Docker, as IMHO it's easier to deal with than custom layers and stuff (and you can use your code outside of lambda too if you need to): https://gist.github.com/lukaszkorecki/a1fe27bf08f9b98e9def9da4bcb3264e We're migrating one of our Clojure services (no BB, yet!) into Lambda, and that's the approach we're taking

👍 1
lukasz 2021-04-15T13:45:28.208100Z

Oh totally, I think I have more structured code laying around somewhere, but you know how it works - lack of time etc etc etc

viesti 2021-04-15T18:58:07.215Z

here's also one implementation https://github.com/dainiusjocas/babashka-lambda-layer/tree/master/src/lambda

lukasz 2021-04-15T20:16:22.215200Z

yep, that will work out of the box

pez 2021-04-14T17:07:54.162500Z

Thanks. Will check out.

2021-04-14T19:25:58.169200Z

I thought I had seen some discussions about how inspect a jar from Babashka. Google mentions something from the slack archive, but I can’t seem to open the page. Any other suggestions?

borkdude 2021-04-14T19:28:40.169600Z

@jeroenvandijk Here is an example: https://github.com/babashka/babashka/blob/master/examples/ls_jar.clj

2021-04-14T19:28:56.170Z

Ah perfect thanks 🙂

2021-04-14T19:29:19.170300Z

I forgot to look there 😅

borkdude 2021-04-14T19:29:29.170500Z

No worries :)

Tomas Brejla 2021-04-14T20:09:20.171100Z

I understand that bb's startup time is pretty low, but shouldn't you actually have some sort of event-handling-loop inside that lambda's code? I'd expect something similar to https://github.com/andthearchitect/aws-lambda-java-runtime/blob/master/src/main/java/com/ata/aws/lambda/LambdaBootstrap.java#L58-L77

Tomas Brejla 2021-04-14T20:11:35.171500Z

even the documentation in https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html states: > Your runtime code is responsible for completing some initialization tasks. Then it processes invocation events in a loop until it's terminated. The initialization tasks run once https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html to prepare the environment to handle invocations.

lukasz 2021-04-14T21:09:51.171700Z

I see - we didn't get as far as deploying to the actual lambda environment (due to other blockers on our end) - but it def worked in the simulator. That said, you can add the while true loop here: https://gist.github.com/lukaszkorecki/a1fe27bf08f9b98e9def9da4bcb3264e#file-core-clj-L57-L63 and it will work just like the Java example (I think, caveat emptor)

lukasz 2021-04-14T21:10:54.171900Z

For the JVM Clojure we're just using the SDK + deploying an uberjar with Terraform - startup time in our use case is not relevant

borkdude 2021-04-14T21:33:30.174Z

The next version of bb will add support for the https://github.com/helins/binf.cljc library (by adding relevant Java classes): read and write binary formats with ease. This could be useful if you e.g. want to write a parsing library for midi, or WASM, or whatever other binary format. This library will then also work with bb (according to @adam678): https://github.com/helins/wasm.cljc

🙌 3
Helins 2021-04-15T11:55:00.207500Z

Indeed, here is a very short but fully working example of decompiling a WASM program into Clojure data and pretty printing it: https://gist.github.com/helins/eacfc7d8b92b97693a93dd46e8a89677

2021-04-15T13:46:19.208300Z

Speaking about wasm, did someone try this? https://github.com/i-net-software/JWebAssembly ? Useful to have a sandbox for Sci projects? :thinking_face:

borkdude 2021-04-15T14:06:32.208800Z

btw @jeroenvandijk I couldn't find our old discussion, but bb 0.3.5 now has the :requires functionality

2021-04-15T14:06:56.209Z

Ah awesome! Thanks!

2021-04-15T14:15:01.209200Z

@borkdude It works! I did find that the require is only needed in the list form:

{:paths
 ["bb-scripts"]
 :tasks {midje-a {:requires ([tasks])
                   :task (tasks/midje)}
                                                   
         midje-b {:task tasks/midje}}}
Both work

borkdude 2021-04-15T14:16:23.209400Z

yes, in the second case, the require is automatic

👌 1
borkdude 2021-04-15T14:16:41.209600Z

and the tasks alias is gone

borkdude 2021-04-15T14:16:50.209800Z

so you will never have any conflicts

2021-04-15T14:17:24.210100Z

Great! Thanks