Fork me on GitHub
#babashka
<
2024-02-05
>
mmer13:02:03

Is there a way to do the equivalent of expect in BB. I am trying to get some automation run but the different OS work differently with expect and I wondered if bb had a built in way of supplying answers to prompted questions?

borkdude13:02:04

What is "expect"?

mmer13:02:24

if you have a script you can use expect to supply answer to cli questions asked by scripts

borkdude13:02:47

this is what you've already said, but I don't know what you're talking about. is "expect" a linux command line tool? babashka doesn't only work on linux

mmer13:02:56

It seems to be something that is used with bash scripts. Lets put it another way - if I run a script in bb can I supply an answer should the script ask a question?

borkdude13:02:30

ok, you were talking about bash. it would have been helpful if you would have supplied that context :) yes, you can do something like that using (bbl)gum: https://github.com/lispyclouds/bblgum

mmer13:02:51

Ok thanks

mmer13:02:20

I would not have come here if it was not something that I felt BB might handle.

borkdude13:02:03

this works by the mechanism of bb shelling out to gum

borkdude13:02:30

you could just shell out to expect then too, I guess

jkrasnay13:02:09

Expect is a utility that can start a child process, wait for the child process to output a certain pattern, then respond by stuffing strings into the child’s stdin.

borkdude13:02:40

(babashka.process/shell "expect" "whatever")

e13:02:35

expect makes interactive terminal programs think they are talking to a real user and terminal by using unix pseudoterminals (pty's), I think Java &/JVM apis can't interface with those out of the box (but there are some 3rd party jvm pty libs)

borkdude14:02:49

just shell out to the damn thing like you would do in bash. if you want cross-platform support, use something like (bbl)gum

richiardiandrea17:02:44

Question, if I switch to use for building a uberjar, would that help me in download/including :pods to it? The problem: I have a project that use build.clj and now it needs a pod (we are making it cross-platform) and I am wondering what is the best way to address that.

borkdude17:02:15

no, it would not help downloading the pod

borkdude17:02:50

maybe I'm understanding it wrong

borkdude17:02:47

tools.bbuild is a babashka-compatible solution to using tools.build. only use it in bb, not in clojure

richiardiandrea18:02:23

@U04V15CAJ Would you suggest me to include :pods as part of the basiswhen building the uberjar?

borkdude18:02:38

I'm not clear on all the details. You are using tools.bbuild which uses a pod, but this isn't the pod you're using in some code in the uberjar?

borkdude18:02:59

Are you shifting from bb uberjar to tools.bbuild because of the problem which was fixed on master?

richiardiandrea20:02:35

No this is an old project that uses build.clj - we are making it cross platform but we need to include pods in the uberjar so that downstream we can use either bb or clojure

borkdude20:02:14

for uberjars there is the trick of including the bb.edn in META-INF/bb.edn so relative to your project, something like resources/META-INF/bb.edn and if you then include :pods in that, I think it will do the trick...

borkdude20:02:39

the pods won't be part of the uberjar, but they will be correctly downloaded

richiardiandrea20:02:49

uhm, then I'll have to provide two files ... my current setup is to only provide a jar to our devops team...

borkdude20:02:29

This file will be part of the uberjar

borkdude20:02:19

the approach I take myself is usually not to talk about pods at all in bb.edn and just write a small wrapper/library which calls load-pod

borkdude20:02:51

but the uberjar approach with META-INF/bb.edn will work as well

❀️ 1
borkdude20:02:01

@U06FS3DLH not sure where this feature is documented

cap10morgan21:02:23

Hmm... I'm not sure it is currently

borkdude21:02:58

I couldn't find it either. anyway the same mechanism is described here for tasks in an uberjar: https://github.com/babashka/babashka/wiki/Self-contained-executable#uberjar

πŸ‘ 1
richiardiandrea16:02:29

Yesterday at the end of the day I got an exception-How is this working? The exception is saying that it cannot run the java command..

richiardiandrea16:02:51

I can dig the code up if you just give me a general idea πŸ˜„

borkdude16:02:24

What do you mean by "this" in "How is this working"?

richiardiandrea16:02:16

I mean, which mechanism pulls the pods down?

borkdude16:02:35

for pulling the pod there is no java required, but for pulling dependencies there is

richiardiandrea16:02:01

uhm, oh I see - so basically my error seems to be that that code that pulls the deps down requires java 11, while my container only has java 17 ... is there a way to set that from the outside (say, a CI env var)?

borkdude16:02:04

if you have java 17 then it should also be able to run code that requires 11?

borkdude16:02:15

backward compatibility

richiardiandrea16:02:46

apologies, yeah that's not what I meant - maybe I'd better fetch the error πŸ˜„

richiardiandrea16:02:51

Clojure tools not yet in expected location: /home/app/.deps.clj/1.11.1.1435/ClojureTools/clojure-tools-1.11.1.1435.jar Downloading to /home/app/.deps.clj/1.11.1.1435/ClojureTools/clojure-tools.zip Unzipping /home/app/.deps.clj/1.11.1.1435/ClojureTools/clojure-tools.zip ... Successfully installed clojure tools! Exception in thread "main" java.io.IOException: Cannot run program "/usr/lib/jvm/java-11-openjdk-11.0.22.0.7-2.el8.x86_64/bin/java" (in directory "jar:file:/app/upgrade-scripts/cardiodi-scripting.jar!/META-INF"): error=2, No such file or directory at [email protected]/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170) at [email protected]/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089) at babashka.process$process_STAR_.invokeStatic(process.cljc:367) at babashka.process$shell.invokeStatic(process.cljc:648) at babashka.impl.deps$add_deps$fn__27336.invoke(deps.clj:100) at borkdude.deps$_main.invokeStatic(deps.clj:1052) at borkdude.deps$_main.doInvoke(deps.clj:882)

richiardiandrea16:02:47

seems like the process is running java-11, how wonder if that is configurable ... or which env var it is using - I am also checking the code as we speak

borkdude16:02:01

I guess the error isn't that you don't have java, but that it tries to start the process inside of a jar as the working directory

borkdude16:02:23

I don't know what exactly you are trying to do, but I need more details, e.g. a repro before I can say anything reliably

richiardiandrea16:02:20

well basically this is using now the trick you suggested yesterday ...just added META-INF/bb.edn and I am launching a script in CI with bb --jar foo.jar

borkdude16:02:16

it shouldn't try to fetch any dependencies when launching an uberjar I think

borkdude16:02:33

but if it does, perhaps you can just add a bb.edn without any dependencies in META-INF/bb.edn and file this as a bug (with a repro)

richiardiandrea16:02:20

uhm ok, I can do that, would that download the pods though? Cause that's what I am after :D

borkdude16:02:26

I think so yes

richiardiandrea16:02:47

kk will try that

richiardiandrea16:02:03

well thank you for your support πŸ˜„

babashka 1
richiardiandrea16:02:50

@U04V15CAJsorry other question - the bb.edn mechanism is the same right? so if I pre-install the pods in my container they will be read from there rather than downloaded correct?

borkdude16:02:19

should be yes

πŸ‘ 1
richiardiandrea21:02:45

I think I see what is going on here, my bb.edn had local/deps {:local/root "."} in it for using deps.edn instead...trying to get rid of that now to see what happens

richiardiandrea21:02:54

no, not that, Exception still happening

borkdude22:02:09

If you can make some sort of repro, I'll take a look tomorrow

πŸ‘ 1
richiardiandrea23:02:40

Removing :deps from bb.edn worked as workaround

richiardiandrea17:02:42

cc @U04V15CAJ sorry for the ping - no rush - just wanted to notify you πŸ˜„

borkdude17:02:25

it seems you found a solution by removing :deps right?

borkdude17:02:40

workaround rather

borkdude17:02:49

or are you still blocked on anything?

richiardiandrea17:02:11

yep worked around, not blocked at the moment thanks to you yeah

borkdude18:02:11

Cool, if possible can you log a GitHub issue? Afk myself now. Can do it later as well

❀️ 1
richiardiandrea18:02:29

yep sorry forgot πŸ˜„