I’m looking for an example of setting up babashka (including paths and such) on CircleCI. Anyone have such an example?
@jeroenvandijk I think you should just be able to do this:
bash < <(curl -s <https://raw.githubusercontent.com/babashka/babashka/master/install>)
you might need sudo
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
@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
he managed to pull off 100% Clojure in that repo ;) (kudos @lee)
ah yeah. That’s a very complete example 🙂
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!
you should probably use an underscore in the file structure
~/Library/me/bin/mb_callls.bb
also probably use one less l
~/Library/me/bin/mb_calls.bb
Thanks, it works!
Had to use sudo
indeed
@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 < <(curl -sL <https://raw.githubusercontent.com/borkdude/babashka/master/install>)
- run:
name: Test bb
command: |
bb version
Thanks!
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")
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
@wilkerlucio This is already supported :)
(shell {:out "the-file.txt" :extra-env {"NOW_VARS" "likeThis"}} "dude")
oh, awesome! I wasn’t aware 🙂
probably needs documenting
it takes the same options as babashka.process, but as the first arg
thats nice, glad to learn this, gonna use often 🙂
:env
is also supported, this replaces all the env vars
Is it possible to use babashka with AWS lambdas?
@pez sure! @lukaszkorecki can tell you more maybe. there is also this blog: https://www.jocas.lt/blog/post/babashka-aws-lambda/
That’s awesome.
@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
Oh totally, I think I have more structured code laying around somewhere, but you know how it works - lack of time etc etc etc
here's also one implementation https://github.com/dainiusjocas/babashka-lambda-layer/tree/master/src/lambda
yep, that will work out of the box
Thanks. Will check out.
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?
@jeroenvandijk Here is an example: https://github.com/babashka/babashka/blob/master/examples/ls_jar.clj
Ah perfect thanks 🙂
I forgot to look there 😅
No worries :)
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
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.
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)
For the JVM Clojure we're just using the SDK + deploying an uberjar with Terraform - startup time in our use case is not relevant
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
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
Speaking about wasm, did someone try this? https://github.com/i-net-software/JWebAssembly ? Useful to have a sandbox for Sci projects? :thinking_face:
btw @jeroenvandijk I couldn't find our old discussion, but bb 0.3.5 now has the :requires
functionality
Ah awesome! Thanks!
@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 workyes, in the second case, the require is automatic
and the tasks
alias is gone
so you will never have any conflicts
Great! Thanks