<![CDATA[@mgreau :: Blog]]>https://mgreau.com/postshttp://mgreau.com/posts/images/cover-blog-devoxxfr2015.jpg@mgreau :: Bloghttps://mgreau.com/postsRSS for NodeWed, 19 Apr 2017 09:21:23 GMT60<![CDATA[[Talk] Migrate Maven CI jobs to Pipeline as code with Jenkins 2 and Docker]]>

This is the talk I gave at DevopsDDay 2016 and Docker Meetup Nantes 2017 about Jenkins 2, Maven, Pipeline as Code and Docker. It was the opportunity to revisit the problems that we have had and the solutions adopted, and some best practices around Maven builds in Docker containers, all managed by the Jenkins Pipeline as Code pattern:

Embedded Video

Recorded @ DevopsDDay 2016

Summary of the presentation

Click, click, click…​ The clicks in the Jenkins UI to handle all the Maven jobs haunt you even at night? You want to manage them with the same process that you use for source code?

If I tell you that you can manage all your Maven builds with 3 lines of Groovy in a Jenkinsfile, it’s cool, isn’it?

exoCI {
    dockerImage = ‘exoplatform/ci:jdk8-maven32’
}

With this case study you will understand why and how we have upgraded more than 300 Jenkins “standard Maven jobs” to Pipelines on our eXo Platform CI instance.
This talk is an opportunity to revisit the problems that we have had and the solutions adopted, and some best practices around Maven builds in Docker containers, all managed by the Jenkins Pipeline as Code pattern.

]]>
https://mgreau.com/posts/2017/03/01/maven-ci-jobs-to-pipeline-with-jenkins2-and-docker.htmlhttps://mgreau.com/posts/2017/03/01/maven-ci-jobs-to-pipeline-with-jenkins2-and-docker.htmlWed, 01 Mar 2017 00:00:00 GMT
<![CDATA[Convert AsciiDoc to HTML/PDF & publish to GitHub Pages with Travis CI and Asciidoctor Docker containers]]>
Purpose

This blog post presents a simple way to automatically convert your AsciiDoc content to HTML and PDF, then publish those files to a public website on each commit.

There are many way to do it, maybe you have already used Jekyll or other static site generator like that. The real benefit of this one is that the workflow is done thanks to only one Travis CI configuration file.

The High-Level View
You have all your AsciiDoc sources files on one branch, all the generated files on another branch and just one configuration file.
All resources explained in this post are listed below:

Overview

The following diagram gives you a quick overview of all interactions between GitHub, Travis CI, Docker and Asciidoctor.
Travis CI makes it possible because it allows you to run any Docker container. This isolates your build from the machine running on Travis CI and allows you to use an Asciidoctor environment that has been prepared for you.

AsciiDoc to Github Pages with Travis and Docker Asciidoctor
Figure 1. Convert your AsciiDoc content to HTML & PDF, then publish those files to GitHub Pages courtesy of Travis CI running Asciidoctor via the provided Docker container(s).

Prerequisites

This post assumes that:

Prepare your GitHub project

Add files to your GitHub project

The first step is to push some files to your master branch. The following GitHub project gives you a sample AsciiDoc content using images and include directive.

All samples come from this OpenDevise GitHub repository, thanks to Dan Allen.

All files available on this demo project are explained below:

Example 1. Files listed on master branch
+ images
   |- tiger.png     (1)
+ includes
   |- include.adoc  (2)
.gitignore
.travis.yml    (3)
demo.adoc      (4)
LICENSE
README.adoc    (5)
1 Image used in AsciiDoc content
2 AsciiDoc content included in the demo.adoc content
3 Travis configuration and scripts to build and publish the project, this file is explained in the Travis part.
4 Sample AsciiDoc file to convert
5 Documentation for the GitHub project, then converted to index.html file for the website

Create a Token for Travis CI

Travis CI will push files on a dedicated branch of your GitHub project, so you need to create a token to allow Travis CI to do it.
As you can see on the following screenshot, you just need to access to your GithHub Personal Settings page and click on the Generate token button, then check the public_repo scope:

GitHub Token Configuration
Figure 2. GitHub Configuration: Create a token used by Travis CI

Travis CI Configuration

Connect Travis CI to your GitHub project

Once your AsciiDoc project is available on the master branch, you need to access to your Travis CI Dashboard and do some quick configuration so that Travis CI can build your project:

  1. First, on your Travis Profile page, you need to Flick the repository switch on for your GitHub project:

Travis Configuration
Figure 3. Travis CI Configuration: Activate Travis CI on the project
You can’t see your project on the list? Click on the Sync account button (top right) and it should be ok.
  1. Then, as shown below, go to the Project Settings tabs and configure it:

    1. Check some options on General Settings

      1. check the Build only if .travis.yml is present option

      2. check the Build pushes option

    2. Create some Environment Variables that will be used in .travis.yml file:

      1. GH_USER_NAME : your GitHub username

      2. GH_USER_EMAIL : your GitHub account email

      3. GH_TOKEN: the token created on previous step

        Uncheck the Display value in build log option
      4. GH_REF : the URL to your github project

Travis Configuration
Figure 4. Travis CI Configuration: Project Settings

.travis.yml: Travis CI Configuration and Scripts

The .travis.yml file is the most important file here ;)
Indeed, in this file, you tell to Travis CI how to process your AsciiDoc files and where to publish the generated files.
Those scripts will be executed after each update on master branch.

file .travis.yml
sudo: required

services:
  - docker                  (1)

before_install:            (2)
  - mkdir -p output
  - docker pull asciidoctor/docker-asciidoctor

script:
  - docker run -v $TRAVIS_BUILD_DIR:/documents/ --name asciidoc-to-html asciidoctor/docker-asciidoctor asciidoctor -D /documents/output *.adoc      (3)
  - docker run -v $TRAVIS_BUILD_DIR:/documents/ --name asciidoc-to-pdf asciidoctor/docker-asciidoctor asciidoctor-pdf -D /documents/output *.adoc    (4)

after_error: (5)
  - docker logs asciidoc-to-html
  - docker logs asciidoc-to-pdf

after_failure:
  - docker logs asciidoc-to-html
  - docker logs asciidoc-to-pdf

after_success:      (6)
  - cd output ; mv README.html index.html ; cp -R ../images images
  - git init
  - git config user.name "${GH_USER_NAME}"
  - git config user.email "{GH_USER_EMAIL}"
  - git add . ; git commit -m "Deploy to GitHub Pages"
  - git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages > /dev/null 2>&1
1 Tell Travis CI that you want to use Docker
2 Create the needed output directory and download the official Asciidoctor Docker image from DockerHub
3 Convert AsciiDoc files to HTML to the /documents/output/ path with a Docker container
4 Convert AsciiDoc files to PDF to the /documents/output/ path with another Docker container
5 Display logs from containers if a problem occured
6 Initialize a git project in the `output/ sub-directory in order to push the generated files and images to the gh-pages branch

Travis Build Logs

Travis CI gives you access to each build logs.
You can see in realtime, what is going on when AsciiDoc files are processed by Asciidoctor on each Docker container (one for HTML output and one for PDF output here)

Travis CI Build
Figure 5. Travis CI Build

Published files (HTML & PDF)

Finally, when the Travis CI Build has succeeded, you can view the generated files at:

Example 2. Files listed on gh-pages branch
+ images            (1)
   |- tiger.png
demo.html         (2)
demo.pdf          (3)
index.html    (4)
README.pdf
1 The images folder is copied so that images are published to GitHub Pages Website
2 The HTML output file
3 The PDF output file
4 The README.html is renamed to index.html in order to have a homepage file for the Website

You can see below a screenshot with both demo.html and demo.pdf files.

AsciiDoc to HTML and PDF published files
Figure 6. HTML and PDF files published on GitHub Pages converted from the same AsciiDoc content by Asciidoctor

I hope this post was useful and it helped you understand how to combine Travis CI and Docker to automatically convert content written in AsciiDoc and publish the output to GitHub Pages on each commit.
There are a lot of other ways to do it, I’d love to have your feedbacks about it, so feel free to add a comment.

]]>
https://mgreau.com/posts/2016/03/28/asciidoc-to-gh-pages-with-travis-ci-docker-asciidoctor.htmlhttps://mgreau.com/posts/2016/03/28/asciidoc-to-gh-pages-with-travis-ci-docker-asciidoctor.htmlMon, 28 Mar 2016 00:00:00 GMT
<![CDATA[[Talk] Improve your Java Environment with Docker @ HanoiJUG 2015]]>

Our Session with Thomas Delhoménie about how to Improve your Java Development Environment with Docker at Hanoi JUG 2015 with a Java EE 7 / Angular / WildFly / Redis / MySQL Application with Docker containers:

Description:

Dockerize your Java Development Environment with Machine & Compose

Developers, Docker Compose is the key to be efficient with your development environment!

Whatever the project and the technologies behind it, all developers should be able to work on it quickly without losing time to setup their development environment.

Today, we really think that Docker, with Machine & Compose, have changed the way to work on developer side.

And now, as a developer, you are able to develop quickly with an environment closest to the production environment.

We will show you how you can develop, build, debug and run your Java, Web, multi-databases applications easily thanks to Docker.

]]>
https://mgreau.com/posts/2015/11/05/improve-java-dev-environment-with-docker.htmlhttps://mgreau.com/posts/2015/11/05/improve-java-dev-environment-with-docker.htmlThu, 05 Nov 2015 00:00:00 GMT
<![CDATA[#docker4Dev: Copy Docker images from one docker machine to another]]>
Overview

In this post, you will see how to copy images from one docker machine to another by using docker-machine scp command available since docker-machine 0.3.0. It may be useful if you have no Internet access neither local docker registry installed.

About this post

Language EN / Timereading 10 mn

Today I really think that Docker is not only a revolution for Ops and DevOps teams, but also on the Development environment side and that’s just a beginning.

That’s why I have a lot of docker machines created on my laptop in order to organize my several development environments. But the fact is that you frequently want to use an image on a machine that is already present on another existing docker machine. And if you are offline or if you Internet connection is slow, you can’t execute a 'docker pull' command, so how to deal with that?

Docker Machine scp
Figure 1. Copy Docker images from machine to machine with scp

Install Docker Machine

Installation via Docker Toolbox

Two weeks ago, Docker announced a new installer for Mac OS X and Windows called Toolbox.

Toolbox installs everything you need to get Docker running in development: the Docker client, Compose (Mac only), Kitematic, Machine, and VirtualBox.

Even if, under the hood, Machine still uses Boot2Docker, now containers are managed by Machine.

You can find all informations about Toolbox at the following URLs:

Installation via Command line

If you still want to install Docker machine without Toolbox, you can execute the following commands:

$ curl -L https://github.com/docker/machine/releases/download/v0.4.1/docker-machine_linux-amd64 > /usr/local/bin/docker-machine  (1)
$ chmod +x /usr/local/bin/docker-machine (2)
1 Download the latest docker-machine binary according to your target platform
2 Apply executable permissions to the binary

Then whatever the choice you made for installing it, you should be able to execute the docker-machine help command to see the scp command on the list:

$ docker-machine help
...
Version: 0.4.1 (e2c88d6)  (1)
...
Commands:
  active		Print which machine is active
  ...
  scp			Copy files between machines  (2)
  ...
  help, h		Shows a list of commands or help for one command
1 Docker Machine 0.4.1 released on August, 14, 2015
2 The scp command is available since docker-machine 0.3.0

Copy image from machine to machine

Unfortunately, for now it is not possible to do it with one command. Indeed, the machine scp command is used to copy the export image file between machines, so, before that, the docker machine ssh command is used to manage file on the source machine and at the end on the target machine.

The docker machine scp usage is based on the machine names, and is similar to the default scp syntax.

Commands explained

$ docker-machine ls --filter=state=Running  (1)
NAME                ACTIVE   DRIVER       STATE     URL                         SWARM
default                      virtualbox   Running   tcp://192.168.99.102:2376       (2)
devnation-2015      *        virtualbox   Running   tcp://192.168.99.104:2376       (3)
docker4dev-ee7-js            virtualbox   Running   tcp://192.168.99.105:2376       (4)


$ docker-machine ssh devnation-2015 docker images | grep node  (5)
node                             latest              20a32f7a591c        8 weeks ago         711.5 MB
node                             0.12.4              f9ba67676f8f        9 weeks ago         711.8 MB

$ docker-machine ssh docker4dev-ee7-js docker images | grep node  (6)

$ docker-machine ssh devnation-2015 "docker save -o /tmp/node.tar node:0.12.4" (7)
$ docker-machine scp devnation-2015:/tmp/node.tar docker4dev-ee7-js:/tmp/node.tar (8)
$ docker-machine ssh docker4dev-ee7-js "docker load -i /tmp/node.tar"  (9)
$ docker-machine ssh docker4dev-ee7-js docker images | grep node       (10)
node                0.12.4              f9ba67676f8f        9 weeks ago         711.8 MB
1 display all running machines
2 default machine created when you launch the terminal shortcut provided by Toolbox
3 the source machine containing the node:0.12.4 image to copy
4 the target machine
5 display all images related to node on the source machine
6 check that there is no image related to node on the target machine for now
7 export the node image to a TAR file on the source machine
8 copy the TAR file from the source machine to the target machine via scp command
9 load the node image to the docker local registry of the target machine
10 check that the node image is now available on the target machine

See it in action: Terminal Session demo

All commands described above have been executed on my laptop and thanks to Asciinema, they have been recorded too:

Export an image from a machine and load it to another machine thought your host

An other way to do the same thing, without using the scp command, is to:

  1. export directly the TAR file to your host with the docker client connected to the source machine

  2. and then load this file to the target machine with the docker client connected to the target machine

$ docker-machine ls  (1)

NAME                           ACTIVE   DRIVER       STATE     URL                         SWARM
default                        *        virtualbox   Running   tcp://192.168.99.102:2376
devnation-2015                          virtualbox   Running   tcp://192.168.99.104:2376


$ eval $(docker-machine env devnation-2015)  (2)
$ docker images | grep alpine                (3)
alpine                           3.1                 fa60145ca189        11 weeks ago        5.033 MB
alpine                           3.2                 8697b6cc1f48        11 weeks ago        5.242 MB


$ docker save  -o /tmp/alpine-3.2.tar alpine:3.2  (4)
$ ls /tmp/alpine*
/tmp/alpine-3.2.tar

$ docker-machine create -d virtualbox docker4dev-ee7-js  (5)
$ eval $(docker-machine env docker4dev-ee7-js)           (6)
$ docker images                                        (7)
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
$ docker load -i /tmp/alpine-3.2.tar                   (8)
$ docker-images                                        (9)
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
alpine              3.2                 8697b6cc1f48        11 weeks ago        5.242 MB
1 display all machines
2 point the docker client to the source machine
3 display all images related to alpine on source machine
4 export the alpine:3.2 image from the source machine to the host
5 create a new machine with the virtualbox driver
6 point the docker client to the target machine
7 check that the target machine does not contain image
8 load the alpine:3.2 image from the host to the docker registry of the target machine
9 check that the alpine:3.2 is now available on the target machine

How do you do this? Do you use a local docker registry reachable by all machines?
I’d love to have your advices.

]]>
https://mgreau.com/posts/2015/08/26/copy-docker-images-from-one-docker-machine-to-another.htmlhttps://mgreau.com/posts/2015/08/26/copy-docker-images-from-one-docker-machine-to-another.htmlWed, 26 Aug 2015 00:00:00 GMT
<![CDATA[[Talk] AsciiDoc : Create and Publish everywhere from anywhere]]>

My slides from DevNation 2015 at Boston in June.

]]>
https://mgreau.com/posts/2012/11/09/google-cloud-endpoints.htmlhttps://mgreau.com/posts/2012/11/09/google-cloud-endpoints.htmlFri, 09 Nov 2012 00:00:00 GMT
<![CDATA[Subversion - corriger les propriétés d'une révision SVN]]>
Language : FR / Temps de lecture : 10mn
Ce post explique comment mettre à jour les propriétés SVN d’une révision donnée d’un repository. Et notamment la propriété svn:date qui, lorsqu’elle est absente sur certaines révisions, bloque les checkout via le client SVNKit (utilisé par défaut dans le plugin Subversion de Jenkins CI).

Suite à des traitements d’administration sur des référentiels Apache Subversion 1.6, les jobs Jenkins CI ne parviennent plus à récupérer les sources d’un référentiel.

Les symptômes du problème

  • les jobs Jenkins ne parviennent plus à faire des "checkout" sur un repository

  • toutes les commandes SVN fonctionnent sur ce même repository via le plugin Eclipse (Subclipse - JavaHL)

  • ces mêmes commandes fonctionnent également en direct sur le serveur SVN

  • le message d’erreur dans la console Jenkins est le suivant :

Building in workspace /.../continuous-integration/jobs/mon-projet/workspace
Checking out a fresh workspace because there's no workspace at
/.../continuous-integration/jobs/mon-projet/workspace

Cleaning local Directory .
Checking out http://serveur/svn/repo1/mon-projet/trunk
ERROR: Failed to check out http://serveur/svn/repo1/mon-projet/trunk

org.tmatesoft.svn.core.SVNException: svn: E175002: REPORT of '/svn/repo1/!svn/vcc/default': 500 Internal Server Error (http://serveur)
 at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
 ...
 Caused by: svn: E175002: REPORT of '/svn/repo1/!svn/vcc/default': 500 Internal Server Error (http://serveur)
 at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:208)
 at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:189)
 ...
 at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.getDatedRevision(DAVRepository.java:200)
 ... 30 more
FATAL: null
java.lang.NullPointerException

L’accès à SVN est réalisé avec le module DAV, après une recherche dans les logs d’Apache, le message réel du serveur SVN est le suivant :

Fri Jul 27 10:04:45 2012] [error] [client ] Could not access revision times. &nbsp;[500, #0]

Le problème se confirme lors de l’exécution des 2 commandes suivantes qui devraient affichées les logs des commit :

  • Accès aux sources via le système de fichiers

svn log --xml -v -r {2008-12-01T00:00:00Z}:{2012-<wbr></wbr>07-13T15:00:00Z} file:///svn/repos/repo1

&lt;?xml version="1.0"?&gt;
&lt;log&gt;
svn: Failed to find time on revision 38307
  • Accès aux sources via le protocole HTTP

svn log --xml -v -r {2008-12-01T00:00:00Z}:{2012-<wbr></wbr>07-13T15:00:00Z} http://serveur/svn/

svn: Server sent unexpected return value (500 Internal Server Error) in response to
REPORT request for '/svn/repo1/!svn/vcc/<wbr></wbr>default'

L’aperçu des informations sur les révisions SVN dans l’IDE Eclipse confirme également le problème :

Révisions SVN dans IDE Eclipse
Figure 1. Révisions SVN dans IDE Eclipse

Solution

La solution consiste à ajouter une date sur les révisions en question.

Pour cela, il faut commencer par autoriser la modification des propriétés sur le référentiel SVN puis par exécuter la commande svn propset sur la révision concernée.

Autoriser la modification des propriétés SVN

Par défaut Apache Subversion définit un hook (pre-revprop-change) sur chaque référentiel SVN qui bloque la modification des propriétés SVN (hormis la propriété svn:log). il faut donc désactiver temporairement ce hook (faire une copie de sauvegarde avant)

echo '#!/bin/sh'&nbsp; &gt; repos/repo1/hooks/pre-revprop-change
echo 'exit 0'&nbsp; &nbsp; &gt;&gt; repos/repo1/hooks/pre-revprop-change
chmod 755 repos/repo1/hooks/pre-revprop-change

Executer la commande SVN pour valoriser les propriétés d’une révision

Il est donc possible d'éxécuter le commande SVN pour valoriser la propriété svn:date

svn propset -r38307  --revprop svn:date '2011-09-21T19:55:44.000220Z' file:///svn/repos/repo1
property 'svn:date' set on repository revision 38307

On en profite également pour mettre à jour l’auteur du commit (svn:author) ainsi que le commentaire (svn:log) associé :

svn propset -r 38307 --revprop svn:author 'mgreau' file:///svn/repos/repo1
property 'svn:author' set on repository revision 38307
svn propset -r38307  --revprop svn:log 'Correction pb date de révision' file:///svn/repos/repo1
property 'svn:log' set on repository revision 38307

Aperçu du résultat dans l’IDE Eclipse

En rafraichissant la vue History dans Eclipse, on s’aperçoit que la révision 38307 contient désormais des informations pour la date, l’auteur et le commentaire de commit.

Révisions SVN OK dans IDE Eclipse
Figure 2. Révisions SVN OK dans IDE Eclipse

Script de mise à jour automatique

L’impression écran précédente met en valeur le fait que plusieurs révisions sont impactées par ce problème sur les propriétés SVN. Je met à disposition un script shell (svn-propset.sh) qui valorise ces propriétés SVN (date, auteur, commentaire) avec les valeurs passées en paramètres du script, pour un intervalle donné de révisions.

Exemple d’utilisation du script :

./svn-propset.sh -X -a mgreau -f 38215 -t 38321 -l "Correction pb date de révision"
 -d 2011-09-21T19:55:44.000220Z -u file:///svn/repos/repo1

Pour d’autres informations vous pouvez consulter les posts (en anglais) qui m’ont permis de résoudre ce problème:

]]>
https://mgreau.com/posts/2012/07/30/corriger-les-proprietes-des-revisions-SVN.htmlhttps://mgreau.com/posts/2012/07/30/corriger-les-proprietes-des-revisions-SVN.htmlMon, 30 Jul 2012 00:00:00 GMT