Fork me on GitHub
#babashka
<
2022-05-04
>
sheluchin12:05:01

Any advice for using bb tasks to run my backend server? I saw this old https://clojurians.slack.com/archives/CLX41ASCS/p1618303880104300 and wonder if anything has changed since then. I have a task that launches my server now. I'd like to run it in the background, have the ability to monitor and kill it, and send the logs to some text files.

borkdude12:05:35

Can you give more context about what is currently missing in bb? I don't understand the question

sheluchin13:05:39

Sure. It's probably not something missing from bb but just a gap in my understanding. • I can launch the background process using process. What is the best way to kill it at that point? Find the PID and kill it as usual, or is there a more idiomatic approach? • Is there something in the API that I should use to redirect stdout/stderr to files, or is it just including the usual &> foo.log as part of the process command? Nevermind, this looks like something I'd do with process's :out :append, :out-file ..., :err-file ....

borkdude13:05:00

@UPWHQK562 you can kill a process by calling destroy on it

sheluchin13:05:32

But it's a server process that should remain up indefinitely. So once I start it with bb server:run, I'm no longer controlling it with Clojure, right?

borkdude13:05:49

it depends, what you are doing in your scripts

sheluchin13:05:12

Okay @borkdude, I think my questions might just be too general. I'll keep experimenting with it. Thanks for your time.

borkdude13:05:17

And now edamame is exposed in babashka on master as well.

🎉 5
richiardiandrea16:05:49

Hi there, I am trying neil for the first time and did this:

clojure -Ttools install io.github.babashka/neil '{:git/tag "v0.0.28"}' :as neil
And then
clojure -Ttools list
TOOL   LIB                            TYPE  VERSION
neil   io.github.babashka/neil        :git  v0.0.28
tools  io.github.clojure/tools.tools  :git  v0.2.0
but this does not work
clojure -Tneil dep search "babashka.nrepl"
Function not found: babashka.neil.api/dep
Am I missing something?

borkdude16:05:21

@richiardiandrea If you are using babashka, then I recommend installing the bb script rather than using it as a clj tool

richiardiandrea16:05:21

@borkdude yeah we can't do that at the moment - not every dev machine has got babashka (it's not a "required" dev tool)

borkdude14:06:52

Hey @richiardiandrea I deprecated the tools usage now. Just use the -m main entrypoint. It doesn't make sense to me to maintain two different entrypoints. So going forward, I recommend using this: https://github.com/babashka/neil#clojure And there will never be any incompatibilities

richiardiandrea19:06:55

Ok sounds good, unfortunately this means for us no babashska for now but I totally understand

borkdude19:06:46

@richiardiandrea I don't understand your reasoning

richiardiandrea19:06:25

Oh wait, sorry yeah I just realized there is no dependency on the babashka cli

borkdude19:06:37

no, but even if there was, why would that be a reason for not using babashka? like: we would use babashka, but now we're not. eh, why? :)

borkdude19:06:10

you can use neil from bb and clojure, but the command line interface is the same, that was the point I was trying to make

richiardiandrea19:06:44

Oh I see what you are saying. Basically in our case we are not "using it" officially yet for scripts but I am trying to push for it. Neil was an attempt to automate a couple of tasks but because not every dev machine has got bb we wanted to use the Clojure CLI

richiardiandrea19:06:00

I hope this makes sense even if it doesn't too much to me lol 😄

borkdude19:06:21

yes, tl;dr, you can use the clojure CLI, you don't need the bb binary to run neil :)

❤️ 1
borkdude19:06:46

just read the link I sent and it should explain itself, feel free to bother me if it doesn't

richiardiandrea19:06:19

yep I just did and I will try it out

borkdude16:05:51

the clj tool hasn't been updated, PRs welcome

borkdude17:05:02

So, we've added a generic :pre-start-fn to babashka process, which thus also works in shell :

{:tasks {:init (defn print-command [{:keys [cmd]}]
                 (apply println cmd))

         hi (shell {:pre-start-fn print-command} "echo hi")}}

$ bb hi
echo hi
hi
Should we do anything else to make printing the command in shell "easier" or is this sufficient?

Daniel Jomphe17:05:06

Sorry to post a chunk of code but we might use :pre-start-fn sometimes instead of relying on this big global thing here that does that:

borkdude17:05:39

Awesome, so from your perspective: no?

Daniel Jomphe17:05:14

Haha you caught me! Exactly, this would be sufficient for our current use, for sure!! 🎉

cap10morgan21:05:01

Babashka-built clojure official Docker images are now live on Docker Hub! 🎉 babashka docker

🎉 7
borkdude22:05:34

Do you have a link to the code for those curious?

cap10morgan22:05:05

The best thing is the bb.edn addition is really all I had to do! There's probably more changes to make down the road (towards what it would look like if we'd started with babashka), but it's very cool that a big wad of JVM Clojure is (often) that easy to babashka-fy!

borkdude22:05:07

Thanks for sharing! :)

👍 2
wilkerlucio17:05:53

does the image includes babashka, or babashka is just being used to build the image?

cap10morgan17:05:14

just the latter (for now)

👍 1
cap10morgan17:05:48

still thinking about whether / how to do an official babashka image, and if one is even needed when the excellent babashka/babashka images already exist

wilkerlucio17:05:43

I'm thinking it could be useful to have it right away on the image, but not sure since babashka updates so often, and is also so easy to install

borkdude17:05:46

bb is also available in circle's clojure image :)

👍 1
cap10morgan17:05:17

yeah, and it's also often all you need (i.e. you don't need any of the other clojure stuff; jvm, jre, lein, clojure cli, boot, etc.). and currently the official clojure images are all kind of based on the notion that you need some of those things. 🙂 but I'm happy to rethink it if it makes sense at some point.

cap10morgan17:05:48

there's also clojuredart that might need an official image at some point, so there's potentially a bigger rethink coming anyway...

cap10morgan17:05:36

I could imagine perhaps we start by including bb in our latest image, b/c that's already kind of the kitchen sink, every-battery-is-included image

cap10morgan17:05:41

:thinking_face:

cap10morgan17:05:50

@borkdude what do you think? do you see a role for an official clojure babashka image? or would that feel needlessly duplicative?

borkdude17:05:46

I don't really have a strong opinion

👍 1
cap10morgan17:05:02

yeah, I don't either haha

wilkerlucio17:05:28

me neither, but a light opinion that would be nice to have it there already 🫠

cap10morgan17:05:06

@U066U8JQJ as in, already installed in all of the official images (or some logical subset of them)?

wilkerlucio17:05:28

then I dunno, haha

cap10morgan18:05:45

fair enough. I get it, I want babashka in all the places too 😆. but some users of the official images want them as tiny as possible. so we have to strike a balance.

cap10morgan18:05:48

and of course you only hear from the folks that want to add things until you add them... and then you hear from those other folks. a lot. 😅

wilkerlucio18:05:32

in this consideration, how big is babashka? its big enough for people to note/care about?

cap10morgan18:05:26

for me: no. it's easily worth it. for those who will complain at me: yes, everything they don't use is too big haha

cap10morgan18:05:17

another possibility I would entertain is (in part because the babashka/babashka image is so minimal; no java, no clojure cli, etc.) to release variants of the tools-deps images that also add babashka. for those who want both sets of tools / runtime environments. for e.g. those who use bb as dev tooling ala make.