News for hackers. Stuff that matters.
Re:Introducing Jib — Build Java Docker images better by mattlondon on Tuesday July 10, 2018 @09:44AM (#17497981)
Maybe someone can help me out on a question I've not got a clear answer on: is it better to build your artefact (jar file in this case) and put that in the docker image, or is it better to put everything you need in the image (source files, dependencies etc) then build the artefact from within the container?

Seems to me like the first approach (compile outside then put artefact in container) is the most sane/sensible approach and the one used here in Jib, but I have seen people advocating the build-in-container approach as better (self-contained, repeatable and so on).

Any benefits to the build-in-container approach that are compelling?

Re:Introducing Jib — Build Java Docker images better by bzajax on Tuesday July 10, 2018 @10:00AM (#17498129)
Docker recently has support for multi stage builds. So you can use one Dockerfile to define how to build your image (produce your jar and necessary other resources) and then copy them into a fresh container running off a more lightweight image that might not contain all the intermediates and your build tools.

https://docs.docker.com/develop/develop-images/multistage-bu...

Re:Introducing Jib — Build Java Docker images better by jacques_chester on Tuesday July 10, 2018 @07:09PM (#17502988)
> Docker recently has support for multi stage builds.

I view these as a future antipattern. They bring what is properly CI's work inside the Docker daemon, which makes it a larger attack surface (many folks run PRs sight-unseen) and obscures it from outside tooling.

They only exist because of the limits of the Dockerfile format. With something like Jib, that disappears.

Re:Introducing Jib — Build Java Docker images better by zokier on Tuesday July 10, 2018 @02:04PM (#17500625)
Multi-stage builds is definitely my preferred method of building stuff, but the problem I've found is that caching dependencies is bit of a pain, either you need to do some tricks with volumes or your builds will be very slow.
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.
Re:Introducing Jib — Build Java Docker images better by peterwwillis on Tuesday July 10, 2018 @12:26PM (#17499563)
I would do both.

Make a build container that pulls in the Git hash that you want to build/test against. You can keep your dependencies, build process, unit and func tests in the container. Your dev team can use the same container image to build and test in the same way that you do, pulling in the latest code from Git and running a docker build. Now nobody needs to set up their environment because it's all just in the Docker image in the same way.

You don't need all those build and test files in production, so you can build a new "deploy container" with just the artifacts from your build process. I would also record the versions of your dependencies, as well as the SHA hash of the build/test container you used, and the SHA hash of the Git repos you pulled from. You can also set things like flyway migrations to run each time the container runs.

Now you can deploy this second container somewhere. You can then use the same build/test container you used before to run func tests against the deployed container, to double check it works in your deployed environment.

Re:Introducing Jib — Build Java Docker images better by hinkley on Tuesday July 10, 2018 @12:41PM (#17499720)
The former can be handily taken care of in your CI toolchain. You need a build agent with all of the CLI tools you need for your build. Many support Docker these days. Some can even spin up images on demand.
Re:Introducing Jib — Build Java Docker images better by peterwwillis on Tuesday July 10, 2018 @02:19PM (#17500780)
This is (for me) the best part of keeping your build process in a container: reducing the complexity of the build agent. The only software dependencies on your build agent are Docker and Git. Your CI/CD job pulls a Git repo with a Dockerfile, and runs 'docker build', and that pulls every dependency it needs.
Re:Introducing Jib — Build Java Docker images better by hinkley on Tuesday July 10, 2018 @04:08PM (#17501627)
Agreed, and I can’t wait to work someplace like that again.

We have a build agent with 9 versions of Node in it. It was 6 when I started here. Once a month I get to help someone figure out weird errors because one task has the wrong value in a drop down. It’s such busy work I can’t even.

When I run the CI system, shit gets done and people are expected to be able to recreate build failures by themselves. Give a man a tool, make it reliable, then expect him to use it.

Re:Introducing Jib — Build Java Docker images better by jacques_chester on Tuesday July 10, 2018 @07:11PM (#17503000)
I am obliged to refer you to Concourse, which is really really good at containerised build and automation: https://concourse-ci.org/
Re:Introducing Jib — Build Java Docker images better by peterwwillis on Wednesday July 11, 2018 @02:51PM (#17509315)
I really like how stupid easy that index page is to read and understand. These seem like pretty good docs.

Some of the documentation is missing, so I'm not sure if I missed this or not. But can you make a pipeline out of independently configured jobs? Or a pipeline of pipelines? Often you'll want to chain jobs or pipelines that are owned by different groups. I imagine they support this, if they support teams...

Re:Introducing Jib — Build Java Docker images better by jacques_chester on Wednesday July 11, 2018 @07:31PM (#17511068)
The usual way to create pipelines of pipelines is that one pipeline puts to a resource that another pipeline will trigger on.

For example, one pipeline might do a bunch of stuff and drop a file into a bucket. Unbeknownst to pipeline 1, pipeline 2 is triggered by the file drop and begins to do its own thing.

The key here is that all statefulness is the responsibility of Resources -- Concourse does not do very much except bookkeeping about what Jobs have seen what versions of a Resource.

So if you need multi-pipeline coordination you can do this through any shared state you please. One that I personally like is tagging repositories, these are a nice visible marker of activity to observers.

At Pivotal each team tends to have several pipelines. Teams which rely on lots of upstream work (Release Engineering, Master Pipeline, CloudOps) tend to run many more pipelines which respond to activity by upstream teams. Similarly, Buildpacks has many pipelines which react to changes made in projects outside our control. When Node releases a new version, the pipeline checks out the sourcecode and begins to roll a new buildpack from scratch. At no point do the downstream teams need to coordinate with the upstream teams.

I'd say that automation is one of our secret weapons, but I never shut up about it.

Re:Introducing Jib — Build Java Docker images better by paulddraper on Tuesday July 10, 2018 @09:54AM (#17498082)
Building in a container gives you the portability benefit of having tools installed in a container.

But not building in your productiom container makes it smaller.

Dockerfiles can actually do both, via "mutli-stage builds". You can build in one container and in the same Dockerfiles copy files from that build container to your final container.

Some take a really extreme stance where the production container has nothing superfluous, not even a shell. https://github.com/GoogleContainerTools/distroless

Re:Introducing Jib — Build Java Docker images better by rifung on Tuesday July 10, 2018 @02:25PM (#17500844)
> Any benefits to the build-in-container approach that are compelling?

The build in container approach makes it so that in theory you have reproducible builds too from any Docker supported machine. I personally like this approach because it makes it so that you don't run into the case where "It works on my machine" when testing locally.

Re:Introducing Jib — Build Java Docker images better by adrianmsmith on Wednesday July 11, 2018 @08:33AM (#17506337)
I think Java has such good build tooling that you don’t need to build in a container for reproducible builds. Other languages might be different.

Install the JDK, install Maven, check out the project, “mvn package” and it’ll download what it needs and produce the JAR to be copied into the Docker image by the Dockerfile.

Re:Introducing Jib — Build Java Docker images better by humbleMouse on Tuesday July 10, 2018 @11:17AM (#17498822)
Everything your jar contains can be stored in a git-hub repo with the project. Then you build a fat jar and put it in the image.
Re:Introducing Jib — Build Java Docker images better by zokier on Tuesday July 10, 2018 @02:01PM (#17500602)
I would advice against using fat jars with docker. They do not layer nicely, so your layer sizes become much bigger than necessary, slowing everything down. If you have multiple applications then with fat jars you lose the ability to share the common bits in the applications, which could also have impact on maintainability.
Re:Introducing Jib — Build Java Docker images better by humbleMouse on Thursday July 12, 2018 @11:45PM (#17520389)
I would argue that fat jars make everything simple and portable. Especially if you do performance testing frequently on hardware that isn't running docker. You can compare performance baremetal vs. VM's this way.

Furthermore, as log as you use gradle/maven with artifactory then maintainability of fat jar artifacts is pretty simple.

Re:Introducing Jib — Build Java Docker images better by organsnyder on Tuesday July 10, 2018 @09:53AM (#17498067)
We run our builds within containers (using the Jenkins k8s plugin) for repeatability, but the generated artifacts (jars and Docker images) are pushed to our artifact repository (Artifactory) as part of the build process. Our final deployable artifact is our base image with a single layer added to include our app.jar.