Jenkins and Docker

As it sounds strangely I lost VM like in I can not find it 🙂 And this VM was quite important because it had Jenkins configured for my Python projects.

But what was it? This VM tested my code for pep8 and pylint violations. It also executed nose test. Not much but allows keep code much cleaner.

I think it is a good opportunity to move to Docker. After rather long time (way to long) I have something that is a compromise between ideal and useful environment.

Docker

About Docker you may read here.

My base image is hbasria/jenkins. But I had one problem with it: permissions. So I done something scary and overwriten default user to root. How? I made my own Dockerfile with:

FROM hbasria/jenkins
USER root

My docker-compose.yml:

version: "2.1"
services:
  jenkins:
    build: .
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - jenkins_home:/var/jenkins_home
        
volumes:
  jenkins_home :     

Another problem I had was with volumes, on windows there are no symlink so I had to play around a little. Problem was because ShiningPanda is using symlinks.

After setting up a container I had to set few things manually (and this is something that I do not like). Connect to container shell as root

docker-compose exec --user root jenkins bash

First create key, get this key, copy and add it to git repository as deployment key,

ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''
cat ~/.ssh/id_rsa.pub

and add repository to know_hosts:

git ls-remote -h git@bitbucket.org:kosci/charlcd.git HEAD

Next visit it’s page at http://localhost:8080 and follow instructions.
Server is working. Time to create project and do some checks.

Project

I’m using ShiningPanda plugin and tox.ini config to make live easier.
My tox.ini looks like this:

[tox]
envlist = py27,py35
skipsdist = True
[testenv]
setenv = VIRTUAL_ENV={envdir}
deps=
    nose
    mock
    future
    flake8
    pylint
whitelist_externals = /bin/bash
commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml charlcd/tests
    /bin/bash -c "flake8 --output-file=flake8-{envname}.log charlcd || :"
    /bin/bash -c "pylint charlcd > pylint-{envname}.log || :"
[flake8]
show-source = True
exclude = .git,.venv,.tox,dist,doc,build,*egg,*/tests/*

How to use this?

Create new Jenkins project, set nice name and select multi-configuration project. Next add repository, set branch, in my case */develop. Because I’m still behind the NAT I cannot use hooks and events.
This tells system what you wanna check.

Under configuration matrix add Tox and select version you need, in my case: py27 and py35.
Under Build add Tox builder and add tox.ini, check Rebuild.
This tells system how to do it.

Finally under post-build actions add Report violations and set pep8 to flake8-*.log and pylint to pylint-*.log.
And Add Publish JUnit test result report and set to **/junit-*.xml
This tells system what you want to see.

Everything works .. almost. Something is wrong and instead of python2.7 and python3.5 I have both 2.7 or both 3.5 runs. But I have checks. I do not have much time so I must stay with such system.

Summary

Docker image should start and configure itself without any user action. But we have some actions that we need to execute manually, as  mention I do not like this.

But the most important: code can be checked ! Yeh ! And I can safety go back to main project 🙂

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s