babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2021-03-31T09:08:11.267800Z

A small demo how you might leverage fully qualified main functions: https://twitter.com/borkdude/status/1377185155077402627

borkdude 2021-03-31T10:16:57.268400Z

Any Windows users want to help with this issue? https://github.com/babashka/babashka/issues/766

borkdude 2021-03-31T10:54:36.268800Z

never mind, figured it out

borkdude 2021-03-31T10:54:47.269100Z

Babashka shebang in a .bat script works!

3
grazfather 2021-03-31T15:36:07.269600Z

I see you use bat

grazfather 2021-03-31T15:36:12.269900Z

I am trying to get them to respect emacs modelines since they don’t respect bb on the shebang as clojure

borkdude 2021-03-31T15:39:54.270300Z

who is them?

borkdude 2021-03-31T15:40:01.270500Z

.bat file?

borkdude 2021-03-31T15:43:41.270700Z

or linux? you can use this trick: https://gist.github.com/borkdude/e6f0b12f9352f3375e5f3277d2aba6c9#file-assoc_pairs-clj-L2

grazfather 2021-03-31T15:58:21.270900Z

no no

grazfather 2021-03-31T15:58:22.271100Z

https://github.com/sharkdp/bat/issues/1600

grazfather 2021-03-31T15:58:50.271400Z

yeah, but bat would use bash syntax

borkdude 2021-03-31T16:00:02.271600Z

oh you mean that bat, I thought you meant Windows .bat :)

grazfather 2021-03-31T16:02:40.271900Z

Yeah, funny confusion 🙂

lread 2021-03-31T16:05:41.273200Z

Just upgraded rewrite-clj’s scripts to use bb v0.3.1's bb.edn, https://github.com/clj-commons/rewrite-clj/commit/7bac58d5bde68b22761d71eaf0592322d1996ace!

richiardiandrea 2021-03-31T16:05:46.273400Z

If I create a uberjar or a uberscript, would my pods be included there as well?

nate 2021-03-31T16:18:38.273700Z

wow, impressive project automation with babashka, this is great to read through

lread 2021-03-31T16:51:10.274300Z

Thanks Nate, I started in bash but have now fully embraced babashka!

borkdude 2021-03-31T17:05:07.278Z

Woohoo!

borkdude 2021-03-31T17:05:25.278500Z

pods are not included as they are platform specific

richiardiandrea 2021-03-31T17:07:17.279800Z

I see, given target machine is compatible with dev machine, how would you recommend distributing a .bb script that uses, for instance, the sql pod?

lread 2021-03-31T17:07:43.280300Z

Here’s a ramble-thought. My bb scripts used to fail fast if a they were not being run with a minimum version of bb. This was done as nicety for folks running my bb scripts. Instead of a mysterious failure, they’d get “hey, upgrade your bb, buddy”. I just removed this min version check because it, ironically, it was relying on recent bb features. My question is: Would it make sense for a bb script or maybe bb.edn to somehow specify a min version of bb and fail fast if that version is not met? I realize this would only help bb versions moving forward, so maybe my idea is a bit late.

borkdude 2021-03-31T17:10:18.281200Z

Oh, that's a great suggestion! I was considering adding something code-wise in bb for it: https://github.com/babashka/babashka/issues/663 but adding this to bb.edn is probably even better

borkdude 2021-03-31T17:11:05.282200Z

I also quite like the version-clj library, but this isn't built-in and have people require it just to compare the bb version is a bit too much overhead maybe

lukasz 2021-03-31T17:12:00.283600Z

(remind's me of a similar config option in Leiningen )

lread 2021-03-31T17:15:39.286100Z

I am surprised more languages don’t offer this kind of check. Or maybe they do, and I am just not aware. I mean backward compatibility is great but it would be nice to effectively say, “yeah, we don’t support forward compatibility, you’ll need to upgrade” instead of failing mysteriously when an old version of tool x tries to access a non-existent new feature.

borkdude 2021-03-31T17:16:23.286600Z

lein supports it but deps.edn doesn't (yet?)

lread 2021-03-31T17:17:42.287200Z

maybe soon (?) with this new build support coming to clojure cli in the pipes.

borkdude 2021-03-31T17:20:26.287400Z

I guess in deps.edn you can just say {:deps {org.clojure/clojure {:mvn/version "1.11.0"}}} and that's your minimum version

borkdude 2021-03-31T17:21:03.288Z

does pom.xml support a min java version?

lread 2021-03-31T17:21:11.288100Z

Oh yeah, I suppose you are right there.

lread 2021-03-31T17:22:39.289600Z

Can’t remember about pom.xml I think there is something in there about what version you want to compile to.

lukasz 2021-03-31T17:23:45.290700Z

FWIW I meant this option: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L37

👍 2
borkdude 2021-03-31T17:23:51.291Z

This is maybe a bad idea, but we could (not should) make :min-bb-version download the min bb version and run the project using that one, so the system bb invokes the needed bb if it's below the minimum

borkdude 2021-03-31T17:25:24.292200Z

but I guess the first minimal step is just exit with an error

lread 2021-03-31T17:25:27.292300Z

Gradle just wafted into my brain. I think I remember it downloading whatever version the gradle file specifies.

borkdude 2021-03-31T17:25:43.292600Z

yeah, boot does that too using boot.properties

borkdude 2021-03-31T17:26:07.293Z

but both gradle and boot aren't very popular, so maybe that's a bad sign? ;)

lread 2021-03-31T17:26:58.293600Z

Ha! I vaguely remember kinda liking gradle, but I was young and impressionable.

borkdude 2021-03-31T17:28:01.294100Z

I heard some people get caught up with the DSL and making builds way too complex

borkdude 2021-03-31T17:28:20.294500Z

I don't have any experience with it myself

lread 2021-03-31T17:28:31.294800Z

Mind you I was coming from maven. So…

borkdude 2021-03-31T17:28:59.295100Z

I know maven only through clojure, I guess I'm shielded a little bit

lread 2021-03-31T17:30:26.296400Z

Ya, I remember it being convenient - so long as you didn’t want to do anything it does not normally do, then, oh boy!

borkdude 2021-03-31T17:31:37.297300Z

then use make/bash + XML-generate the pom.xmls? Sounds a bit like what I'm doing now with deps.edn sometimes ;)

lukasz 2021-03-31T17:41:26.298700Z

From a security perspective you don't want tools to randomly download binaries, just saying

borkdude 2021-03-31T17:43:09.299900Z

@lukaszkorecki Yeah, I understand from that point of view. I started wondering though: what's the difference with downloading binaries (from a controlled source) or .jar files for that matter? Both can screw up your system, but somehow binaries are often considered more suspicious

lukasz 2021-03-31T17:44:00.300600Z

Jars are not usually executable, in this case a binary downloads another binary and replaces itself, right?

lukasz 2021-03-31T17:44:27.301400Z

In some setups machines come with pre-installed stuff, and this approach might not even be an option

borkdude 2021-03-31T17:45:09.302100Z

Note that pod binaries can now be downloaded automatically from a pod registry when loading them, this was by popular request. The bb binary would not replace the system bb, the system bb would just delegate to the newer one if needed.

lukasz 2021-03-31T17:45:28.302400Z

I see. Maybe this should be an opt-in?

borkdude 2021-03-31T17:45:57.303Z

Yeah, I'm not implementing this in the foreseeable future, just throwing it out here for initial feedback.

lukasz 2021-03-31T17:46:02.303300Z

:thumbsup:

borkdude 2021-03-31T17:49:52.304900Z

anyway, :min-bb-version seems like a good idea for bb.edn

borkdude 2021-03-31T17:56:25.305200Z

@richiardiandrea if you use (load-pod 'org.babashka/postgresql "0.0.x") the pod will be automatically downloaded

richiardiandrea 2021-03-31T17:56:52.305500Z

yeah I am in an environment where I am not likely to access the internet

borkdude 2021-03-31T17:59:33.305700Z

@lee Just FYI, this pattern exists: https://book.babashka.org/#main_file Maybe it comes in handy somewhere in rewrite-clj if you want to prevent side effects when e.g. execute bb doc ...

borkdude 2021-03-31T18:00:28.306Z

@richiardiandrea In this case it's better to download the pod(s) yourself and copy them yourself to your artifact/docker image/container

👍 1
borkdude 2021-03-31T18:01:05.306300Z

you can load pods also just using a path: (load-pod "./pod-babashka-postgresql")

richiardiandrea 2021-03-31T18:05:51.306500Z

would just cloning the repo do the job there? (sorry newbie question)

borkdude 2021-03-31T18:06:54.306700Z

cloning what repo?

lread 2021-03-31T18:15:17.309400Z

yeah @lukaszkorecki I sometimes do work on cljdoc and it has a (probably not well known?) feature where you can download a zipped version of docs for offline viewing. I was thinking this could be a potential vehicle, however unlikely, to get something nasty on somebody’s system, if we aren’t careful.

lread 2021-03-31T18:35:26.309800Z

Cool, thanks, I was going to switch to that convention when/if I switched to vanilla tasks, but I think it is probably worth doing now.

bherrmann 2021-03-31T21:29:35.310700Z

fyi: the pom.xml can support dependency ranges, https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN402

richiardiandrea 2021-03-31T22:15:43.311200Z

I have an additional question on this one...I have ":/home/cokap/.m2/repository/org/postgresql/postgresql/42.2.2/postgresql-42.2.2.jar" as result of babashka.classpath/get-classpath...why can't I (import 'org.postgresql.util.PGobject)? Am I missing something?

borkdude 2021-03-31T22:17:05.311600Z

The postgres driver is not part of babashka, it's only part of the pod

borkdude 2021-03-31T22:17:34.311800Z

do you want to transform something into json or an array?

richiardiandrea 2021-03-31T22:19:54.312Z

no unfortunately I have to store a BYTEA

borkdude 2021-03-31T22:23:11.312300Z

ah, byte array, yeah, in this case you can just send over the byte array directly

borkdude 2021-03-31T22:23:23.312500Z

and it will be stored automatically as bytea

richiardiandrea 2021-03-31T22:26:20.313Z

oh cool! I was worried for a second 😄 let me try that

richiardiandrea 2021-03-31T22:58:29.313200Z

works flawlessly!

[query "INSERT INTO file_blobs (name, mime_type, byte_size, content) VALUES (?, ?, ?, ?) RETURNING id"
 sqlvec [query (:title image) (:mime-type image) (:byte-size image) (Files/readAllBytes (:jpath image))]
 inserted-rows (db/execute! db sqlvec)]