Показаны сообщения с ярлыком docker jenkins slave. Показать все сообщения
Показаны сообщения с ярлыком docker jenkins slave. Показать все сообщения

воскресенье, 22 марта 2015 г.

Docker-Jenkins-Slave 2.0 (DJS2)

I often need to build some RPM or test my code on different operating systems that have different environment, libraries versions etc. On my host machine I use Arch Linux, but my job requires to write software for RHEL/CentOS. It's useful to use buildbots like Jenkins to run this builds on automated basis, commencing builds after any commit, whatever.

Anyway, installing jenkins on host machine and using Docker as slaves is useful, but can clog your computer with garbage files that hard to cleanup. DJS2 offers you isolated environment (LXC container) where your Jenkins and all Docker slaves are executed, and only jenkins data folder with jobs is stored on your computer.

So, if you need to test/build your code on different linux-based operating systems, all you need with DJS2 is only LXC-enabled Linux host machine and Vagrant.

You can get it here: https://github.com/rrader/docker-jenkins-slave

New version of DJS is already on GitHub. It's in beta and still not tested well, but is working on my PC. Try it on your PC and send me feedback, I'd be really pleased to see any feedback - about failures and successful runs as well.

It's really easy to deploy vagrant with different OS slaves on your local machine. Now CentOS 6 and CentOS 7 only available to use, but eventually all supported OSs will be migrated (as CentOS 5, Suse, Debian).

Pull-Requests are highly appreciated :)

Following text is part of README, it's instructions how to get Jenkins+Docker+LXC on your computer working.

Prerequisites


  1. Vagrant
Optional (but is really recommended)
  1. vagrant-lxc plugin: vagrant plugin install vagrant-lxc
  2. vagrant-lxc related configuration on Host. See https://github.com/fgrehm/vagrant-lxc/wiki 

Getting started

$ git clone git@github.com:rrader/docker-jenkins-slave.git djs
$ cd djs
$ ./djs.sh up
[lots of vagrant output ....]
==================================================
Jenkins should be available on 10.0.3.74:8080
Start using slaves with adding one
 e.g. # ./djs.sh add centos7-java Luke
Now you should be able to use your just deployed jenkins on http://10.0.3.74:8080 or similar
Now let's add some slaves with ./djs.sh add <image> <name>
$ ./djs.sh add centos7-java Luke
Unable to find image 'antigluk/jenkins-slave-centos6-java' locally
Pulling repository antigluk/jenkins-slave-centos6-java
[lots of docker output ....]
Status: Downloaded newer image for\
    antigluk/jenkins-slave-centos6-java:latest\
    507e2a18674253d0d7d1f5201ee963681704c2d18310af619f9fcbb0124efaf3
Connection to 10.0.3.74 closed.
This will pull centos7-java image from Docker Hub and start it. After this command ends you should be able to see Luke worker in "Build Executor Status" section on Jenkins.


Notes [important]

Only centos6-java and centos7-java are ready to use now with Vagrant Jenkins


Links

DJS Repository: https://github.com/rrader/docker-jenkins-slave

пятница, 13 марта 2015 г.

New CentOS 7 Maven Slave in docker-jenkins-slave

Today I pushed new Jenkins' slave template into docker-jenkins-slave named "centos7-java".

It's based (thank you, Captain Obvious) on CentOS 7 and it's purpose is to build Maven projects, so image has maven preinstalled.

It's pretty usual. But the news here is that new image doesn't contain awful SSH daemon that breaks Docker's philosophy to run single process in container. Now ENTRYPOINT in container is just running Swarm jar itself:

ENTRYPOINT ["java", "-jar", "/root/swarm-client.jar", "-master", "http://172.17.42.1:8070", "-mode", "exclusive", "-executors", "1", "-fsroot", "/root"]

CMD ["-labels", "docker-centos7-java", "-name", "Chewbakka"]

In order to start slave container previously steps were like this:

1) Start container
2) Inspect it's IP
3) Connect by SSH using special keys that should be already inside Docker image
4) Run Swarm jar (by ssh)

Drawbacks of this approach:
1) You can't pass optional arguments to swarm (without editing start script)
2) It violates Docker's philosophy
3) Overcomplicated start script that has to know container's IP address

So, what's new really:
1) You can pass Swarm arguments to "docker run" command itself
2) Slave start script was reduced to just one-liner script without SSH/keys magic
3) Start script contains maven caching volume to share ".m2" local repositories between machines

Links

Dockerfile and scripts: https://github.com/rrader/docker-jenkins-slave/tree/master/centos7-java
Why you don't need to run SSHd in your Docker containers: http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/
Swarm Available Options: https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin#SwarmPlugin-AvailableOptions

Caching Maven Local Repository in Docker

I'm using Docker instances as Jenkins slaves and run my containers like

# docker run -d --name="Chewbakka" antigluk/jenkins-slave-centos7-java -labels docker-centos7-java -name "Chewbakka"

(actually, I do it using docker-jenkins-slave )

However, it doesn't make sense to keep maven local repository in every container.

It can be done using Docker Data Volumes
We can mount host's directory into any directory inside container if we specify -v argument like this:

-v /tmp/docker-m2cache:/root/.m2:rw

This will mount host's directory /tmp/docker-m2cache into container's /root/.m2

Resulting command will be

# docker run -d --name="Chewbakka" -v /tmp/docker-m2cache:/root/.m2:rw antigluk/jenkins-slave-centos7-java -labels docker-centos7-java -name "Chewbakka"

вторник, 2 сентября 2014 г.

Docker Jenkins Slave Generator


tl;dr: Service for generating Dockerfile for Jenkins slaves is up and running here: http://docker-jenkins-slave.herokuapp.com/ .

Docker jenkins slave


The beginning of story is here: http://antigluk.blogspot.com/2013/10/docker-jenkins.html [russian].
Abstract: If you want to build your project on different environments (e.g. Jenkins installed on Arch Linux, and you want to build RPM on CentOS 6) with jenkins, but you don't want to use virtual machines, which is inefficient wasting of RAM and CPU, using Docker is good idea.