babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Jakub Zika 2021-06-15T10:05:29.038200Z

Hi, when I do $ bb uberscript pg_copycat.clj -m pg_copycat.core $ bb pg_copycat.core everything goes fineโ€ฆ When I do $ bb -cp $(clojure -Spath) --classpath src uberjar pg_copycat.jar -m pg_copycat.core $ bb pg_copycat.jar it fails with ----- Context ------------------------------------------------------------------ 1: (ns user (:require [pg-copycat.core])) (apply pg-copycat.core/-main *command-line-args*) ^--- Could not resolve symbol: pg-copycat.core/-main If I rename pg_copycat.core to pg-copycat.core in /src/pg_copycat/core.clj then it works. But all other namespaces (like pg_copycat.utils) can stay with underscore. I would like to keep naming consistent across namespaces. Thanks

borkdude 2021-06-15T10:06:42.038400Z

What exactly is your question?

Jakub Zika 2021-06-15T10:07:34.038900Z

Why does the main namespace has to be different when using uberjar and uberscript.

borkdude 2021-06-15T10:09:16.039400Z

@zikajk I think you should never use -m foo_bar, always use -m foo-bar

Jakub Zika 2021-06-15T10:09:41.039700Z

ok, i thought so.. so it is not a feature. Thanks

borkdude 2021-06-15T10:10:21.040Z

for directory / file names (on the classpath) use underscores, but in code, always use hyphens

๐Ÿ‘ 1
Jakub Zika 2021-06-15T10:55:44.043200Z

Hi, I am trying to pack my script with all the dependencies bb.edn

{:paths          ["src"]
 :deps           {seancorfield/honeysql                                  {:mvn/version "2.0.0-beta2"}
                  douglass/clj-psql                                      {:mvn/version "0.1.2"}
                  clojure-term-colors/clojure-term-colors                {:mvn/version "0.1.0"}
                  borkdude/spartan.spec                                  {:git/url "<https://github.com/borkdude/spartan.spec>"
                                                                          :sha "12947185b4f8b8ff8ee3bc0f19c98dbde54d4c90"}}}
I tried to use both $ bb -cp $(clojure -Spath) --classpath src uberjar pg_copycat.jar -m pg-copycat.core $ bb uberscript pg_copycat.clj -m pg-copycat.core but it still needs to download dependencies from bb.edn when $ bb pg_copycat.jar on different server. What should I to create a script which depends only on BB? Thanks again

borkdude 2021-06-15T11:00:31.044Z

@zikajk if you have a bb.edn in your local directory, bb will always load dependencies. if you want to run the uberscript, then run it from a directory without the bb.edn

1
borkdude 2021-06-15T11:02:06.044700Z

or you could override the classpath with bb --classpath "" pg_copycat.clj

borkdude 2021-06-15T11:02:13.044900Z

that will probably work

Jakub Zika 2021-06-15T11:08:50.047Z

Ahh, this does work with uberscript but does not work with uberjar. So i will get back to using uberscript and I will delete bb.edn during the deployment. Thanks

borkdude 2021-06-15T11:09:04.047400Z

@zikajk It should also work with the uberjar

mike_ananev 2021-06-15T11:09:15.047900Z

@borkdude how to run two tasks with parameters in parallel? e.g. bb run --parallel 'task1 param1' 'task2 param1'

Jakub Zika 2021-06-15T11:11:57.048Z

I am not sure what i am doing wrong but i am not skilful with java classpaths tbh

$ bb -cp $(clojure -Spath) --classpath src uberjar pg_copycat.jar -m pg-copycat.core
$ rm bb.edn
$ bb pg_copycat.jar 
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Could not find namespace: clojure.term.colors.
Location: 2:3
----- Stack trace --------------------------------------------------------------
 - &lt;expr&gt;:2:3
 - &lt;expr&gt;:3:3
 - &lt;expr&gt;:1:10
$ bb uberscript pg_copycat.clj -m pg-copycat.core
$ rm bb.edn
$ bb pg_copycat.clj 
{:exit 2, :out localhost:5432 - no response
, :err }
Cannot connect to database [postgres].

borkdude 2021-06-15T11:15:27.048300Z

Here is an uberjar example:

borkdude@MBP2019 /tmp $ cat src/program.clj
(ns program
  (:require [medley.core :as m]))

(defn -main [&amp; _args]
  (prn (m/index-by :id [{:id 1} {:id 2}])))

borkdude@MBP2019 /tmp $ bb uberjar foo.jar -m program
borkdude@MBP2019 /tmp $ cat bb.edn
{:paths ["src"]
 :deps {medley/medley {:mvn/version "1.3.0"}}}
borkdude@MBP2019 /tmp $ bb --classpath "" foo.jar
{1 {:id 1}, 2 {:id 2}}

borkdude 2021-06-15T11:15:44.048500Z

it ignores the bb.edn correctly with the --classpath "" option

borkdude 2021-06-15T11:16:02.048700Z

Cannot connect to database [postgres]
doesn't seem to be related to bb but more related to your config

borkdude 2021-06-15T11:16:36.048900Z

The issue with -cp $(clojure -Spath) --classpath src is that you are setting the classpath twice. The second option will override the first option

๐Ÿ‘ 1
borkdude 2021-06-15T11:16:56.049100Z

you can combine them: -cp $(clojure -Spath):src

๐Ÿ‘ 1
Jakub Zika 2021-06-15T11:18:04.049400Z

The connection to database is awaited output comming from uberscript. Thank you it seems to be the problem

borkdude 2021-06-15T11:19:01.049800Z

@mike1452 bb doesn't support invoking multiple tasks from the command line yet.

borkdude 2021-06-15T11:20:03.050Z

The --parallel option just means that task dependencies of the invoked task are ran in parallel

mike_ananev 2021-06-15T11:34:48.050300Z

Thank you.

grazfather 2021-06-15T14:05:00.050900Z

Hm, it seems that babashka doesnโ€™t work on Alpine linux. Has anyone else noticed this?

grazfather 2021-06-15T14:06:41.051100Z

FROM alpine:latest

RUN apk add --no-cache bash curl
RUN curl -sL <https://raw.githubusercontent.com/babashka/babashka/master/install> | bash

RUN ls -l /usr/local/bin/
RUN /usr/local/bin/bb -h

grazfather 2021-06-15T14:07:18.051400Z

---&gt; Running in edd842dd84de
total 88200
-rwxr-xr-x    1 3434     3434      90311864 Jun 13 20:04 bb
Removing intermediate container edd842dd84de
 ---&gt; 5930268b3b7d
Step 5/7 : RUN /usr/local/bin/bb -h
 ---&gt; Running in a5f4abfb1f4c
/bin/sh: /usr/local/bin/bb: not found

grazfather 2021-06-15T14:07:36.051700Z

basically itโ€™s not seen as executable by the loader for some reason

borkdude 2021-06-15T14:16:01.052Z

@grazfather you should use the --static option

grazfather 2021-06-15T14:16:26.052400Z

you think itโ€™s a shared lib issue? --static is an option to the install script now?

borkdude 2021-06-15T14:16:32.052600Z

yes

borkdude 2021-06-15T14:16:40.052800Z

alpine is based on musl, not glibc

grazfather 2021-06-15T14:17:01.053300Z

yep, I just expected a clearer error about missing libs if that were the issue ๐Ÿ™‚

grazfather 2021-06-15T14:17:07.053500Z

(from alpine, not from bb)

grazfather 2021-06-15T14:44:26.053800Z

Confirmed this works great ๐Ÿ™‚

FROM alpine:latest

# Needed to install babashka itself
RUN apk add --no-cache bash curl
RUN curl -sL <https://raw.githubusercontent.com/babashka/babashka/master/install> \
        | bash -s -- --static

grazfather 2021-06-15T15:00:25.054700Z

oh, nice, maybe I will use that as my FROM ๐Ÿ™‚ I add a bit after what is shown, itโ€™s to test out my dotfiles installer

grazfather 2021-06-15T15:01:20.055Z

hm you have a redundant CMD in there

kokada 2021-06-15T15:10:09.055200Z

This error is not printed by Babashka Not sure if it is the shell, linker or even Linux itself, but really nothing we could do

kokada 2021-06-15T15:11:19.055400Z

BTW, not alpine fault, this behavior is the same in any Linux distro I know

lispyclouds 2021-06-15T15:16:27.056600Z

@grazfather if youre referring to the CMD ["/bin/sh"] that comes from the base alpine image which we extend. This is the Dockerfile we use: https://github.com/babashka/babashka/blob/master/Dockerfile.alpine

grazfather 2021-06-15T15:16:51.057Z

ah, Yeah, that makes sense