babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-01-26T01:22:28.146200Z

If this is covered in the docs I’ll look harder but didn’t see it on first pass: Is there a way to break up scripts into separate files in bb and require them?

2021-01-26T15:14:52.153500Z

Thanks will read this thoroughly

2021-01-26T02:07:28.146400Z

I suppose that’s what pods do?

bherrmann 2021-01-26T02:52:54.146800Z

You can use add-classpath to tell bb to search other places for your ns

bherrmann 2021-01-26T02:55:30.147Z

See https://book.babashka.org/#libraries

2021-01-26T06:22:21.147300Z

Thanks! I’ll have to experiment with that.

2021-01-26T06:27:54.150100Z

I used the dockerfile from the babashka repo to compile the postgresql pod. I copied the generated binary to my server in the .babashka/pods/repository/org.babashka/postgresql/0.0.1 directory then tried to run the postgresql sample code:

.babashka/pods/repository/org.babashka/postgresql/0.0.1/pod-babashka-postgresql: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /home1/[redacted]/.babashka/pods/repository/org.babashka/postgresql/0.0.1/pod-babashka-postgresql)
----- Error --------------------------------------------------------------------
Type:     java.io.IOException
Message:  Stream closed
Location: /home1/[redacted]/public_html/clj-test/cgi-bin/./test.clj:4:1

----- Context ------------------------------------------------------------------
1: #!/home1/[redacted]/public_html/clj-test/bb
2:
3: (require '[babashka.pods :as pods])
4: (pods/load-pod 'org.babashka/postgresql "0.0.1")
   ^--- Stream closed
5: (require '[pod.babashka.postgresql :as pg])


----- Stack trace --------------------------------------------------------------
user - /home1/[redacted]/public_html/clj-test/cgi-bin/./test.clj:4:1
Any thoughts how I can compile the pod to not require GLIBC_2.14?

borkdude 2021-01-26T08:45:37.152400Z

Yes, you need to use the --static flag to compile it to a static binary on linux

2021-01-26T15:10:16.153Z

Oh I missed that flag sorry about that. Thanks again!

lispyclouds 2021-01-26T06:44:46.151100Z

@jayzawrotny you could try compiling the pod statically. https://www.graalvm.org/reference-manual/native-image/StaticImages/ Maybe have the uberjar and then use native-image --static ...? Thats how we build the babashka static binary

2021-01-26T15:15:49.154100Z

Thanks I think I was missing the static flag!

lispyclouds 2021-01-26T06:45:46.151500Z

The static steps here might help: https://github.com/babashka/babashka/blob/master/.circleci/config.yml#L142

2021-01-26T16:21:47.154300Z

https://github.com/babashka/babashka/blob/master/script/compile#L71 this section is helping me a lot too

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

borkdude 2021-01-26T08:45:37.152400Z

Yes, you need to use the --static flag to compile it to a static binary on linux

2021-01-26T15:10:16.153Z

Oh I missed that flag sorry about that. Thanks again!

2021-01-26T15:14:52.153500Z

Thanks will read this thoroughly

2021-01-26T15:15:49.154100Z

Thanks I think I was missing the static flag!

2021-01-26T16:21:47.154300Z

https://github.com/babashka/babashka/blob/master/script/compile#L71 this section is helping me a lot too

2021-01-26T22:47:45.155100Z

That worked! Thanks again for all the help borkdude and lispyclouds.

2021-01-26T22:49:01.155900Z

What’s the best way to use honeysql? Is it still what’s recommended here? https://github.com/babashka/babashka-sql-pods/#honeysql

borkdude 2021-01-26T22:52:28.156400Z

@jayzawrotny This is now the more easy way: https://github.com/babashka/pod-babashka-sqlite3#honeysql We should update the sql-pods docs

borkdude 2021-01-26T22:52:51.157Z

(PR always welcome)

borkdude 2021-01-26T22:53:11.157300Z

So:

(ns honeysql-script
  (:require [babashka.deps :as deps]
            [babashka.pods :as pods]))

;; Load HoneySQL from Clojars:
(deps/add-deps '{:deps {honeysql/honeysql {:mvn/version "1.0.444"}}})

(require '[honeysql.core :as sql]
         '[honeysql.helpers :as helpers])

borkdude 2021-01-26T22:53:41.157500Z

ah let me just update it right now

borkdude 2021-01-26T22:55:23.157700Z

done

borkdude 2021-01-26T22:56:42.158500Z

@jayzawrotny Note that using babashka.deps requires a JVM and is only fast when the classpath is cached. I'm not sure if that's available on your shared host

borkdude 2021-01-26T22:56:54.158900Z

But you can build an uberjar with babashka as well and upload that

2021-01-26T22:59:07.160700Z

So that means building a static babashka + honeysql as a static binary and babashka-sql-pod as a static binary?

borkdude 2021-01-26T22:59:53.161100Z

To build an uberjar, add honeysql to a deps.edn and then bb -cp "$(clojure -Spath)" -m your-script.main --uberjar foo.jar You don't need to change babashka itself

borkdude 2021-01-26T23:00:21.161600Z

this is just to prevent needing a JVM in the shared host

2021-01-26T23:00:34.161900Z

And I should do that in the babashka build docker container then upload to my shared host?

borkdude 2021-01-26T23:01:03.162200Z

you can run docker containers there?

2021-01-26T23:01:08.162500Z

No

borkdude 2021-01-26T23:01:31.163300Z

oh, I see, no you don't need to build babashka itself to be able to use it with source libraries

2021-01-26T23:01:33.163400Z

I just meant build it in your linux container for babashka on my local

2021-01-26T23:01:39.163700Z

Ohhh

borkdude 2021-01-26T23:02:33.164500Z

as long as you manage to get the source on the classpath, it's fine. babashka.deps can manage this for you (through tools.deps on the JVM) or you can do it yourself in some other way

borkdude 2021-01-26T23:02:48.164900Z

e.g. an uberjar is a way to package the source in a standalone file

borkdude 2021-01-26T23:03:16.165700Z

well "standalone". you still need bb to execute it: bb foo.jar

borkdude 2021-01-26T23:04:33.166900Z

I guess you can even package the pod in resources and then spit it out on the shared host using io/copy the first time

borkdude 2021-01-26T23:05:29.167700Z

but you will also need to copy bb itself there, so maybe one extra binary file to copy isn't that bad

borkdude 2021-01-26T23:06:01.167900Z

@jayzawrotny https://book.babashka.org/#_uberjar

2021-01-26T23:07:39.169Z

I’ll have to try that tonight. Thanks for all the help, I really appreciate it!

borkdude 2021-01-26T23:08:13.170100Z

No problem. You can also git clone honeysql and then add the source to the classpath using babashka.classpath. This is another way without the JVM

borkdude 2021-01-26T23:08:43.170500Z

assuming it has no dependencies

2021-01-26T23:11:28.172600Z

I’m thinking getting some third-party libs like honeysql in there is the last major problem that needs to be worked out and tested before at least writing a guide\tutorial, then with that super uberjar that might streamline the process.

2021-01-26T23:11:57.172900Z

One thought I haven’t decided yet on though is if I should make a PR to add a dockerfile to the sql pod (and eventually other pods) or if I should create a template repo with some scripts and presets to help others get started?

borkdude 2021-01-26T23:12:38.173500Z

We can publish a static release if that helps

2021-01-26T23:13:21.174100Z

Oh yes! That would reduce some steps for people. How can I help with that?

borkdude 2021-01-26T23:14:55.175100Z

We generate a CircleCI config here: https://github.com/babashka/babashka-sql-pods/blob/master/script/generate_circleci.clj You would just have to add one extra job that is the same as the other linux one but with the --static, which you could do using an environment variable

borkdude 2021-01-26T23:15:17.175800Z

I'm off now, getting late. PR welcome

2021-01-26T23:15:25.176Z

Cool, I can handle that. Thanks again!