News for hackers. Stuff that matters.
Re:Introducing Jib — Build Java Docker images better by kinghajj on Tuesday July 10, 2018 @03:07PM (#17501162)
At work, I setup the build system to use Apache Archiva to cache Java dependencies, along with other services like apt-cacher, devpi, and squid, for Debian, Python, and general HTTP caching, respectively. We build all of our images atop the "bitnami/minideb" base, and split the Dockerfiles into "partials" that source a dynamic parent image via a build argument. For example, the partial that sets up Debian package and HTTP caching:

    ARG base
    FROM ${base}
    ARG apt_cacher_host
    ARG http_proxy
    ARG https_proxy
    ARG no_proxy
    ENV HTTP_PROXY="${http_proxy}"
    ENV HTTPS_PROXY="${https_proxy}"
    ENV NO_PROXY="${no_proxy}"
    ENV http_proxy="${http_proxy}"
    ENV https_proxy="${https_proxy}"
    ENV no_proxy="${no_proxy}"
    RUN set -ex; \
        if [ ! -z "${apt_cacher_host}" ]; then \
            echo "Acquire::http::Proxy \"${apt_cacher_host}\";Acquire::https::Proxy \"false\";" >/etc/apt/apt.conf.d/01proxy; \
        fi; \
For Java, another partial creates a Maven settings file with the Apache Archiva URL:

    ARG base
    FROM ${base}
    ARG maven_mirror
    COPY devops/image-partials/java-artifacts/settings.xml /tmp/settings.xml
    RUN set -ex; \
        env; \
        if [ ! -z "${maven_mirror}" ]; then \
            sed -r "s!%%MAVEN_MIRROR%%!${maven_mirror}!g;" /tmp/settings.xml >/usr/share/maven/conf/settings.xml; \
        fi;
The important part of settings.xml is this section:

    <mirrors>
        <mirror>
            <id>archiva.default</id>
            <url>%%MAVEN_MIRROR%%</url>
            <mirrorOf>external:*</mirrorOf>
        </mirror>
    </mirrors>
And voila, Maven will go through Archiva for all its dependencies, which are transparently cached so that subsequent builds don't need to re-download everything again.

There are no comments on this comment yet.