Fork me on GitHub
#docker
<
2021-08-09
>
zendevil.eth05:08:58

I am running lein uberjar in my local machine and it’s running correctly, but when I run lein uberjar while creating an image like so:

1   FROM clojure:openjdk-8-lein
  1 RUN apt-get update
  2 RUN apt-get -y install npm
  3 RUN npm install -g shadow-cljs
  4 WORKDIR "/humboi"
  5 COPY . .
  6 RUN lein uberjar
  7 EXPOSE 3000
  8 CMD ["java" "-jar" "target/uberjar/humboi.jar"]
I get the error:
#12 570.0 Retrieving re-frisk/re-frisk/1.5.1/re-frisk-1.5.1.jar from clojars
#12 572.5 Failed to read artifact descriptor for cljsjs:react:jar:16.13.0-0
#12 572.5 Failed to read artifact descriptor for ns-tracker:ns-tracker:jar:0.4.0
#12 572.5 This could be due to a typo in :dependencies, file system permissions, or network issues.
#12 572.5 If you are behind a proxy, try setting the 'http_proxy' environment variable.
------
executor failed running [/bin/sh -c lein uberjar]: exit code: 1
How to fix this?

lispyclouds06:08:56

you can always build the uberjar outside and copy it in with the docker file. the way youre building would result in a really fat docker image. i recommend doing all the builds outside and using something like openjdk:16 as the base image

lispyclouds06:08:41

also if youre building outside in a CI for example, the CI can cache the dependencies. you dont have the download it again unless the dependencies change

lispyclouds06:08:14

final docker images should be as lean as possible

zendevil.eth06:08:27

if you have a ci/cd pipeline, your approach would require to push the jar files to version control and put an extra step between committing the code and pushing

zendevil.eth06:08:49

do you know why this dockerfile isn’t working?

lispyclouds06:08:45

no, build the jar using the lein uberjar command using the ci and only have COPY app.jar . in the dockerfile

lispyclouds06:08:23

looking at the error, could be a maven glitch, not sure. is it repeatedly happening? i generally retry on these errors

lispyclouds06:08:45

as for the ci thing, have a docker file like

FROM openjdk:16

COPY target/uberjar/humboi.jar .

ENTRYPOINT ["java", "-jar", "humboi.jar"]
and run the following steps in the ci:
- clone the repo
- lein uberjar
- docker build .

lispyclouds06:08:31

if you use something like GitHub Actions as your CI, is quite easy to install and setup java and lein on the CI: https://github.com/marketplace/actions/setup-clojure