babashka-sci-dev

Eugen 2021-10-23T10:04:52.018100Z

thanks @borkdude, I'll have a look at that as well

Eugen 2021-10-23T10:05:46.019Z

thanks @rahul080327 for the context, it's really helpfull - I haven't played with that but I will give it a try. I found https://ask.clojure.org/index.php/8990/how-to-do-a-http-request-over-a-unix-socket-in-clojure

borkdude 2021-10-23T10:06:26.019300Z

Perhaps the answer has changed with Java 17

Eugen 2021-10-23T10:10:28.020700Z

I found an http server over unix sockets in rust and I think I can use that to test the connection and make a piece of code work - or a reproducer

borkdude 2021-10-23T10:11:02.021100Z

why not talk to docker directly?

Eugen 2021-10-23T10:11:57.021700Z

I don't know the API and I want to have something simple

Eugen 2021-10-23T10:12:14.022Z

that I can also println debug

borkdude 2021-10-23T10:12:53.022400Z

makes sense

lispyclouds 2021-10-23T10:17:59.025100Z

as far as i understand java 16+ has made it possible to connect to a socket using the SocketChannel class and we need to do the write of the whole http payload onto the output stream it gives. not sure if theres any higher level abstractions than that in java stdlib. maybe if we have a thing to convert url and opt map to the http payload string, we can maybe attempt a self contained client.

lispyclouds 2021-10-23T10:18:37.025500Z

> why not talk to docker directly? did you mean shelling out to it too? @borkdude

borkdude 2021-10-23T10:19:24.025900Z

no, I meant instead of the http server example

borkdude 2021-10-23T10:20:13.026800Z

it seems contaijners needs an abstraction layer that leaves the option to do the communication in different ways

borkdude 2021-10-23T10:20:26.027300Z

or it needs a simplified java 17 fork without external deps

borkdude 2021-10-23T10:21:18.028300Z

I forgot to mention @eugen.stan, @rahul080327 has also made this thing: https://github.com/lispyclouds/pod-lispyclouds-docker ;)

lispyclouds 2021-10-23T10:21:35.028900Z

> it seems contaijners needs an abstraction layer yeah thats what i was thinking of, pass a :transport key in the client opt map and pass :http-client or :curl

borkdude 2021-10-23T10:22:24.030100Z

A pod in go might also work, since all the docker stuff is already in go and it would make it pretty light weight

lispyclouds 2021-10-23T10:22:27.030300Z

yeah the pod "works" but has some streaming caveats. my hope is to make contajners src compatible with bb

borkdude 2021-10-23T10:22:38.030500Z

yeah that would be optimal

borkdude 2021-10-23T10:23:02.030900Z

you could however implement streaming using sockets in a pod as well

borkdude 2021-10-23T10:23:12.031300Z

with some client side wrapping code

borkdude 2021-10-23T10:23:47.032300Z

but it seems for most scripting cases you wouldn't need streaming, am I wrong?

lispyclouds 2021-10-23T10:24:01.032700Z

problem with the go approach is that the go lib changes all the time and quite the coupled api with the server, quite a task to maintain. with the clj approach its simply adding the openapi yaml

lispyclouds 2021-10-23T10:24:36.033200Z

the go lib too is essentially a glorified http client 😄

lispyclouds 2021-10-23T10:25:10.033600Z

> but it seems for most scripting cases you wouldn't need streaming, am I wrong? yeah most of the cases should be covered

borkdude 2021-10-23T10:26:04.033800Z

:)

borkdude 2021-10-23T10:27:08.035100Z

ok, to summarize all the options: 1. make contaijners source compatible with bb (either using babashka.curl or JDK 17 which needs a bb upgrade) 2. use nbb + dockerode or something 3. use the docker pod and extend with features if necessary. streaming can be implemented with some more work 4. Just use the JVM for these tasks 5. Use another language for these tasks

Eugen 2021-10-23T10:27:36.035400Z

a good bunch of options

Eugen 2021-10-23T10:27:53.035800Z

using nbb would mean to migrate the code I have to cljc / cljs

borkdude 2021-10-23T10:28:14.036400Z

yeah this would be a different direction and having docker stuff for bb would be good

Eugen 2021-10-23T10:28:18.036600Z

I'll first look at doing something in Java to have it in bb

Eugen 2021-10-23T10:28:29.037Z

so no tooling is changed

borkdude 2021-10-23T10:28:57.037800Z

bb is not yet based on java 17 but this is possible

lispyclouds 2021-10-23T10:29:49.038900Z

some heads up maybe, if somehow we need to extend some classes or something to make java's http client talk unix sockets, we may need some :gen-class stuff and not sure if that would be bb compatible. thats what we had to do with the OkHttp client

borkdude 2021-10-23T10:30:48.039700Z

why do you need an http client at all if you communicate over domain sockets

lispyclouds 2021-10-23T10:31:08.040200Z

docker is doing http over sockets

Eugen 2021-10-23T10:31:19.040600Z

socket is binary stream, http is a protocol on top of that

borkdude 2021-10-23T10:31:39.040900Z

does the JDK 11 client perhaps now support this in JDK 17?

lispyclouds 2021-10-23T10:31:52.041100Z

afaik, no

borkdude 2021-10-23T10:32:12.041800Z

it seems like babashka.curl isn't a bad idea then

borkdude 2021-10-23T10:32:21.042100Z

for bb

lispyclouds 2021-10-23T10:32:21.042200Z

i could not find a way to tell it to use a unix socket not a tcp one

Eugen 2021-10-23T10:33:25.042700Z

did you ask nicely ? (joking 😄 )

lispyclouds 2021-10-23T10:34:20.043200Z

if only there was sudo in java

Eugen 2021-10-23T10:34:29.043500Z

:))

borkdude 2021-10-23T10:33:46.042900Z

or the pod

borkdude 2021-10-23T10:34:50.044500Z

#spire is also making a pod which supports streaming

lispyclouds 2021-10-23T10:35:05.045200Z

i wanna side on the src compat, i would know most if not all things should work in a simpler way

Eugen 2021-10-23T10:35:18.045700Z

I think we should also raise an issue to make the default http client work over unix sockets in jave

lispyclouds 2021-10-23T10:35:20.045900Z

and adding bb.curl should not the too hard

borkdude 2021-10-23T10:35:36.046200Z

@rahul080327 isn't the contaijners stuff async by default?

lispyclouds 2021-10-23T10:37:15.047800Z

no, as the underlying OkHttp client has quite a different callback based async behaviour, never gotten around to implement that. however for streaming its easier to throw it in a loop in a future and read events

borkdude 2021-10-23T10:37:51.048100Z

ok this will make things much easier then for bb compat

lispyclouds 2021-10-23T10:39:47.049400Z

when and if project loom lands, no need for async 😛

lispyclouds 2021-10-23T10:41:02.050400Z

yeah so this is where we would need the :gen-class to extend classes and supply to the java client

borkdude 2021-10-23T10:41:37.050800Z

I think you could also use reify instead

borkdude 2021-10-23T10:42:06.051800Z

But this is making things more complex anyways. I would say try the bb.curl approach and make reader conditionals

Eugen 2021-10-23T10:42:06.051900Z

checked the imports and they use some dependencies - so adapting might require some work

borkdude 2021-10-23T10:42:44.052300Z

isolate the http client namespace into one place, make it .cljc and use bb.curl in the :bb condition

lispyclouds 2021-10-23T10:59:25.053900Z

yeah its the client and the ability to read pem files for which https://github.com/into-docker/pem-reader is used, which i think should be bb compatible? needs data.codec as the only dep. curl can handle pem files on its own and does a better job 😄

borkdude 2021-10-23T11:05:08.054700Z

I haven't used data.codec with bb before, so that assumption needs testing :)

lispyclouds 2021-10-23T11:05:36.055100Z

yeah if we are doing bb.curl this dep can be dropped too

lispyclouds 2021-10-23T11:09:22.056400Z

that reminds me, mutual TLS is a bit tricky with the java client too, docker/podman uses it for authenticating to remote container engines

Eugen 2021-10-23T11:38:55.056900Z

http client won't work unless it's fixed. It has :

static void checkURI(URI uri) {
        String scheme = uri.getScheme();
        if (scheme == null)
            throw newIAE("URI with undefined scheme");
        scheme = scheme.toLowerCase();
        if (!(scheme.equals("https") || scheme.equals("http"))) {
            throw newIAE("invalid URI scheme %s", scheme);
        }
        if (uri.getHost() == null) {
            throw newIAE("unsupported URI %s", uri);
        }
    }

borkdude 2021-10-23T11:39:51.057100Z

Major facepalm

Eugen 2021-10-23T11:40:26.057700Z

client was built when there where no unix sockets in JDK so this was not on the roadmap

lispyclouds 2021-10-23T11:41:45.058600Z

ah interesting, i assumed i needed to inherit something like OkHttp but the issue seems to be much more basic, TIL

lispyclouds 2021-10-23T11:43:21.059500Z

would it still be possible to pass a http://blah/<rest of the docker path> to it? this is essentially how curl works

Eugen 2021-10-23T11:48:38.060300Z

that is the first blocker and I submitted a JDK bug and twitted about it - hopefully someone sees it 🙂

Eugen 2021-10-23T11:49:08.060900Z

I did not try it further

lispyclouds 2021-10-23T11:52:17.062100Z

nice, i think if we go ahead with the bb.curl approach as a starter and if and when we have native support we can deprecate it

Eugen 2021-10-23T11:53:17.062700Z

perhaps as the the client might take a long time to get fixed if the fix is more complicated

Eugen 2021-10-23T11:53:47.063300Z

if the fix is as simple as fixing the checkURI then it might get backported to 16

borkdude 2021-10-23T12:05:54.063600Z

you can try to override this class and compile it locally with a change ;)