From 3c0100d4dc12bb596ed81b9d55eae686547d5ad1 Mon Sep 17 00:00:00 2001 From: Damien Carcel Date: Mon, 15 Jan 2018 09:51:20 +0100 Subject: [PATCH] Update CI v2 --- .ci/Jenkinsfile | 54 ++++-- .ci/k8s/pim_17_ce.dev.yaml | 3 +- .ci/k8s/pim_17_ce.yaml | 4 +- .ci/k8s/pim_20_ce.dev.yaml | 4 +- .ci/k8s/pim_20_ce.yaml | 3 +- Jenkinsfile | 359 ------------------------------------- 6 files changed, 45 insertions(+), 382 deletions(-) delete mode 100644 Jenkinsfile diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 6ef060d3..b8eabb54 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -1,11 +1,15 @@ #!groovy import org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateAction +import groovy.transform.Field String launchUnitTests = "yes" String launchIntegrationTests = "yes" String[] pimVersions = ["1.7", "2.0"] String[] supportedPhpVersions = ["5.6", "7.0", "7.1"] +@Field def String verboseOutputs = "yes" +@Field def String dotsPerLine = "50" + def clientConfig = [ "php-http/guzzle6-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7"]], "php-http/guzzle5-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7", "zendframework/zend-diactoros", "slim/slim"]], @@ -16,7 +20,6 @@ imageRepo = "eu.gcr.io/akeneo-ci/php-api-client" imageTag = "pull-request-${env.CHANGE_ID}-build-${env.BUILD_NUMBER}" gcrImages = [] - def clients = clientConfig.keySet() as String[] def buildResult= 'SUCCESS' @@ -28,13 +31,19 @@ try { string(defaultValue: pimVersions.join(','), description: 'PIM edition the tests should run on', name: 'requiredPimVersions'), choice(choices: 'yes\nno', description: 'Run unit tests and code style checks', name: 'launchUnitTests'), choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'), + choice(choices: 'no\nyes', description: 'Enable Verbose mode', name: 'verboseOutputs'), + string(defaultValue: '50', description: 'Number of dots per line', name: 'dotsperline'), string(defaultValue: clients.join(','), description: 'Clients used to run integration tests (comma separated values)', name: 'clients'), + choice(choices: 'no\nyes', description: 'Enable Verbose mode', name: 'verboseOutputs'), + string(defaultValue: '50', description: 'Number of dots per line', name: 'dotsperline'), ]) pimVersions = userInput['requiredPimVersions'].tokenize(',') launchUnitTests = userInput['launchUnitTests'] launchIntegrationTests = userInput['launchIntegrationTests'] clients = userInput['clients'].tokenize(',') + verboseOutputs = userInput['verboseOutputs'] + dotsPerLine = userInput['dotsperline'] } milestone 2 @@ -168,7 +177,7 @@ void buildPim(String pimVersion, String phpVersion) { ]) container("php") { - sh "composer --ansi require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist" + sh "php -d memory_limit=-1 /usr/local/bin/composer --ansi require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist" sh "cp app/config/parameters.yml.dist app/config/parameters.yml" sh "sed -i \"s#database_host: .*#database_host: 127.0.0.1#g\" app/config/parameters.yml" if ("2.0" == pimVersion) { @@ -280,7 +289,7 @@ void runIntegrationTest(String phpVersion, String client, String psrImplem, Stri runPim17IntegrationTest(phpVersion, client, psrImplem) break case "2.0": - runPim20IntegrationTest(phpVersion, client, psrImplem) + runPim2IntegrationTest(phpVersion, client, psrImplem, pimVersion) break default: error("pimVersion \"${pimVersion}\" is not a valid version managed by this script..") @@ -319,7 +328,7 @@ def runPim17IntegrationTest(String phpVersion, String client, String psrImplem) files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n') for (file in files) { - messages.add([ + def commands = [ // Export "php" container id into shared file (We use ''' has we don't want groovy interpolation for $) // And clean kubernetes' docker prefix "docker://" (Take care, pubsub uses Busybox's sed != GNU sed) [container: "pubsub", script: '''sh -c "kubectl get pod \\${POD_NAME} -o jsonpath='{$.status.containerStatuses[?(@.name==\\"php\\")].containerID}' | sed 's#docker://##g' > /home/jenkins/php-container-id" '''], @@ -338,10 +347,14 @@ def runPim17IntegrationTest(String phpVersion, String client, String psrImplem) junit: [in: "/home/jenkins/php-api-client/", name: "junit_output.xml"], script: 'sudo php -d error_reporting="E_ALL" ./bin/phpunit -c phpunit.xml.dist '+file+' --log-junit junit_output.xml' ] - ]) - } - return messages - }) + ] + def message = new net.sf.json.JSONObject() + message.put("name",file) + message.put("commands",commands) + messages.add(message) + } + return messages + }, verboseOutputs, dotsPerLine) } /** @@ -361,8 +374,7 @@ def runPim17IntegrationTest(String phpVersion, String client, String psrImplem) * @param client Name of the HTTP client package to use to run the test with * @param psrImplem Name of the PSR 7 implementation package to run the test with */ -def runPim20IntegrationTest(String phpVersion, String client, String psrImplem) { - String pimVersion = "2.0" +def runPim2IntegrationTest(String phpVersion, String client, String psrImplem, String pimVersion) { String phpApiImageName = getApiClientGCRImageName(phpVersion, client, psrImplem) String pimImageName = getPimGCRImageName(pimVersion) @@ -373,9 +385,8 @@ def runPim20IntegrationTest(String phpVersion, String client, String psrImplem) // Find and store PHP test integration files to launch them in parallels files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/v2_0/Api -name "*Integration.php"').tokenize('\n') files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n') - for (file in files) { - messages.add([ + def commands = [ // Export "php" container id into shared file (We use ''' has we don't want groovy interpolation for $) // And clean kubernetes' docker prefix "docker://" (Take care, pubsub uses Busybox's sed != GNU sed) [container: "pubsub", script: '''sh -c "kubectl get pod \\${POD_NAME} -o jsonpath='{$.status.containerStatuses[?(@.name==\\"php\\")].containerID}' | sed 's#docker://##g' > /home/jenkins/php-container-id" '''], @@ -397,10 +408,14 @@ def runPim20IntegrationTest(String phpVersion, String client, String psrImplem) junit: [in: "/home/jenkins/php-api-client/", name: "junit_output.xml"], script: 'php -d error_reporting="E_ALL" ./bin/phpunit -c phpunit.xml.dist '+file+' --log-junit junit_output.xml' ] - ]) + ] + def message = new net.sf.json.JSONObject() + message.put("name",file) + message.put("commands",commands) + messages.add(message) } return messages - }) + }, verboseOutputs, dotsPerLine) } /** @@ -433,12 +448,10 @@ def withBuildNode(String phpVersion, body) { command: 'cat', alwaysPullImage: true, envVars: [ - envVar(key: "COMPOSER_HOME", value: "/shared/.composer"), envVar(key: "COMPOSER_AUTH", value: "{\"github-oauth\":{\"github.com\": \"$token\"}}")], resourceRequestCpu: '500m', resourceRequestMemory: '1000Mi') ], volumes: [ - nfsVolume(mountPath: '/shared', serverAddress: "${env.NFS_IP}", serverPath: '/exports', readOnly: false), hostPathVolume(hostPath: "/var/run/docker.sock", mountPath: "/var/run/docker.sock") ]) { node("build-" + uuid) { @@ -543,7 +556,10 @@ def withPhpApi(String phpApiImageName, String phpVersion, body) { * - (Init) php-api-client : Copy php-api-client sources to /home/jenkins/php-api-client (Used for K8s PIM's template) * - (Run) gcloud : Used to manage pubsub queues and to create PIM's Kubernetes pods (Based on template) */ -def queue(String phpApiImageName, String pimImageName, String pimVersion, String phpVersion, body) { + +def queue(String phpApiImageName, String pimImageName, String pimVersion, String phpVersion, body, verboseOutputs, dotsPerLine) { + def verbosity = (verboseOutputs == "yes") ? "-v" : "" + def linesize = (dotsPerLine.isNumber())? dotsPerLine :"50" clearTemplateNames() def uuid = UUID.randomUUID().toString() // Maximum pods in parallel. Default set to number of messages @@ -564,7 +580,7 @@ def queue(String phpApiImageName, String pimImageName, String pimVersion, String } podTemplate(name: "php-api-client-pubsub", label: "pubsub-" + uuid, containers: [ - containerTemplate(name: "gcloud", ttyEnabled: true, command: 'cat', image: "eu.gcr.io/akeneo-ci/gcloud:1.0.17", resourceRequestCpu: '100m', resourceRequestMemory: '200Mi', envVars: [envVar(key: "PUBSUB_PROJECT_ID", value: "akeneo-ci")]) + containerTemplate(name: "gcloud", ttyEnabled: true, command: 'cat', image: "eu.gcr.io/akeneo-ci/gcloud:1.0", alwaysPullImage: true, resourceRequestCpu: '100m', resourceRequestMemory: '200Mi', envVars: [envVar(key: "PUBSUB_PROJECT_ID", value: "akeneo-ci")]) ], annotations: [ podAnnotation(key: "pod.beta.kubernetes.io/init-containers", value: """ @@ -614,7 +630,7 @@ def queue(String phpApiImageName, String pimImageName, String pimVersion, String try { sh "cat /home/jenkins/php-api-client/.ci/k8s/${k8s_template}" sh "kubectl apply -f /home/jenkins/php-api-client/.ci/k8s/${k8s_template}" - sh "gcloud.phar job:wait ${env.NODE_NAME}-results-subscription ${size} ${env.WORKSPACE} --ansi" + sh "gcloud.phar ${verbosity} job:wait --dotsperline ${linesize} ${env.NODE_NAME}-results-subscription ${size} ${env.WORKSPACE} --ansi" } finally { sh "kubectl delete job ${env.NODE_NAME}" sh "gcloud.phar pubsub:topic:delete ${env.NODE_NAME}" diff --git a/.ci/k8s/pim_17_ce.dev.yaml b/.ci/k8s/pim_17_ce.dev.yaml index ad756347..fefd63d7 100644 --- a/.ci/k8s/pim_17_ce.dev.yaml +++ b/.ci/k8s/pim_17_ce.dev.yaml @@ -103,7 +103,8 @@ spec: resources: requests: {cpu: "300m", memory: "300Mi"} - name: pubsub - image: eu.gcr.io/akeneo-ci/gcloud:1.0.17 + image: eu.gcr.io/akeneo-ci/gcloud:1.0 + imagePullPolicy: Always command: ["/bin/sh", "-c"] args: - | diff --git a/.ci/k8s/pim_17_ce.yaml b/.ci/k8s/pim_17_ce.yaml index 61dd6b89..b7580f44 100644 --- a/.ci/k8s/pim_17_ce.yaml +++ b/.ci/k8s/pim_17_ce.yaml @@ -85,7 +85,9 @@ spec: resources: requests: {cpu: "500m", memory: "750Mi"} - name: pubsub - image: eu.gcr.io/akeneo-ci/gcloud:1.0.17 + image: eu.gcr.io/akeneo-ci/gcloud:1.0 + imagePullPolicy: Always + command: ["/bin/sh", "-c"] args: - | diff --git a/.ci/k8s/pim_20_ce.dev.yaml b/.ci/k8s/pim_20_ce.dev.yaml index daa20ab2..25252e84 100644 --- a/.ci/k8s/pim_20_ce.dev.yaml +++ b/.ci/k8s/pim_20_ce.dev.yaml @@ -140,7 +140,9 @@ spec: timeoutSeconds: 1 initialDelaySeconds: 5 - name: pubsub - image: eu.gcr.io/akeneo-ci/gcloud:1.0.17 + image: eu.gcr.io/akeneo-ci/gcloud:1.0 + imagePullPolicy: Always + command: ["/bin/sh", "-c"] args: - | diff --git a/.ci/k8s/pim_20_ce.yaml b/.ci/k8s/pim_20_ce.yaml index 87c6545e..d5ec3a9d 100644 --- a/.ci/k8s/pim_20_ce.yaml +++ b/.ci/k8s/pim_20_ce.yaml @@ -122,7 +122,8 @@ spec: timeoutSeconds: 1 initialDelaySeconds: 5 - name: pubsub - image: eu.gcr.io/akeneo-ci/gcloud:1.0.17 + image: eu.gcr.io/akeneo-ci/gcloud:1.0 + imagePullPolicy: Always command: ["/bin/sh", "-c"] args: - | diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 17c5761e..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1,359 +0,0 @@ -#!groovy - -String launchUnitTests = "yes" -String launchIntegrationTests = "yes" -def pimVersions = ["1.7", "2.0"] -def supportedPhpVersions = ["5.6", "7.0", "7.1"] - -def clientConfig = [ - "php-http/guzzle6-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7"]], - "php-http/guzzle5-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7", "zendframework/zend-diactoros", "slim/slim"]], - "php-http/curl-client": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7", "zendframework/zend-diactoros", "slim/slim"]] -] - -def clients = clientConfig.keySet() as String[] - -stage("Checkout") { - milestone 1 - if (env.BRANCH_NAME =~ /^PR-/) { - userInput = input(message: 'Launch tests?', parameters: [ - string(defaultValue: pimVersions.join(','), description: 'PIM edition the tests should run on', name: 'requiredPimVersions'), - choice(choices: 'yes\nno', description: 'Run unit tests and code style checks', name: 'launchUnitTests'), - choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'), - string(defaultValue: clients.join(','), description: 'Clients used to run integration tests (comma separated values)', name: 'clients'), - ]) - - pimVersions = userInput['requiredPimVersions'].tokenize(',') - launchUnitTests = userInput['launchUnitTests'] - launchIntegrationTests = userInput['launchIntegrationTests'] - clients = userInput['clients'].tokenize(',') - } - milestone 2 - - node('docker') { - deleteDir() - checkout scm - stash "php-api-client" - - for (pimVersion in pimVersions) { - deleteDir() - checkout([$class: 'GitSCM', - branches: [[name: pimVersion]], - userRemoteConfigs: [[credentialsId: 'github-credentials', url: 'https://github.com/akeneo/pim-community-dev.git']] - ]) - stash "pim_community_dev_${pimVersion}" - } - } - - checkouts = [:] - - if (launchUnitTests.equals("yes")) { - String currentClient = "php-http/guzzle6-adapter" - String currentPsrImplem = "guzzlehttp/psr7" - - for (phpVersion in clientConfig.get(currentClient).get("phpVersion")) { - String currentPhpVersion = phpVersion - - checkouts["${currentClient}-${currentPsrImplem}-${currentPhpVersion}"] = {runCheckoutClient(currentPhpVersion, currentClient, currentPsrImplem)} - } - } - - if (launchIntegrationTests.equals("yes")) { - for (pimVersion in pimVersions) { - String currentPimVersion = pimVersion - - if ("2.0" == currentPimVersion) { - checkouts["pim_community_dev_${currentPimVersion}"] = {runCheckoutPim18(currentPimVersion)} - } - - if ("1.7" == currentPimVersion) { - checkouts["pim_community_dev_${currentPimVersion}"] = {runCheckoutPim17(currentPimVersion)} - } - } - - for (client in clients) { - for (phpVersion in clientConfig.get(client).get("phpVersion")) { - for (psrImplem in clientConfig.get(client).get("psrImplem")) { - String currentClient = client - String currentPhpVersion = phpVersion - String currentPsrImplem = psrImplem - - checkouts["${currentClient}-${currentPsrImplem}-${currentPhpVersion}"] = {runCheckoutClient(currentPhpVersion, currentClient, currentPsrImplem)} - } - } - } - } - - parallel checkouts -} - -if (launchUnitTests.equals("yes")) { - stage("Unit tests and Code style") { - def tasks = [:] - - String currentClient = "php-http/guzzle6-adapter" - String currentPsrImplem = "guzzlehttp/psr7" - - tasks["php-cs-fixer"] = {runPhpCsFixerTest("7.1", currentClient, currentPsrImplem)} - - for (phpVersion in clientConfig.get(currentClient).get("phpVersion")) { - String currentPhpVersion = phpVersion - - tasks["phpspec-${phpVersion}"] = {runPhpSpecTest(currentPhpVersion, currentClient, currentPsrImplem)} - } - - parallel tasks - } -} - -if (launchIntegrationTests.equals("yes")) { - for (pimVersion in pimVersions) { - String currentPimVersion = pimVersion - stage("Integration tests ${currentPimVersion}") { - def tasks = [:] - - for (client in clients) { - for (phpVersion in clientConfig.get(client).get("phpVersion")) { - for (psrImplem in clientConfig.get(client).get("psrImplem")) { - String currentClient = client - String currentPsrImplem = psrImplem - String currentPhpVersion = phpVersion - - tasks["phpunit-${currentClient}-${currentPsrImplem}-${currentPhpVersion}"] = {runIntegrationTest(currentPhpVersion, currentClient, currentPsrImplem, currentPimVersion)} - } - } - } - - parallel tasks - } - } -} - -/** - * Run checkout of the PIM for a given PHP version and a PIM version. - * - * @param pimVersion PIM version to checkout - */ -void runCheckoutPim17(String pimVersion) { - node('docker') { - deleteDir() - try { - docker.image("akeneo/php:5.6").inside("-v /home/akeneo/.composer:/home/docker/.composer") { - unstash "pim_community_dev_${pimVersion}" - - sh "composer require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist" - sh "cp app/config/parameters.yml.dist app/config/parameters.yml" - sh "sed -i 's/database_host: localhost/database_host: mysql/' app/config/parameters.yml" - sh "sed -i \"s@installer_data: .*@installer_data: '%kernel.root_dir%/../vendor/akeneo/catalogs/${pimVersion}/community/api/fixtures'@\" app/config/pim_parameters.yml" - - stash "pim_community_dev_${pimVersion}" - } - } finally { - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - sh "docker volume rm \$(docker volume ls -q) || true" - - deleteDir() - } - } -} - -/** - * Run checkout of the PIM for a given PHP version and a PIM version. - * - * @param pimVersion PIM version to checkout - */ -void runCheckoutPim18(String pimVersion) { - node('docker') { - deleteDir() - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - - try { - docker.image("akeneo/php:7.1").inside("-v /home/akeneo/.composer:/home/docker/.composer -e COMPOSER_HOME=/home/docker/.composer") { - unstash "pim_community_dev_${pimVersion}" - - sh "composer require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist" - sh "cp app/config/parameters_test.yml.dist app/config/parameters_test.yml" - sh "sed -i \"s#database_host: .*#database_host: mysql#g\" app/config/parameters.yml" - sh "sed -i \"s#index_hosts: .*#index_hosts: 'elasticsearch: 9200'#g\" app/config/parameters.yml" - sh "sed -i \"s@installer_data: .*@installer_data: '%kernel.root_dir%/../vendor/akeneo/catalogs/${pimVersion}/community/api/fixtures'@\" app/config/pim_parameters.yml" - - stash "pim_community_dev_${pimVersion}" - } - } finally { - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - sh "docker volume rm \$(docker volume ls -q) || true" - - deleteDir() - } - } -} - -/** - * Run checkout of the PHP client, for a given PHP version, HTTP client and PSR7 implementation. - * - * @param phpVersion PHP version to use to run the composer - * @param client name of the HTTP client package to use to checkout - * @param psrImplem name of the PSR 7 implementation package to checkout - */ -void runCheckoutClient(String phpVersion, String client, String psrImplem) { - node('docker') { - deleteDir() - try { - docker.image("akeneo/php:${phpVersion}").inside("-v /home/akeneo/.composer:/.composer -e COMPOSER_HOME=/.composer") { - unstash "php-api-client" - - sh "composer require ${client} ${psrImplem}" - sh "composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist" - - sh "cp tests/etc/parameters.yml.dist tests/etc/parameters.yml" - - stash "php-api-client_${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_") - } - } finally { - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - sh "docker volume rm \$(docker volume ls -q) || true" - - deleteDir() - } - } -} - -/** - * Run php cs fixer, for a given PHP version, HTTP client and PSR7 implementation. - * - * @param phpVersion PHP version to run the test with - * @param client name of the HTTP client package to run the test with - * @param psrImplem name of the PSR 7 implementation package to run the test with - */ -void runPhpCsFixerTest(String phpVersion, String client, String psrImplem) { - node('docker') { - deleteDir() - try { - docker.image("akeneo/php:${phpVersion}").inside() { - unstash "php-api-client_${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_") - - sh "mkdir -p build/logs/" - - sh "./bin/php-cs-fixer fix --diff --dry-run --format=junit --config=.php_cs.php > build/logs/phpcs.xml" - } - } finally { - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - sh "docker volume rm \$(docker volume ls -q) || true" - - sh "find build/logs/ -name \"*.xml\" | xargs sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-cs-fixer] /\"" - junit "build/logs/*.xml" - - deleteDir() - } - } -} - -/** - * Run PHPspec tests, for a given PHP version, HTTP client and PSR7 implementation. - * - * @param phpVersion PHP version to run the test with - * @param client name of the HTTP client package to use to run the test with - * @param psrImplem name of the PSR 7 implementation package to run the test with - */ -void runPhpSpecTest(String phpVersion, String client, String psrImplem) { - node('docker') { - deleteDir() - try { - docker.image("akeneo/php:${phpVersion}").inside() { - unstash "php-api-client_${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_") - - sh "mkdir -p build/logs/" - - sh "./bin/phpspec run --no-interaction --format=junit > build/logs/phpspec.xml" - } - } finally { - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - sh "docker volume rm \$(docker volume ls -q) || true" - - sh "find build/logs/ -name \"*.xml\" | xargs sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${phpVersion}] /\"" - junit "build/logs/*.xml" - - deleteDir() - } - } -} - -/** - * Run integration tests of the PHP client, for a given PHP version, HTTP client, PSR7 implementation and a PIM version. - * First, it starts the PIM. The configuration of the PIM (composer, parameters) is already done in the checkout step. - * Then, it launches the PHPUnit tests. - * - * Do note that PHPUnit resets the PIM database between each test and generates the API client id/secret, - * thanks to "docker exec" commands inside the PHPUnit process. - * In order to do that, the docker socket and docker bin are exposed as volumes to the PHPUnit container. - * - * @param phpVersion PHP version to run the test with - * @param client name of the HTTP client package to use to run the test with - * @param psrImplem name of the PSR 7 implementation package to run the test with - * @param pimVersion PIM version to run the test with - */ -void runIntegrationTest(String phpVersion, String client, String psrImplem, String pimVersion) { - node('docker') { - deleteDir() - try { - dir('pim') { - unstash "pim_community_dev_${pimVersion}" - - if ("2.0" == pimVersion) { - sh "docker pull akeneo/fpm:php-7.1 || true" - - sh "docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim --tmpfs=/var/lib/mysql/:rw,noexec,nosuid,size=400m --tmpfs=/tmp/:rw,noexec,nosuid,size=200m -d mysql:5.7" - sh "docker run --name elasticsearch -e ES_JAVA_OPTS=\"-Xms256m -Xmx256m\" -d elasticsearch:5" - sh "docker run --user docker --name akeneo-pim --link mysql:mysql --link elasticsearch:elasticsearch -v \$(pwd):/srv/pim -w /srv/pim -d akeneo/fpm:php-7.1" - sh "docker run --name httpd --link akeneo-pim:fpm -v \$(pwd):/srv/pim -v \$(pwd)/docker/httpd.conf:/usr/local/apache2/conf/httpd.conf -v \$(pwd)/docker/akeneo.conf:/usr/local/apache2/conf/vhost.conf -w /srv/pim -d httpd:2.4" - - // Wait for elasticsearch container ready - sh "sleep 20" - sh "docker exec akeneo-pim bin/console pim:install -e prod" - } - - if ("1.7" == pimVersion) { - sh "docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim --tmpfs=/var/lib/mysql/:rw,noexec,nosuid,size=400m --tmpfs=/tmp/:rw,noexec,nosuid,size=200m -d mysql:5.5" - sh "docker run --user docker --name akeneo-pim --link mysql:mysql -v \$(pwd):/srv/pim -v \$(pwd)/docker/akeneo.conf:/etc/apache2/sites-available/000-default.conf:ro -w /srv/pim -d akeneo/apache-php:php-5.6" - - // Wait for elasticsearch container ready - sh "sleep 20" - sh "docker exec akeneo-pim app/console pim:install -e prod" - } - } - - unstash "php-api-client_${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_") - sh "mkdir -p build/logs/" - - if ("2.0" == pimVersion) { - docker.image("akeneo/php:${phpVersion}").inside("--link akeneo-pim:akeneo-pim --link httpd:httpd -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -w /home/docker/client --privileged") { - sh "sed -i \"s#base_uri: .*#base_uri: 'http://httpd'#g\" tests/etc/parameters.yml" - sh "sed -i \"s#bin_path: .*#bin_path: bin#g\" tests/etc/parameters.yml" - sh "sed -i \"s#version: .*#version: #g\" tests/etc/parameters.yml" - sh "sudo ./bin/phpunit -c phpunit.xml.dist --testsuite PHP_Client_Unit_Test_2_0 --log-junit build/logs/phpunit_integration.xml" - } - } - - if ("1.7" == pimVersion) { - docker.image("akeneo/php:${phpVersion}").inside("--link akeneo-pim:akeneo-pim -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -w /home/docker/client") { - sh "sudo ./bin/phpunit -c phpunit.xml.dist --testsuite PHP_Client_Unit_Test_1_7 --log-junit build/logs/phpunit_integration.xml" - } - } - } finally { - sh "docker stop \$(docker ps -a -q) || true" - sh "docker rm \$(docker ps -a -q) || true" - sh "docker volume rm \$(docker volume ls -q) || true" - - sh "find build/logs/ -name \"*.xml\" | xargs sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${phpVersion}-${client.replaceAll('/', '-')}-${psrImplem.replaceAll('/', '-')}] /\"" - junit "build/logs/*.xml" - - deleteDir() - } - } -}