Fork me on GitHub
#babashka
<
2021-01-25
>
Eccentric J00:01:41

./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

Eccentric J01:01:40

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.

borkdude09:01:48

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

🎉 3
Marco Pas10:01:55

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?

borkdude10:01:46

@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 Pas10:01:25

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

borkdude10:01:42

Not that I know of

borkdude10:01:29

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

bb --clojure ...
this might help somewhat

Marco Pas10:01:43

Wil give it a try 🙂

borkdude10:01:51

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

borkdude10:01:58

if you are using those

Jakub Holý16:01:56

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))

borkdude16:01:35

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

borkdude16:01:13

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

borkdude16:01:38

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

borkdude16:01:06

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ý16:01:34

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

Jakub Holý18:01:00

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...

borkdude18:01:34

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

borkdude18:01:31

I think the aws pod does support it

Jakub Holý18:01:54

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

Jakub Holý18:01:33

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

borkdude18:01:03

then use those?

Jakub Holý18:01:45

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.

borkdude18:01:27

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

borkdude18:01:26

@U0FT7SRLP 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ý18:01:17

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

Jakub Holý18:01:24

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 
                            :credentials-provider (credentials/system-property-credentials-provider)}))

borkdude18:01:23

cool, hope it works!

Dig19:01:18

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.

👍 3
Jakub Holý19:01:38

BTW thanks a lot for the aws pod

borkdude19:01:29

:thumbsup: good to see it being used

jeroenvandijk08:01:58

@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ý18:01:12

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? ...

borkdude18:01:42

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

Jakub Holý18:01:07

good idea, will try

borkdude18:01:26

> 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ý18:01:11

thanks a lot!!! That could be it

borkdude18:01:39

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

Jakub Holý18:01:09

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

firstclassfunc21:01:29

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 ?

borkdude21:01:07

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

firstclassfunc21:01:32

no, for my bb script.

borkdude21:01:19

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

borkdude21:01:25

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

(ns logger)

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

(ns bar (:require logger))

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