Fork me on GitHub
#babashka
<
2022-08-06
>
jmglov13:08:18

I'm having an issue with Babashka pods on ARM (I think). I'm using {org.babashka/aws {:version "0.1.2"}} in an arm64 lambda, and when I try to create a client with (aws/client {:api :s3, :region region}), I get a stream closed exception with a stacktrace like this: https://gist.github.com/jmglov/4d79f2c9a50e3580b36663c21eaddf5c

jmglov13:08:20

My assumption is that the pod is built for amd64 and not arm64, but I don't really know how to resolve this.

jmglov13:08:42

In the meantime, I'll try to verify the assumption by seeing if everything works on amd64.

borkdude13:08:12

@U054AT6KT Could you paste the long stack trace in a gist instead of in the channel?

āœ… 1
ā¤ļø 1
borkdude13:08:19

But if you upload the one you downloaded on your own computer, it might not match that architecture

borkdude13:08:51

There is an issue here with some ideas for improvement: https://github.com/babashka/babashka/issues/1316

jmglov13:08:23

Makes sense. I did confirm that it worked on amd64, so it is an arch issue. I think I'll switch to awyeah-api so I can make blambda work with deps. šŸ˜‰

borkdude13:08:42

aw yeah :)

šŸ˜‚ 1
borkdude13:08:04

You could also just manually download the aarch64 pod

borkdude13:08:22

but yeah, I think awyeah might be good to explore

jmglov13:08:48

Yeah, I could. Or I could also use an amd64 lambda. The choices are paralysing! šŸ˜±

borkdude13:08:41

At least you're not considering #nbb - one less choice!

šŸ˜… 1
jmglov13:08:50

Does Babashka use the standard tools.deps stuff for handling deps.edn , or does it use the ported library? I want to set the local Maven cache to something other than ~/.m2/repository , and I can't figure out how to do that. Setting the M2_HOME env var has no effect (though I'm not sure that's how Maven finds the cache anyway).

borkdude13:08:34

it does use the standard tools deps stuff for bb.edn - the only thing that has been ported is the bash script which was converted to clojure and is part of bb

1
jmglov13:08:04

I vaguely remember that there's some environment variable that one can set to tell clojure to look for the local cache, but I can't craft the right search to find it.

Alex Miller (Clojure team)13:08:03

In the deps.edn, not an env var

jmglov13:08:11

Can you set that from the command line, or does it have to be added to deps.edn?

borkdude13:08:27

In bb's case, you can add it to bb.edn if you want to do stuff with deps for bb

borkdude13:08:13

clojure has -Sdeps to merge options, but bb doesn't have this yet. What you can however do is create another bb2.edn and then refer to that with --config

jmglov13:08:36

For posterity, I found :mvn/local-repo documented here: https://clojure.org/reference/deps_and_cli

borkdude13:08:15

yes, the "reference" usually has all the stuff documented, where "guide" is usually a gentle introduction which covers a lot but doesn't cover all of the options

jmglov13:08:01

It took me a few levels of searches before I realised that "maven cache" is the magic term. šŸ˜‰

jmglov13:08:39

I think the easiest way out for me is probably to use :mvn/local-repo in deps.edn. Thanks both of you for the help! šŸ™‚

jmglov13:08:03

Hrm, setting :mvn/local-repo "/tmp/deps-mvn-repo" in my deps.edn and running bb help still seems to use ~/.m2/repository.

borkdude13:08:35

bb does look at your deps.edn - unless you invoke bb clojure

borkdude13:08:10

or unless you write something like {:deps {current/deps.edn {:local/root "."}}} in bb.edn

jmglov13:08:36

Here's my bb.edn:

{:paths ["."]
 :deps {local/deps {:local/root "."}}}
and deps.edn
{:deps {com.cognitect.aws/endpoints {:mvn/version "1.1.12.206"}
        com.cognitect.aws/s3 {:mvn/version "822.2.1109.0"}
        com.grzm/awyeah-api {:git/url ""
                             :git/sha "0fa7dd51f801dba615e317651efda8c597465af6"}}
 :mvn/local-repo "/tmp/deps-mvn-repo"}

borkdude13:08:17

yeah, hmm, this ain't gonna work I realize, I think because the :mvn/local-repo isn't inherited from external deps

jmglov13:08:19

This is what the Babashka Book says to do if you want to use deps.edn, right?

borkdude13:08:32

yes, if you want to include the deps from deps.edn

jmglov13:08:43

Ah, OK. Is there a way around this in Babashka?

borkdude13:08:48

yes, add it to bb.edn

jmglov13:08:04

OK, so keep all of the deps in bb.edn instead?

borkdude13:08:38

you could keep the deps local/root thing to refer to deps.edn, but the mvn/local-repo isn't inherited from other files

jmglov13:08:38

And add :mvn/local-repo at the top level of bb.edn?

borkdude13:08:08

We should really have something like -Sdeps for this

jmglov13:08:24

That worked as advertised! šŸŽ‰

jmglov14:08:40

Whoa, more weirdness! With a bb.edn like this:

{:paths ["."]
 :deps {com.cognitect.aws/endpoints {:mvn/version "1.1.12.206"}
        com.cognitect.aws/s3 {:mvn/version "822.2.1109.0"}
        com.grzm/awyeah-api {:git/url ""
                             :git/sha "0fa7dd51f801dba615e317651efda8c597465af6"}}
 :mvn/local-repo "/tmp/deps-mvn-repo"}
I ran bb help and saw this, as expected:
Downloading: com/cognitect/aws/s3/822.2.1109.0/s3-822.2.1109.0.pom from central
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central
Downloading: com/cognitect/aws/endpoints/1.1.12.206/endpoints-1.1.12.206.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom from central
Downloading: org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.pom from central
Downloading: com/cognitect/aws/s3/822.2.1109.0/s3-822.2.1109.0.jar from central
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.jar from central
Downloading: com/cognitect/aws/endpoints/1.1.12.206/endpoints-1.1.12.206.jar from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar from central
When I removed /tmp/deps-mvn-repo and ran bb help again, it didn't re-download the deps. Any idea why?

borkdude14:08:32

because of caching I think. Use --force

borkdude14:08:46

(which I'll rename to just -Sforce because that's what it does)

borkdude14:08:03

Messing with your mvn repo (deleting stuff) isn't what the deps tooling expects

jmglov14:08:25

Haha, the deps tooling doesn't know me very well. šŸ˜‰

šŸ˜… 1
jmglov14:08:22

That worked. Oddly enough bb help --force didn't download the deps, but bb tasks --force did. :man-shrugging::skin-tone-2:

borkdude14:08:14

That may be because bb help just prints the help and doesn't process any other flags

borkdude14:08:32

The official syntax is bb --force .... - force is a global option

borkdude14:08:59

The help output will also tell you that ;)

jmglov14:08:46

[jmglov@laurana:~/Documents/code/clojure/s3-log-parser/src]$ bb --force tasks

Downloading: com/cognitect/aws/s3/822.2.1109.0/s3-822.2.1109.0.pom from central
Downloading: com/cognitect/aws/endpoints/1.1.12.206/endpoints-1.1.12.206.pom from central
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom from central
Downloading: org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.pom from central
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.jar from central
Downloading: com/cognitect/aws/endpoints/1.1.12.206/endpoints-1.1.12.206.jar from central
Downloading: com/cognitect/aws/s3/822.2.1109.0/s3-822.2.1109.0.jar from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar from central
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  File does not exist: tasks

borkdude14:08:33

I see... this is worthy of a bug report :)

borkdude14:08:42

(we should migrate this stuff to #babashka-cli :)

jmglov14:08:00

That's actually what I typed, I just got it backwards in Slack. šŸ˜¬

jmglov14:08:16

OK, I'll continue the thread there, because now I need some advice.

jmglov14:08:41

I can file a bug report as well.

borkdude14:08:11

I meant, we should migrate the CLI handling of bb to the bb.cli library - it's all manual right now

borkdude14:08:31

but yes, bug report is fine

jmglov14:08:56

Ah, now I get you.

jmglov14:08:25

OK, so I thought a little more about what I want to do. Here's the situation: ā€¢ I have a bb app (project? dunno what to call it) that will run as a AWS Lambda. It has its deps specified in lambda/bb.edn ā€¢ I have another bb.edn which is used for provisioning the lambda and associated layers; let's call it infra/bb.edn ā€¢ infra/bb.edn should have a deploy-deps-layer task that reads lambda/bb.edn, uses the Clojure CLI to download JARs from Maven and/or Git into a scratch directory (`/tmp/lambda-deps`, for example), then zips that directory up and creates a layer for it.

jmglov14:08:32

So I need to set both :mvn/local-repo and the GITLIBS environment variable. My current thinking is that I have a task in infra/bb.edn that reads lambda/bb.edn, writes a /tmp/lambda-deps.edn, then invokes clojure to do the deps downloads.

jmglov14:08:27

Does this make sense? If so, what clojure command would I run from Babashka to make this work?

borkdude14:08:55

Btw, I think #holy-lambda has figured all of this stuff out already for bb on AWS ;)

Alex Miller (Clojure team)14:08:12

Fyi, you can also set gitlibs via Java system property clojure.gitlibs.dir

Alex Miller (Clojure team)14:08:15

Although I guess you can't set that in the jvm that would matter so nvm

jmglov14:08:46

Holy Lambda is awesome, but: a) it uses Docker, which I don't wanna, and b) it lets me get away with not understanding how all this stuff works. šŸ˜‰

šŸ‘ 1
jmglov15:08:20

How does bb itself invoke tools.deps? Does it literally execute clojure?

borkdude15:08:18

no, it executes deps.clj's main function: https://github.com/borkdude/deps.clj

jmglov15:08:19

If I want to use deps from a bb task, would you recommend doing the same? Does bb provide any helper functions for this?

borkdude15:08:38

deps from a bb task: explain

borkdude15:08:53

bb tasks support :extra-deps if you need extra deps in a task

jmglov15:08:35

Haha, I'm about to link a gist that will make you lose your lunch. Do not look directly at this gist!

jmglov15:08:52

Doesn't quite work, but at least you see what evil magicks I'm playing with here.

jmglov15:08:03

It basically almost works.

borkdude15:08:38

@U054AT6KT You can use (with-out-str (babashka.deps/clojure ["-Spath" "-Sdeps" ...])) as well, if you like. babashka.deps/clojure is basically the same as invoking deps.clj's main function

jmglov15:08:26

Ah, that seems much nicer!

borkdude15:08:55

(clojure [...] {:dir ...})

borkdude15:08:58

is the syntax

jmglov15:08:13

So the next arg after -Sdeps is the literal EDN string, right? So then I don't have to spit deps.edn to the work-dir.

borkdude15:08:24

yes, just an EDN map will do as well

jmglov15:08:47

That's much much nicer than having to set :dir and all. Thanks!

jjttjj13:08:48

@U054AT6KT FWIW i've had luck using clojure.tools.build/uber, passing it :exclude ["^clojure[/].+"] to make zips(uberjars) to deploy babashka projects to lambda (I also had an aversion to using docker for this)

borkdude13:08:35

@U064UGEUQ babashka supports bb uberjar for this as well

jjttjj13:08:15

yup I have a version using that too šŸ™‚ Currently using the build tool one because it's more similar to the non-bb deploy code and avoids shelling out

šŸ‘ 1
jmglov14:08:29

I also have the requirement to be able to edit the code in the AWS Console, so I want to deploy the deps as a layer but not include the lambda sources. Maybe this can be accomplished with an uberjar, but it would require removing paths from the bb.edn or deps.edn as far as I can tell.

borkdude14:08:24

I repeat: bb uberjar produces an uberjar from bb.edn :)

borkdude14:08:30

no JVM required

jmglov14:08:52

For my use case, Iā€™d need to preprocess bb.edn to remove the lambda sources, though. Or maybe you weren't replying to me?

borkdude14:08:39

I was blabbering in general, just broadcasting generally useless info haha

šŸ˜‚ 1
djhaskin98718:08:40

I made a channel for those who are enthusiastic about making CLI tools in Clojure over at #cli-makers if anyone's interested.

lilactown21:08:08

is there a good TUI lib that works with babashka?

lilactown21:08:21

or should I look into nbb for that?

lilactown21:08:53

I want to write a TUI app that has a structured text area with autocomplete

borkdude21:08:04

Btw, ffz comes to mind as well. Some people use it in combination with #babashka-neil

borkdude21:08:37

you can launch fzf from babashka with babashka process, this works great

ā¤ļø 1
lilactown21:08:22

ah, I'll see if lanterna can do that

borkdude21:08:31

TUI is difficult in Java-ish environments. Better luck with #nbb probably: See https://github.com/babashka/nbb#reagent

borkdude21:08:56

@lilactown What's also exciting to try (but more experimental) is bun with FFI. E.g. here it uses blipgloss which is a bun library which wraps lipgloss, a go library, and calls it via FFI: https://github.com/babashka/nbb/blob/main/examples/bun/blipgloss.cljs I've also got an ncurses example here: https://github.com/babashka/nbb/blob/main/examples/bun/ffi.cljs Again, note, experimental (because bun) ;-)

šŸ’Æ 1