Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I build docker images from inside jenkins/agent #783

Open
objt-pe opened this issue Mar 28, 2024 · 3 comments
Open

How can I build docker images from inside jenkins/agent #783

objt-pe opened this issue Mar 28, 2024 · 3 comments

Comments

@objt-pe
Copy link

objt-pe commented Mar 28, 2024

Describe your use-case which is not covered by existing documentation.

We want to create docker builds from inside the jenkins/agent to push them to an artifactory. Does anyone have a clue how to do this?

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

Are you interested in contributing to the documentation?

No response

@gounthar
Copy link
Contributor

I guess you would have to use DinD or DonD, or use only the docker client and target a docker engine elsewhere. 🤔

@zhan9san
Copy link
Contributor

Hi @objt-pe

It depends how do you use jenkins/agent image.

If you are using k8s plugin with jenkins/agent, generally, the jnlp container(jenkins/agent) acts as a sidecar container and it is recommended to build docker images in your own image.

If you want to use customized jnlp image, you can add jenkins-agent as your customized image's entrypoint like below.

podman is daemon-less. If can be used inside the container.

# Install podman here

WORKDIR /opt
RUN wget https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz && \
  tar -zxvf openjdk-21.0.2_linux-x64_bin.tar.gz && \
  rm openjdk-21.0.2_linux-x64_bin.tar.gz
ENV JENKINS_JAVA_BIN=/opt/jdk-21.0.2/bin/java

ARG VERSION=3261.v9c670a_4748a_9
RUN curl --create-dirs -fsSLo /usr/share/jenkins/agent.jar https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar \
  && chmod 755 /usr/share/jenkins \
  && chmod 644 /usr/share/jenkins/agent.jar

# Set Jenkins connection entrypoint
RUN curl -fsSLo /usr/local/bin/jenkins-agent https://raw.githubusercontent.com/jenkinsci/docker-agent/3261.v9c670a_4748a_9-2/jenkins-agent
RUN chmod a+x /usr/local/bin/jenkins-agent
ENTRYPOINT ["/usr/local/bin/jenkins-agent"]

Feel free to let me know if you have any concerns.

@felipecrs
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants