Create image for jenkins agent

410 views Asked by At

I am trying to create a maven-based buildkit image for the jenkins agent. If you create an image and run it as an agent, it takes infinite repetition. I think the image is built incorrectly, but it asks to inspect the Dockerfile.

FROM jenkins/inbound-agent:alpine as jnlp

FROM maven:3.6.3-jdk-11-slim as maven

RUN apt-get update && \
    apt-get install -y \
        git \
        libfontconfig1 \
        libfreetype6

FROM moby/buildkit

COPY --from=jnlp /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-agent
COPY --from=jnlp /usr/share/jenkins/agent.jar /usr/share/jenkins/agent.jar

ENTRYPOINT ["/usr/local/bin/jenkins-agent"]

When only the maven agent is created without the "FROM moby/buildkit" statement, it runs without problems.

1

There are 1 answers

8
Dmytro Sirant On

Updated answer with a full example:

Your Dockerfile doesn't have references to the maven image. If you need to have buildit in your final image you can install it by downloading from the GitHub or copying it from a docker image as you have for Jenkins agent.

I didn't test the docker file, but I hope you got the idea.

FROM jenkins/inbound-agent:alpine as jnlp
FROM moby/buildkit as buildkit

FROM maven:3.6.3-jdk-11-slim

RUN apt-get update && \
    apt-get install -y \
        git \
        libfontconfig1 \
        libfreetype6

COPY --from=buildkit /usr/bin/build* /usr/local/bin/
COPY --from=jnlp /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-agent
COPY --from=jnlp /usr/share/jenkins/agent.jar /usr/share/jenkins/agent.jar

ENTRYPOINT ["/usr/local/bin/jenkins-agent"]

Update:

Per request in the comments, here is the version that might work for JDK8. You need to match all the components to have the same version to work:

FROM jenkins/inbound-agent:latest-alpine-jdk8 as jnlp
FROM moby/buildkit as buildkit

FROM maven:3.6.3-jdk-8-slim

RUN apt-get update && \
    apt-get install -y \
        git \
        libfontconfig1 \
        libfreetype6

COPY --from=buildkit /usr/bin/build* /usr/local/bin/
COPY --from=jnlp /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-agent
COPY --from=jnlp /usr/share/jenkins/agent.jar /usr/share/jenkins/agent.jar

ENTRYPOINT ["/usr/local/bin/jenkins-agent"]