jenkinsci / nomad-plugin

Nomad cloud plugin for Jenkins
https://plugins.jenkins.io/nomad/
MIT License
56 stars 41 forks source link

Some pointers with the docker image option #8

Closed far-blue closed 8 years ago

far-blue commented 8 years ago

hello :)

great to see this jenkins plugin!

One thing I'm confused about is what would need to be in a docker image being launched as a slave. Currently I have an image with the jenkins swarm slave jar - is this what is needed here as well? Or do I need to bundle something different?

iverberk commented 8 years ago

Hi @far-blue,

The only thing you would need in a docker image is Java. The plugin will automatically inject the slave.jar and run it with the correct parameters to connect back to the Jenkins master, easy :-)

far-blue commented 8 years ago

Hmm, interesting. I'm not sure that would work for me, though, as my current container is 'fat' - it has a local copy of MySQL as well so each build has an isolated database it can use for unit tests. I assume if the image is run by copying the slave jar artefact into the /local space and then executed as the 'entrypoint' on the container then the normal running of supervisord to co-ordinate the slave jar and the mysql instance will be bypassed.

If I was to build the image to already contain the slave jar or was to configure the image to look for and use a supplied jar would there be a way to ask the nomad-plugin to 'just run' the docker image without overriding the normal container exec? Possibly passing in some env vars for things like the master ip address and port etc?

iverberk commented 8 years ago

Ah, yeah that would bypass/override your entrypoint with supervisord. Let me think about this. Is there any way for you to just start the mysql instance as part of the test? So before your run the unit-tests you run a bash script or something like that to fire up the mysql service.

far-blue commented 8 years ago

Possibly, yes, although there might be issues with running mysql as the test user. More importantly, though, is that would require a change in build behaviour depending on whether the build was running on master or a static slave or a dynamic slave which I'd prefer not to do. It would also mean updating about 120 projects ;)

I don't know if the slave jar itself has some sort of 'on startup' scripting support - I'm new to the concept of dynamic slaves as we currently use statically allocated slaves via Nomad using the swarm slave system where the slaves are long-running and resources are pre-allocated.

iverberk commented 8 years ago

I understand, was just thinking about possible solutions. Let me think if we can allow containers to just manage themselves and connect to the master on startup. I think it should be feasible.

antweiss commented 8 years ago

@far-blue Currently you can start the mysql instance with the prefix command option and let the plugin execute the slave jar. @iverberk I was also thinking of adding an SSH slave option. your thoughts?

far-blue commented 8 years ago

@antweiss I don't know anything about a prefix command option - it isn't mentioned in the docs for the nomad plugin. Where would I find more info on it?

antweiss commented 8 years ago

Hmm, right, I forgot it hasn't been released yet. It's smoething we've added in the last couple of weeks. This allows you to prepend a command (or a sequence of commands separated by semicolons) to slave.jar invocation. Like: bash -c '<your_cmd_here>; java -jar /local/slave.jar .... More or less as the prefix command in regular Jenkins ssh slaves.

iverberk commented 8 years ago

@antweiss let's create another release today after merging #6

antweiss commented 8 years ago

@iverberk with great pleasure :)

far-blue commented 8 years ago

Ah, cool, yes, that would work :)

iverberk commented 8 years ago

@far-blue version 0.3 of the plugin was released yesterday and the Wiki has been updated to reflect the changes (https://wiki.jenkins-ci.org/display/JENKINS/Nomad+Plugin). Let me know if this solves your issue.

far-blue commented 8 years ago

I've had a good play and managed to get mysql running alongside the java jenkins slave etc. so from that perspective the new prefix command stuff works well :)

However, I was concerned about permissions and preferred keeping mysql running as its own user and I wasn't so keen on using sudo to manage this.

While investigating, I realised that only the 'CMD' for a docker container was being configured via the plugin and Nomad and so the 'ENTRYPOINT' could be used to do what I wanted.

My current setup which appears to be working in tests uses ENTRYPOINT in the Dockerfile to run a shell script as root (via Tini so I don't get PID1 issues). That script first starts supervisord which then manages MySQL and all the associated user permissions and environment changes before then running: /bin/su --login -p -c "$*" jenkins-slave Which effectively runs whatever command you've passed in as the jenkins-slave user in a login shell and preserving the ENV vars created in the Dockerfile and at runtime from Docker and Nomad.

antweiss commented 8 years ago

@far-blue thanks for sharing - that's an interesting approach too. I'm closing the issue as you have a solution.