Fork me on GitHub
#babashka
<
2022-09-26
>
Søren Sjørup09:09:54

I’m wondering if there’s an example somewhere of how to do deployment with babashka. Like git tagging and maybe rsync’ing to a remote host.

borkdude09:09:15

@soren Several of my projects do this. My convention is to have a bb publish task that creates a tag, pushes and then CI kicks off a release. E.g. nbb: https://github.com/babashka/nbb/blob/e5d84b0fac59774f5d7a4a9e807240cce04bf252/bb.edn#L55

Søren Sjørup09:09:18

Thank you very much!

lepistane13:09:04

Hello

FROM babashka/babashka:latest

COPY . /app

WORKDIR /app

CMD ["bb", "-m", "", "stream-link", "link", "stream-name", "1]
This is my docker file i run docker build ... i run docker run <img> i get exception
Exception in thread "main" java.lang.Exception: Couldn't find 'java'. Please set JAVA_HOME.
	at borkdude.deps$_main.invokeStatic(deps.clj:439)
	at borkdude.deps$_main.doInvoke(deps.clj:428)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at babashka.impl.deps$add_deps$fn__26719$fn__26720.invoke(deps.clj:92)
	at babashka.impl.deps$add_deps$fn__26719.invoke(deps.clj:92)
	at babashka.impl.deps$add_deps.invokeStatic(deps.clj:92)
	at babashka.main$exec.invokeStatic(main.clj:815)
	at babashka.main$main.invokeStatic(main.clj:1084)
	at babashka.main$main.doInvoke(main.clj:1054)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at babashka.main$_main$f__31212__auto____31222.invoke(main.clj:1123)
	at clojure.lang.AFn.run(AFn.java:22)
	at java.lang.Thread.run(Thread.java:829)
	at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:705)
	at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
Exception in thread "main" java.lang.NullPointerException
	at clojure.lang.RT.intCast(RT.java:1221)
	at babashka.main$_main.invokeStatic(main.clj:1123)
	at babashka.main$_main.doInvoke(main.clj:1109)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at babashka.main.main(Unknown Source)
I am quite new to docker and i am not sure if it's something i am doing
bb.edn

{:paths ["src"]
 :deps {}
 :pods {}}

lispyclouds13:09:56

hey, do you have a dependency download happening in your script or bb.edn?

lepistane13:09:18

i shared my bb.edn (it's empty) and i dont think i am downloading anything in the script

(ns 
  (:require [clojure.java.shell :as shell :refer [sh]]
            [cheshire.core :as json]
            [ :as io]
            [clojure.string :as s]
            [taoensso.timbre :as timbre])
  (:import (java.time.format DateTimeFormatter)
           (java.time ZonedDateTime ZoneId Duration)))

lispyclouds13:09:36

right thats weird, this error generally happens when bb is trying to download a dependency and needs java for it

lispyclouds13:09:48

looking at the stacktrace looks like a dep is being downloaded

lispyclouds13:09:10

look for maybe (deps/add-deps '{:deps ... in your code?

lepistane13:09:25

there is none of that in my code

lepistane13:09:42

i just ran empty script (just ns declaration, without requirements and code) - got the same exception

lepistane13:09:47

changed my bb.edn to

{:paths ["src"]}
now it works

lispyclouds13:09:11

ah interesting

lepistane13:09:22

thanks for the help

lispyclouds13:09:42

not sure what was happening there, maybe @U04V15CAJ has better ideas

borkdude14:09:57

Bb probably checks for non nil deps and then invokes deps.clj

lispyclouds14:09:22

something i learnt today too

borkdude14:09:38

We could check for empty? instead

borkdude14:09:43

PR welcome ;)

kwladyka13:09:23

hey, is babashka mainly (only) about faster start of the application? I have trouble to understand use cases when I could be interested in to use babashka.

kwladyka13:09:26

So I understand use cases as writhing small bash script to do something but in Clojure. Is it correct? Do I miss other use cases?

lispyclouds13:09:48

In general, for me i see bb for the following: • where i would use bash • where i would use python without the machine learning things • CI automation • glue scripts • CLI apps • need Clojure but the run time has to be less than few seconds at max • AWS lambdas

👍 1
lispyclouds13:09:17

Also scripts with real multithreading (and soon virtual threads!) if thats important 😄

kwladyka13:09:26

> CI automation how bb help you with CI?

kwladyka13:09:01

> need Clojure but the run time has to be less than few seconds at max Does it speed up all kind of Clojure systems without any issues?

lispyclouds13:09:31

it only "speeds up" the start time as things are either compiled to native code or interpreted with low overhead. long time perf or things like tight loops with any day be faster on a JVM.

kwladyka13:09:38

so the rule is: if you use pure bb it will be faster, but if you depend on third party libraries, then JVM will be faster. Do I understand this correctly?

lispyclouds13:09:34

bb can do third party libs, provided they follow certain rules. as for the faster bit, its mostly startup time and not necessarily runtime performance

kwladyka13:09:33

I will ask in other way: Can I use bb with jar file to speed up cold start?

lispyclouds13:09:15

if the contents of the jar file is compatible with bb then yes.

kwladyka13:09:29

I know GraalVM or how it is called can do it, but it has issues. I am curious if bb can speed up cold start (starting docker in cloud) which take for example 8 sec. to 2 seconds or something like that.

lispyclouds13:09:38

bb cannot execute arbritary code

kwladyka13:09:47

> compatible What does it mean?

kwladyka14:09:08

So can I use bb to speed up my regular systems or not? It is not clear for me.

kwladyka14:09:42

but as I can understand I can’t use it in that way

lispyclouds14:09:48

so bb is a native compiled environment which interprets clojure unlike the usual clojure which emits JVM bytecodes, which runs differently. meaning it can interop with java code at run time etc. bb doesnt have the jvm so cant interop unless the java class is know ahead of time.

lispyclouds14:09:23

a lot of clojure libs are around java code or have clojure code which emit byte codes. such libs cannot be run on bb

kwladyka14:09:51

oh so bb can’t use Java, only pure Clojure? > unless the java class is know ahead of time Do you mean author of bb include it into bb?

kwladyka14:09:02

ah ok now it is clear

lispyclouds14:09:25

bb is an interpreter and doenst have the full JVM infra anymore, hence the limitations

lispyclouds14:09:02

bb can do java if you compile it yourself 🙂

👍 1
kwladyka14:09:49

Is it simple to make my own bb working with deps.edn from the project?

kwladyka14:09:12

The simple solution to speed cold start could be great

lispyclouds14:09:29

sure, but bb uses its own project system https://book.babashka.org/#project-setup

kwladyka14:09:33

actually if someone will make such solution it will be awesome

lispyclouds14:09:14

if your code isnt too complex you can always have it in a single file and bb script.clj

lispyclouds14:09:35

its in a similar set of ideas like bash or python

kwladyka14:09:53

I am thinking if bb can speed up cold starts in cloud for complex systems

kwladyka14:09:03

8 sec of cold start means 8 sec longer response

kwladyka14:09:07

which is huge

kwladyka14:09:20

if it can be reduced to 1-3 sec. it makes a difference

kwladyka14:09:31

but if it will became hard and complex, then I will not use it

lispyclouds14:09:56

complex code is okay too. you can use its project setup

kwladyka14:09:17

thank you, I will back to this topic in “free time”

lispyclouds14:09:25

bb can produce a single script or a jar if you want too

kwladyka14:09:04

Maybe someone will make a “1 line solution” to prepare bb to run with project and do all things like get libraries from deps.edn by automate

kwladyka14:09:16

that will be huge win

lispyclouds14:09:51

quite doable! 🙂

kwladyka14:09:55

in the world of cloud and dynamic scaling multiple instances

lispyclouds14:09:22

keep in mind, the JVM isnt quick to start but is one of the fastest when running for a while. so optimise not only on start time but how long a thing runs. if its more than 4-5s, the JVM can already beat bb

lispyclouds14:09:11

JVM will probably outperform native code too, which has an even lower startup time than bb

lispyclouds14:09:52

i wouldnt write a long running server in rust for instance

kwladyka14:09:12

> but is one of the fastest when running for a while Do you mean bb is slower in runtime?

lispyclouds14:09:51

so the JVM has the Just In Time compiler (JIT) which produces optimised assembly code based on how your code runs. its only possible when its running so ahead of time (AOT) languages like rust/go wont have these info. and bb is an interpreter, like python. it doesnt emit assembly

kwladyka14:09:02

oh so bb works only with .clj files? not .jar?

lispyclouds14:09:30

it can do jars, provided then contain compatible code 🙂

lispyclouds14:09:38

they are just zips right

lispyclouds14:09:27

but yeah if it has .class files, it cant. bb cant load bytecodes right.

kwladyka14:09:35

So when compile my own bb can I make it start faster and work as fast as standard jar file compiled from Clojure including Java libraries?

kwladyka14:09:53

ok, so my final understanding is:

kwladyka14:09:02

bb can make cold start faster, but it makes runtime slower

lispyclouds14:09:55

yep. the whole reason it starts faster is probably also why its runtime is slower: it doesnt have the fancy machinery of the JVM

kwladyka14:09:01

which now make use cases very clear

kwladyka14:09:25

thank you for explanation

kwladyka14:09:45

It should be written in first line of the doc to make people understand when use bb heh

lispyclouds14:09:20

> It should be written in first line of the doc to make people understand when use bb heh we can take it as a feedback, also PRs welcome!

👍 1
kwladyka14:09:35

out of my curiosity: is babashka name because author is from Russia? 😉

lispyclouds14:09:53

can ask the author @U04V15CAJ 😛

kwladyka14:09:35

oh I didn’t notice he is an author!

kwladyka14:09:57

good job 🙂

lispyclouds14:09:34

as far as i remember, its for the "gray" areas of bash, so the grandma reference, the word-play with bash

👍 1
borkdude14:09:56

I'm not from Russia :)

borkdude14:09:29

babashka is just a nonsense name which sounded funny to me

lispyclouds14:09:52

also you can check out this https://www.youtube.com/watch?v=ZvOs5Ele6VE from me, mostly focusing on scripting and moving from the JVM to native to bb. also has a bb project made from scratch, live code!

👍 1
lispyclouds14:09:07

its a talk at a Linux users group, so has some intro to clojure too, can skip it probably 😛

kwladyka14:09:13

I am always curious how people are so creative to make names for they libraries. I am simple guy and name things in very raw way: for example https://github.com/kwladyka/form-validator-cljs While everyone have cool names for everything 🙂

lispyclouds14:09:11

what do you think is really happening in the hammock?

lispyclouds14:09:23

also id recommend checking out #nbb too since you seem to be involved in cljs too!

kwladyka14:09:41

Thanks. Although I hate node.js 🙂

lispyclouds14:09:07

its the best worst thing we have

😂 1
borkdude14:09:28

We all hate it, that's why I tried to put some Clojure on top ;)

👍 3
wilkerlucio16:09:49

hello, one question about spec.alpha, currently when using anything that depends on clojure.spec.alpha, a babashka user must include the https://github.com/babashka/spec.alpha, I wonder if that should be included by default, given its also part of Clojure core

borkdude16:09:15

@wilkerlucio yes, I want to include that as a built-in, just haven't gotten around to it yet

🙏 1