Fork me on GitHub
#babashka
<
2023-10-05
>
James Orson02:10:56

Is there some kind of quick guide for a “former intermediate bash user trying to escape to babashka”? I’ve tried (likely naively) to replace my scripts with babashka and it seems like since I’m needing to call gnu utils or OS package managers, it isn’t much better at all than using Bash directly. Anyone else have or escape this same experience?

James Orson02:10:57

Here is a clojure library I’ve developed where I have bb and bash equivalent CI/CD scripts: https://git.sr.ht/~jamesaorson/brain/tree/main/item/scripts

James Orson02:10:05

In case you want a concrete example of what I’m saying

nate02:10:10

I find it’s worth switching to bb is there’s a conditional or loop. If it’s just a straight run through a set of commands, then bash is quicker.

👍 2
James Orson02:10:07

Gotcha Most every bash script I need is like, checking what OS you are and installing a list of dependencies basically So it seemed like babashka was increasing the complexity

nate02:10:25

Yeah, sounds like it.

James Orson02:10:41

Is there a benefit to using babashka for app dev over normal clojure though? I know that Biff uses it

nate02:10:24

That first conditional, or needing to do anything with complex data output (like json) and the switch to bb is worth it.

1
2
nate02:10:08

For normal app dev, I just do Clojure.

nate02:10:43

Babashka does well for the glue stuff in dev and for system scripting.

👍 1
James Orson02:10:30

Thanks dude, makes sense

nate02:10:29

You’re welcome. Glad to help.

Bob B02:10:28

my general rule of thumb is if I have to think about or google how to do something in bash, I'm probably better served using babashka... if it's just executing a handful of static commands, it's probably not worth it, but control flow, loops, maps, I'm probably stepping over to babashka. I also have the headache of a windows machine at work, which means I'll usually reach straight for babashka

mmer09:10:10

What I found useful was the combination of writing code that had to break out to do bash like commands such as creating directories etc. It has meant that I can stay in clojure land. Previously I wrote a solution that required me to call pandoc from the bash and then hand over to clojure to do some work. I think now I would do all that within the context of clojure.

Nundrum13:10:25

I am very well versed in bash, and probably go a lot further with it than I should. That said, there are two things that get me to switch over to bb: 1. When parsing data needs something more clever than cut or jq. 2. When I am writing something that is going to be used repeatedly, and the complexity goes beyond "reasonably simple". Particularly if needing to work with filenames that have embedded spaces and such.

Matt LeVeck01:10:31

My experience with bb is very limited. But I just rewrote bash utility in bb, and here is what I noticed. What the util does: 1) Calls a service to get a list of Kubernetes cluster names 2) makes a rest call for each of those names to get a config yaml 3) Munges values in those files to make sure certain keys are unique 4) merges them into 1 file 5) writes the result to a config file path after backing up the old value Where BB is better: 1. BB script is 2-3x as fast as the bash script. Both do the second round of file downloads in parallel. But asking a single client with a thread pool to issue N requests is a lot faster than using gnu parallel to launch N clients 2. Fewer dependencies. The merge step is an easy in memory operation on a map, rather than a call to kubectl. Yaml library is included with Babashka so no yq. Not need for gnu parallel. 3. No other languages. YQ is basically it's own DSL 4. Cli arguments are a lot easier to manage/ make professional 5. Easier to extend features (accept different input sources, output targets) b/c again, cli and control flow is easier in Clojure than Bash. Downsides of BB: Eh... while the bash script requires more dependencies (kubectl, yq, gnu parallel) it's more likely that internal users have those, rather than bb.

👍 1
James Orson01:10:51

Thanks for the rundown For me, I’d often consider Python or Clojure for something this complex anyways, so it doesn’t fit in my head as “replacing bash with…” For me it may be more “replacing python utilities with babashka”

Nundrum01:10:36

If only I could get a rewrite of Saltstack with Babashka/Clojure

1
Matt LeVeck02:10:49

@U05VAB0RW4C the distribution story was easier with babashka than python b/c with python things like the requests and pyyaml don't come included. Easier to just instruct "brew install babashka" and run this script than any of the options available with Python.

👍 1
James Orson02:10:34

Yup and that’s what I’m seeing here I don’t use python outside of work, but I also doubt I could get babashka into my work as I have a hard enough time getting devs to grok python sometimes, and showing them clojure causes them to flee.

Matt LeVeck02:10:09

Yeah. This was a tool that I needed and lots of people find useful. But it wasn't assigned as a project. So nobody could get too mad about the language choice.

👍 1
Santiago19:10:14

While using deps/add-deps in a script running in a github action I’m getting Couldn't find 'java'. Please set JAVA_HOME. I’m setting up Java in a previous step and env | grep "JAVA" shows:

JAVA_HOME_11_X64=/usr/lib/jvm/temurin-11-jdk-amd64
JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.8-1/x64 <--- ta-dah!
JAVA_HOME_8_X64=/usr/lib/jvm/temurin-8-jdk-amd64
JAVA_HOME_17_X64=/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.8-1/x64
what is missing?

borkdude19:10:12

Try debugging in your script with (println (System/getenv "JAVA_HOME"))

borkdude19:10:30

can you post or remove the script to this thread to reduce long code in the channel?

Santiago19:10:30

hum I think the issue is somewhere in the setup-babashka action. I changed my action’s steps to run setup-clojure instead (after setup-java) and now it works

👍 1