Fork me on GitHub
#babashka
<
2021-04-14
>
jeroenvandijk12:04:45

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

borkdude12:04:40

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

bash < <(curl -s )
you might need sudo

jeroenvandijk13:04:53

Had to use sudo indeed

jeroenvandijk13:04:21

@U04V15CAJ 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 < <(curl -sL )
              
      - run:
          name: Test bb
          command: |
            bb version

jeroenvandijk12:04:27

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

borkdude12:04:30

@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

borkdude12:04:00

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

🙌 6
❤️ 3
jeroenvandijk12:04:05

ah yeah. That’s a very complete example 🙂

Jakub Holý (HolyJak)12:04:15

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!

borkdude12:04:43

you should probably use an underscore in the file structure

3
borkdude12:04:37

~/Library/me/bin/mb_callls.bb

borkdude12:04:47

also probably use one less l

borkdude13:04:02

~/Library/me/bin/mb_calls.bb

wilkerlucio14:04:35

with babashka tasks, I’m often feeling the need to use bash things (like VAR=SOMETHING command ... or do-soething > 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")

wilkerlucio14:04:12

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

borkdude14:04:06

@U066U8JQJ This is already supported :)

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

🆒 6
wilkerlucio14:04:33

oh, awesome! I wasn’t aware 🙂

borkdude14:04:43

probably needs documenting

borkdude14:04:58

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

wilkerlucio14:04:50

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

borkdude15:04:12

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

🆒 3
pez16:04:02

Is it possible to use babashka with AWS lambdas?

borkdude16:04:45

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

pez16:04:33

That’s awesome.

lukasz16:04:23

@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

👍 3
Tomas Brejla20:04:20

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 Brejla20:04:35

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.

lukasz21:04:51

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)

lukasz21:04:54

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

viesti06:04:10

It occurred to me that would it make sense to have the Lambda custom runtime polling loop as a mini library even? Could help taking bb into use in Lambda maybe more. Maybe using http-kit client, or even so that another http client could be used (might help to run as a jvm lib without http-kit even).

lukasz13:04:28

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

lukasz20:04:22

yep, that will work out of the box

pez17:04:54

Thanks. Will check out.

jeroenvandijk19:04:58

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?

jeroenvandijk19:04:56

Ah perfect thanks 🙂

jeroenvandijk19:04:19

I forgot to look there 😅

borkdude19:04:29

No worries :)

borkdude21:04:30

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

🙌 9
Adam Helins11:04:00

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

jeroenvandijk13:04:19

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

borkdude14:04:32

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

jeroenvandijk14:04:56

Ah awesome! Thanks!

jeroenvandijk14:04:01

@U04V15CAJ 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

borkdude14:04:23

yes, in the second case, the require is automatic

👌 3
borkdude14:04:41

and the tasks alias is gone

borkdude14:04:50

so you will never have any conflicts

viesti06:04:10

It occurred to me that would it make sense to have the Lambda custom runtime polling loop as a mini library even? Could help taking bb into use in Lambda maybe more. Maybe using http-kit client, or even so that another http client could be used (might help to run as a jvm lib without http-kit even).