Generator-jhipster: Jenkins pipeline and protractor

Created on 16 Dec 2016  路  4Comments  路  Source: jhipster/generator-jhipster

This is to continue the discussion started in #4600 about Jenkins and protractor.

I tested https://github.com/mark-adams/docker-chromium-xvfb/tree/master/images/base to run chrome in docker and it works well.
I guess we can adapt to run firefox instead since that's what we set in the protractor conf file.
Now the difficulty with protractor is that it needs to start the application and you probably need other elements to run (Database, Elastic Search, JHipster Registry, etc...)
So I see several possibilities:

  1. Don't run the build in a docker and ask the user to install the elements by himself. Not very nice...
  2. Run the elements from Jenkins in docker containers and do the necessary port/host mapping (I don't know if it's easy without docker-compose)
  3. Run the elements from the jhipster-ci-stack container (so you could have a dockerized Jenkins that launches a jhipster-ci-stack docker that launches a mysql docker. Looks like too much docker in docker in docker, but maybe that can work...). For comparison, Travis uses the docker-compose file in src/main/docker to launch the elements.
  4. Put all the possible combinations of docker images on the docker hub (eg. jhipster-ci-stack-psql-es). Probably too much...
  5. Eventually, we could generate a Dockerfile that is used by the Jenkinsfile to build himself the docker build container (see https://jenkins.io/blog/2016/08/08/docker-pipeline-environments/). I find this quite elegant.

Opinion ?

cc @mraible

Most helpful comment

So it appears the best solution I found is actually (2) using docker container linking to give access to the containers. This is kinda like what is done in src/main/docker/app.yml but without docker-compose.
You can try the following pipeline script for instance

node {
    stage('checkout') {
        git url: 'https://github.com/jhipster/jhipster-sample-app.git'
    }

    def mysql = docker.image('mysql:5.7.13').run('-e MYSQL_USER=root -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=mysql')

    docker.image('openjdk:8').inside("--link ${mysql.id}:mysql -u root -e MAVEN_OPTS=\"-Duser.home=./\"") {
        stage('check tools') {
            sh "java -version"
        }

        stage('clean') {
            sh "./mvnw clean"
        }

        stage('run') {
            sh "echo '{ \"allow_root\": true }' > /root/.bowerrc"
            sh "export SPRING_DATASOURCE_URL=\"jdbc:mysql://mysql:3306/mysql?useUnicode=true&characterEncoding=utf8&useSSL=false\" && ./mvnw -Pprod"
        }
    }
}

Note: this script is not usable as-is as it will block at the end. A full script would need to run the server in background, wait that it is started, launch the protractor tests and call mysql.stop() to remove the mysql container.

As this uses docker, it is dependent on #4600 being merged.
Also as there is quite a bit of work, are there people interested in having Protractor tests running in Jenkins (please thumb up if interested) ?

All 4 comments

~On second thought 2 and 3 would cause issues when multiple builds run in parallel.~

So it appears the best solution I found is actually (2) using docker container linking to give access to the containers. This is kinda like what is done in src/main/docker/app.yml but without docker-compose.
You can try the following pipeline script for instance

node {
    stage('checkout') {
        git url: 'https://github.com/jhipster/jhipster-sample-app.git'
    }

    def mysql = docker.image('mysql:5.7.13').run('-e MYSQL_USER=root -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=mysql')

    docker.image('openjdk:8').inside("--link ${mysql.id}:mysql -u root -e MAVEN_OPTS=\"-Duser.home=./\"") {
        stage('check tools') {
            sh "java -version"
        }

        stage('clean') {
            sh "./mvnw clean"
        }

        stage('run') {
            sh "echo '{ \"allow_root\": true }' > /root/.bowerrc"
            sh "export SPRING_DATASOURCE_URL=\"jdbc:mysql://mysql:3306/mysql?useUnicode=true&characterEncoding=utf8&useSSL=false\" && ./mvnw -Pprod"
        }
    }
}

Note: this script is not usable as-is as it will block at the end. A full script would need to run the server in background, wait that it is started, launch the protractor tests and call mysql.stop() to remove the mysql container.

As this uses docker, it is dependent on #4600 being merged.
Also as there is quite a bit of work, are there people interested in having Protractor tests running in Jenkins (please thumb up if interested) ?

Closing this as #4903 is merged

Yes even though running the protractor tests is not part of the PR. But this will be a lot of work so no need to keep this issue opened.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcelinobadin picture marcelinobadin  路  3Comments

sdoxsee picture sdoxsee  路  4Comments

frantzynicolas picture frantzynicolas  路  3Comments

chegola picture chegola  路  4Comments

edvjacek picture edvjacek  路  3Comments