polylith

https://polylith.gitbook.io/ and https://github.com/polyfy/polylith
seancorfield 2021-06-26T05:03:36.142700Z

Started exploring the idea of migrating all our legacy artifacts into projects in our monorepo, even though we're still very early on the refactoring of the overall codebase. Looks very promising: I can just declare that the project depends on the (legacy) subproject that is the main entry point, treating it as a "base" even though it isn't in the Polylith structure (yet!). In tandem with this we're looking at replacing at least parts of our build shell script with a Clojure build.clj script of some sort, with an eye on the upcoming tools.build (that Alex talked about at clojureD) -- we're already taking advantage of being able to run multiple exec functions via -X in the latest CLI prerelease (1.10.3.882).

34🚀
tengstrand 2021-06-27T16:53:38.150600Z

Nice!

domparry 2021-06-29T09:54:19.151800Z

Great going Sean. How many projects do you have to migrate in total? Or is the 16 all of the already?

seancorfield 2021-06-29T16:13:07.152300Z

@domparry We had 14 artifacts that we built for deployment, so those are all projects now, plus development, plus a dev-only tool which I hadn't considered as a candidate for a projects entry until yesterday. So that's "everything" converted in terms of buildable artifacts as projects. But my plan is to pull apart several of our larger artifacts into smaller projects: we have multiple -main functions in our codebase and we run some of them via java -cp the.jar the.main-ns rather than java -jar the.jar, so I plan to get us away from that by adding more projects.

1
seancorfield 2021-06-29T16:13:35.152500Z

(since I can just designate a JAR to build and a :main-class to use)

seancorfield 2021-06-29T16:14:42.152700Z

Then I plan to break apart all those -main namespaces from our legacy projects and those will become bases. That was actually my intention when I started this work, but I got distracted by converting our build system from several shell scripts to a single Clojure script instead 😐

domparry 2021-06-29T16:17:56.152900Z

That's inspiring. I think we are going to dedicate more focused effort on migrating to poly from now on.

1
seancorfield 2021-06-26T05:04:36.143600Z

I suspect I'll start pulling all our our -main functions out into bases fairly soon as part of this work and, yes, more blog posts will accompany it all.

3📚
seancorfield 2021-06-26T08:00:53.145600Z

(defn uberjars [& projects]
  (doseq [p projects]
    (let [uberjar  (requiring-resolve 'hf.depstar.uberjar/build-jar)]
        (with-dir (io/file (str (System/getProperty "user.dir") "/projects/" p))
          (uberjar (-> (calc-project-basis) :aliases :uberjar :exec-args
                       ;; cater for being _above_ the project dir:
                       (update :jar #(str "projects/" p "/" %)))))))))
A function that can be run at the top of the workspace to build uberjars in projects, assuming each project uses depstar and has an :uberjar alias that can be invoked with -X.

seancorfield 2021-06-26T08:01:31.145700Z

(defn- calc-project-basis []
  (let [{:keys [root-edn project-edn]} (t/find-edn-maps)
        deps  (t/merge-edns [root-edn project-edn])]
    (t/calc-basis deps {})))
(assumes clojure.tools.deps.alpha :as t)

seancorfield 2021-06-26T08:02:05.145900Z

and [clojure.tools.deps.alpha.util.dir :refer [with-dir]]

2021-06-26T11:05:06.147900Z

Our team has a couple of lambdas in a Polylith repo. Unfortunately it is a private one, that I cannot share here. We have a project containing a deps.edn with depencencies and aliases. A base with a namespace that contains the lambda entry point. The "api" of the lambda. The base consumes components with functionality used by the lambda, just as in any other Polylith project. To build the lambda, we use depstar and have a "compile" (or did we name it "jar"?) alias that AOT-compiles the code and builds a jar file. That file is the one we deploy to AWS. The jar-file can be manually deployed, or (as we do) with AWS CDK ("infrastructure as code"). Hope this helps!

tengstrand 2021-06-26T13:08:05.148400Z

Cool! This will be interesting to follow 🙂

tengstrand 2021-06-26T13:11:08.148600Z

@furkan3ayraktar has several years of experience of working with AWS lambdas + Polylith. He could be a good candidate to explaining this.

stask 2021-06-26T14:51:36.149Z

Thanks!