Prepare coursier artifact for offline use inside container

242 Views Asked by At

I have an sbt project producing my artifact xyz. I would like to put it along with all its dependencies in the docker container so it can be used using

coursier launch --mode offline xyz

The important part is that preparation should take use of local cursier cache from host.

I tried

  • executing sbt publishLocal,
  • then resolving my artifact dependencies (cursier resolve xyz),
  • then preparing to directories - local & cache - by copying resolved artifact into them
  • then copying those directories into docker container (as coursier cache and ivy local respectively).

This didn't work because coursier doesn't list .pom and .xml files in its output. I tried copying whole directories (abc/1.0.0 instead of abc/1.0.0/some.jar) but AFAIK there is no reliable way to know how many folders up one has to go because maven and ivy have different dir structures.

1

There are 1 best solutions below

0
On

while my usecase is not quite identical to yours -- I figure I'd write up my findings and maybe my solution works for you as well!

here's my sample dockerfile, I used this to install scalafmt in an offline-compatible way

FROM ubuntu:jammy

RUN : \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*  # */  stackoverflow highlighting bug

ARG CS=v2.1.0-RC4
ARG CS_SHA256=176e92e08ab292531aa0c4993dbc9f2c99dec79578752f3b9285f54f306db572
ARG JDK_SHA256=aef49cc7aa606de2044302e757fa94c8e144818e93487081c4fd319ca858134b
ENV PATH=/opt/coursier/bin:$PATH
RUN : \
    && curl --location --silent --output /tmp/cs.gz "https://github.com/coursier/coursier/releases/download/${CS}/cs-x86_64-pc-linux.gz" \
    && echo "${CS_SHA256}  /tmp/cs.gz" | sha256sum --check \
    && curl --location --silent --output /tmp/jdk.tgz "https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz" \
    && echo "${JDK_SHA256}  /tmp/jdk.tgz" | sha256sum --check \
    && mkdir -p /opt/coursier \
    && tar --strip-components=1 -C /opt/coursier -xf /tmp/jdk.tgz \
    && gunzip /tmp/cs.gz \
    && mv /tmp/cs /opt/coursier/bin \
    && chmod +x /opt/coursier/bin/cs \
    && rm /tmp/jdk.tgz

ENV COURSIER_CACHE=/opt/.cs-cache
RUN : \
    && cs fetch scalafmt:3.6.1 \
    && cs install scalafmt:3.6.1 --dir /opt/wd/bin

the key to offline execution for me was to use cs fetch and set COURSIER_CACHE

here's the offline execution succeeding:

$ docker run --net=none --rm -ti cs /opt/wd/bin/scalafmt --version
scalafmt 3.6.1