Fork me on GitHub
#babashka
<
2021-06-15
>
Akiz10: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

borkdude10:06:42

What exactly is your question?

Akiz10:06:34

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

borkdude10:06:16

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

Akiz10:06:41

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

borkdude10:06:21

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

👍 3
Akiz10: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

borkdude11:06:31

@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

2
borkdude11:06:06

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

borkdude11:06:13

that will probably work

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

borkdude11:06:04

@zikajk It should also work with the uberjar

Akiz11: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].

borkdude11:06:27

Here is an uberjar example:

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

(defn -main [& _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}}

borkdude11:06:44

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

borkdude11:06:02

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

borkdude11:06:36

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
borkdude11:06:56

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

👍 2
Akiz11:06:04

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

mike_ananev11:06:15

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

borkdude11:06:01

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

borkdude11:06:03

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

grazfather14:06:00

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

grazfather14:06:41

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

grazfather14:06:18

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

grazfather14:06:36

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

borkdude14:06:01

@grazfather you should use the --static option

grazfather14:06:26

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

borkdude14:06:40

alpine is based on musl, not glibc

grazfather14:06:01

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

kokada15:06:09

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

kokada15:06:19

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

grazfather14:06:07

(from alpine, not from bb)

grazfather14:06:26

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

grazfather15:06:25

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

grazfather15:06:20

hm you have a redundant CMD in there

lispyclouds15:06:27

@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

grazfather15:06:51

ah, Yeah, that makes sense