babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-01-25T00:16:41.116400Z

./script/compile: line 49: ~/Downloads/graalvm-ce-java11-20.3.1/Contents/Home/bin/native-image: No such file or directory
I’ll try 20.3.0 just in case 20.3.1 doesn’t work

2021-01-25T01:14:40.117800Z

Got past that part by installing the native-image via gu install native-image but ran into another snag: I built it on OS X when it needs to be built on a similar OS. Setting up a docker container for it now.

borkdude 2021-01-25T09:03:48.119Z

@jayzawrotny FWIW, babashka itself also has a Dockerfile, maybe it helps

🎉 1
Marco Pas 2021-01-25T10:24:55.121Z

I am looking into how to get an overview of test coverage while running tests on some BB code. I can include cloverage as a dependency but unsure how to set the arguments that are required..

Clojure CLI Tool
To use cloverage in a Clojure CLI Project, clj -Sdeps '{:deps {cloverage {:mvn/version "RELEASE"}}}' -m cloverage.coverage *args-to-coverage*

Where args-to-coverage will usually be something like "-p src -s test"
https://github.com/cloverage/cloverage (deps/add-deps '{:deps {cloverage/cloverage {:mvn/version "1.2.2"}}}) Any pointers on how i could set the required parameters?

borkdude 2021-01-25T10:32:46.122500Z

@marco.pasopas cloverage is a pretty low level tool which will instrument your clojure code in a JVM. I'm pretty sure it doesn't work with bb / sci. But what you can do is run your scripts with JVM clojure / leiningen in development and then run cloverage as usual. And then run your scripts with bb when done.

Marco Pas 2021-01-25T10:33:25.123Z

@borkdude Do you have an alternative that could be used with bb / sci?

borkdude 2021-01-25T10:33:42.123200Z

Not that I know of

borkdude 2021-01-25T10:34:29.124100Z

@marco.pasopas Btw, you can run a JVM with bb as well:

bb --clojure ...
this might help somewhat

Marco Pas 2021-01-25T10:34:43.124500Z

Wil give it a try 🙂

borkdude 2021-01-25T10:34:51.124800Z

but you will have to add deps that are built into bb explicitly in a deps.edn file

borkdude 2021-01-25T10:34:58.125Z

if you are using those

borkdude 2021-01-25T12:04:57.125600Z

A small ring router using clojure.core.match: https://twitter.com/borkdude/status/1353674980425404417 Source: https://gist.github.com/borkdude/1627f39d072ea05557a324faf5054cf3

Jakub Holý 2021-01-25T16:19:56.127100Z

Is it so that https://book.babashka.org/#_uberscript does not work with scripts that require a pod? (I am trying to make something that will be simple to run in AWS Lambda. The original https://github.com/dainiusjocas/babashka-lambda/ uses uberscript but I need to include 1-2 pods (thi binaries are present))

borkdude 2021-01-25T16:45:35.128100Z

@holyjak pods aren't included in uberscripts, an uberscript is just one source file

borkdude 2021-01-25T16:46:13.128400Z

you can also make an uberjar, but I don't think you can run binaries from a jar

borkdude 2021-01-25T16:46:38.129Z

so it's probably best to include them in the docker image by explicitly adding them

borkdude 2021-01-25T16:52:06.129700Z

or you can let them download in the lambda but I don't know if that will persist somehow (probably not) and this will incur some startup time

Jakub Holý 2021-01-25T16:52:34.130300Z

I build the uberjar and include that + bb + the pods. That seems to work.

borkdude 2021-01-25T17:14:38.130500Z

cool

Jakub Holý 2021-01-25T18:01:00.132700Z

Question about the AWS pod - I have a fn like this that return the credentials to use for an S3 call:

(defn assume-s3-writer-role []
  (-> (aws/invoke sts-client
                  {:op      :AssumeRole
                   :request {:RoleArn         "arn:aws:iam::123:role/my-s3-role"
                             :RoleSessionName "xyz"}})
      :Credentials
      (select-keys [:AccessKeyId :SecretAccessKey :SessionToken])))
how best to plug it into the s3-client? The basic provider does not support session token yet so I guess I need to set system properties and use the sys. property one...

borkdude 2021-01-25T18:32:34.133700Z

@holyjak I think you can pass these tokens along with the basic credential provider: https://github.com/babashka/pod-babashka-aws#credentials

2021-01-26T08:32:58.151900Z

@holyjak @borkdude Yeah I think this looks good. I’m using a custom tool and credential_process to assume credentials. I could try converting that to Bashbashka at some point

Jakub Holý 2021-01-25T18:33:04.134200Z

not for session token - see https://github.com/cognitect-labs/aws-api/issues/170

borkdude 2021-01-25T18:33:31.134500Z

I think the aws pod does support it

Jakub Holý 2021-01-25T18:34:54.134900Z

to mee it seems you just wrap the cognitect provider, which as per ☝️ does not support it https://github.com/babashka/pod-babashka-aws/blob/main/src/pod/babashka/aws/impl/aws/credentials.clj#L37

borkdude 2021-01-25T18:36:15.135300Z

@holyjak right. @i.slack might be able to explain you what he did here: https://github.com/babashka/pod-babashka-aws/commit/58b0e80709eb00e715abf20174811c50cb4147d4

Jakub Holý 2021-01-25T18:36:33.135500Z

the profile and sys. props. providers support it but not the basic one

borkdude 2021-01-25T18:37:03.135700Z

then use those?

Jakub Holý 2021-01-25T18:37:45.135900Z

Yes, that is what I was thinking. Sadly it seems I cannot use the with-system-properties macro so it is slightly more work but still possible.

borkdude 2021-01-25T18:38:27.136100Z

@holyjak Maybe it works when you just set the right system property before the call?

borkdude 2021-01-25T18:39:26.136300Z

@jeroenvandijk might also have ideas. his credential-process logic might support it, but I'm not sure. this allows you to call out to a different program

Jakub Holý 2021-01-25T18:40:17.136500Z

Yes, both the cred. process and the sys, props would work.

Jakub Holý 2021-01-25T18:41:24.136700Z

I ended up with this:

(defn set-s3-writer-credentials-sysprops []
  (-> (aws/invoke sts-client
                  {:op      :AssumeRole
                   :request {:RoleArn         "arn:aws:iam::123:role/my-s3-role"
                             :RoleSessionName "xyz"}})
      :Credentials
      ((juxt :AccessKeyId :SecretAccessKey :SessionToken))
      (->> (zipmap ["aws.accessKeyId" "aws.secretKey" "aws.sessionToken"])
           (run! (fn [[k v]] (System/setProperty k v))))))

(set-s3-writer-credentials-sysprops)
(def s3-client (aws/client {:api                  :s3
                            :region               region
                            ;; the basic-provider does not support session token yet - see <https://github.com/cognitect-labs/aws-api/issues/170>
                            :credentials-provider (credentials/system-property-credentials-provider)}))

borkdude 2021-01-25T18:42:23.136900Z

cool, hope it works!

Jakub Holý 2021-01-25T18:44:12.137900Z

Any tips how to troubleshoot https://github.com/babashka/pod-babashka-aws/issues/30 ? I would like to find out where the exception is thrown and whether it contains any details about the problematic http response. I guess it was a redirect - from which url to which? ...

borkdude 2021-01-25T18:45:42.138100Z

Is it possible for you to reproduce this using the "normal" aws-api lib?

Jakub Holý 2021-01-25T18:46:07.138300Z

good idea, will try

borkdude 2021-01-25T18:46:47.138500Z

@holyjak Ah, I think I've seen that before. https://github.com/cognitect-labs/aws-api/issues/15

borkdude 2021-01-25T18:47:26.139300Z

> This indicates that you are trying to access an S3 resource (bucket or object) that resides in a different region from the client's region. Remedy: create a new s3 client in the same region you are trying to access.

Jakub Holý 2021-01-25T18:58:11.139500Z

thanks a lot!!! That could be it

borkdude 2021-01-25T18:58:39.139700Z

I had the same problem, you can look at the tests, there as also set the region

Jakub Holý 2021-01-25T18:59:09.139900Z

I do set it. The problem is that the bucket is obviously elsewhere than I expected 🙂

Dig 2021-01-25T19:10:18.140200Z

sorry to be late to the party here. @holyjak you got! that is exactly what I do in my scripts. I have generic util package that runs aws-adfs and returns key, token, etc and I just set it to my system properties. It works and I can just :require the package in the same JVM which does not allow to set env vars.

👍 1
Jakub Holý 2021-01-25T19:28:38.140500Z

BTW thanks a lot for the aws pod

borkdude 2021-01-25T19:50:29.140900Z

:thumbsup: good to see it being used

firstclassfunc 2021-01-25T21:19:29.142Z

Hello everyone, can someone tell me what they are using for logging given most of the libs require some reflection and won’t work without compiling ?

borkdude 2021-01-25T21:31:07.142300Z

@gary001 you mean for a graalvm project, apart from bb?

firstclassfunc 2021-01-25T21:35:32.142700Z

no, for my bb script.

borkdude 2021-01-25T21:42:19.144100Z

ah right. I'm not aware of any fancy logging library for bb, besides the usual prn, println and (binding [*out* *err*] ...)

borkdude 2021-01-25T21:51:25.144500Z

Simple logger to stderr, including namespace, line and col:

(ns logger)

(defmacro log [&amp; msgs]
  (let [m (meta &amp;form)]
    `(binding [*out* *err*] ;; or bind to (io/writer log-file)
       (println (str (ns-name *ns*) ":"
                     ~(:line m) ":"
                     ~(:column m))
                ~@msgs))))

(ns bar (:require logger))

(logger/log "what goes on here")
bar:13:1 what goes on here

borkdude 2021-01-25T21:53:18.144800Z

^ @gary001

👍 4