Fork me on GitHub
Jakub Zika10:06:29

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


What exactly is your question?

Jakub Zika10:06:34

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


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

Jakub Zika10:06:41

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


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

👍 3
Jakub Zika10:06:44

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 ""
                                                                          :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


@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


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


that will probably work

Jakub Zika11:06:50

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


@zikajk It should also work with the uberjar

Jakub Zika11:06:57

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 --------------------------------------------------------------
 - <expr>:2:3
 - <expr>:3:3
 - <expr>: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].


Here is an uberjar example:

[email protected] /tmp $ cat src/program.clj
(ns program
  (:require [medley.core :as m]))

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

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


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


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


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

👍 2

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

👍 2
Jakub Zika11:06:04

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


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


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


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


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


FROM alpine:latest

RUN apk add --no-cache bash curl
RUN curl -sL  | bash

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


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


basically it’s not seen as executable by the loader for some reason


@grazfather you should use the --static option


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


alpine is based on musl, not glibc


yep, I just expected a clearer error about missing libs if that were the issue 🙂


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


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


(from alpine, not from bb)


Confirmed this works great 🙂

FROM alpine:latest

# Needed to install babashka itself
RUN apk add --no-cache bash curl
RUN curl -sL  \
        | bash -s -- --static


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


hm you have a redundant CMD in there


@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:


ah, Yeah, that makes sense