Fork me on GitHub
Jakub Holý12:03:59

Hi folks! How would you build a docker image with a lein-based app in GitHub Actions? Using Multi-Stage Builds and some base image with lein?


If you're interested, I've been working on unifying builds for common tooling and frameworks: (It's similar to source-to-image, if you've heard about that.) There is also a Github Action: Would be interested to hear whether that matches your use case. 🙂

👀 3
Jakub Holý13:03:18

Thanks, that looks really well! The GH Action example would be even better if it showed how to cache the dependencies :) Do you plan to support Windows? Currently the Readme only mentions brew (though the GA Action implies Linux is also supported)


It definitely runs on Linux, but I have never added something to a Linux package repo before, so you'll have to download the release yourself ( I'll see if I can get it built on Windows, but I currently have no way of verifying the result.

👍 3
Jakub Holý13:03:37

It is not critical, we can use lein directly and only use into in GH. Thank you!

👍 3

> The GH Action example would be even better if it showed how to cache the dependencies 🙂 I don’t have an example at hands but used to have caching ability using multistage build + docker context + local maven registry main idea is to keep everything you need to get the dependencies in one named stage. in gh action you can build an image using two command instead of one docker build … : • docker build --target name_of_the_stage -t deps • docker build -t image second command will use result of the previouse command, so there will be no significant time penalty Then you can run result of the first command with simple infinite loop script From running container you can copy downloaded dependencies using docker cp . They can be cached normally.


Using into-docker, something like this should just work™:

- uses: actions/[email protected]
    path: cache-file.tar
    key: ${{ runner.os }}-build
- uses: into-docker/[email protected]
    image: target-image:latest
    builder: intodocker/clojure
    profile: default
    cache-path: cache-file.tar

😻 3
Jakub Holý14:03:20

I guess the cache key should also include a hash of the project.clj or similar...


That sounds reasonable. In this case, it would also work without, but the cache would grow and grow whenever you change project.clj.

Jakub Holý14:03:18

I am not sure how it works. I would suppose that old, unused entries get pruned... Need to do some reading 🙂 I guess into simply unpacks the archive into /.m2/repository and then runs lein build so if the project.clj changed, it will simply install any missing dependencies and ignore any newly unused so using the hash is not really necessary...


Yes, that's basically it. And that might mean that the ~/.m2/repository grows and grows, unless there is a pruning mechanism like you mentioned.

Jakub Holý14:03:35

> Once you create a cache, you cannot change the contents of an existing cache but you can create a new cache with a new key. according to Also the example there hashes the package lock file. So it seems it is necessary after all to include some hash of dependencies ... > GitHub will remove any cache entries that have not been accessed in over 7 days.


Cool, thanks for sharing!

👍 3
Jakub Holý15:03:21

@U011WHW60F8 should perhaps also link to the available builder images, which hopefully describe what they expect from the application to be able to build and run it.


I'll definitely have to do a review of builder images and whether their documentation is up-to-date. I don't necessarily want to maintain a list of those images, so maybe using Github topics is good enough:

💯 3

that would be the best option

👍 3