Skip to content

Commit c1b5dd1

Browse files
Merge pull request #112 from damien-carcel/jenkins
Update CI v2
2 parents 32ac90c + 3c0100d commit c1b5dd1

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
lines changed

.ci/Jenkinsfile

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!groovy
22

33
import org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateAction
4+
import groovy.transform.Field
45

56
String launchUnitTests = "yes"
67
String launchIntegrationTests = "yes"
78
String[] pimVersions = ["1.7", "2.0"]
89
String[] supportedPhpVersions = ["5.6", "7.0", "7.1"]
10+
@Field def String verboseOutputs = "yes"
11+
@Field def String dotsPerLine = "50"
12+
913
def clientConfig = [
1014
"php-http/guzzle6-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7"]],
1115
"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"
1620
imageTag = "pull-request-${env.CHANGE_ID}-build-${env.BUILD_NUMBER}"
1721
gcrImages = []
1822

19-
2023
def clients = clientConfig.keySet() as String[]
2124
def buildResult= 'SUCCESS'
2225

@@ -28,13 +31,19 @@ try {
2831
string(defaultValue: pimVersions.join(','), description: 'PIM edition the tests should run on', name: 'requiredPimVersions'),
2932
choice(choices: 'yes\nno', description: 'Run unit tests and code style checks', name: 'launchUnitTests'),
3033
choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'),
34+
choice(choices: 'no\nyes', description: 'Enable Verbose mode', name: 'verboseOutputs'),
35+
string(defaultValue: '50', description: 'Number of dots per line', name: 'dotsperline'),
3136
string(defaultValue: clients.join(','), description: 'Clients used to run integration tests (comma separated values)', name: 'clients'),
37+
choice(choices: 'no\nyes', description: 'Enable Verbose mode', name: 'verboseOutputs'),
38+
string(defaultValue: '50', description: 'Number of dots per line', name: 'dotsperline'),
3239
])
3340

3441
pimVersions = userInput['requiredPimVersions'].tokenize(',')
3542
launchUnitTests = userInput['launchUnitTests']
3643
launchIntegrationTests = userInput['launchIntegrationTests']
3744
clients = userInput['clients'].tokenize(',')
45+
verboseOutputs = userInput['verboseOutputs']
46+
dotsPerLine = userInput['dotsperline']
3847
}
3948
milestone 2
4049

@@ -168,7 +177,7 @@ void buildPim(String pimVersion, String phpVersion) {
168177
])
169178

170179
container("php") {
171-
sh "composer --ansi require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist"
180+
sh "php -d memory_limit=-1 /usr/local/bin/composer --ansi require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist"
172181
sh "cp app/config/parameters.yml.dist app/config/parameters.yml"
173182
sh "sed -i \"s#database_host: .*#database_host: 127.0.0.1#g\" app/config/parameters.yml"
174183
if ("2.0" == pimVersion) {
@@ -280,7 +289,7 @@ void runIntegrationTest(String phpVersion, String client, String psrImplem, Stri
280289
runPim17IntegrationTest(phpVersion, client, psrImplem)
281290
break
282291
case "2.0":
283-
runPim20IntegrationTest(phpVersion, client, psrImplem)
292+
runPim2IntegrationTest(phpVersion, client, psrImplem, pimVersion)
284293
break
285294
default:
286295
error("pimVersion \"${pimVersion}\" is not a valid version managed by this script..")
@@ -319,7 +328,7 @@ def runPim17IntegrationTest(String phpVersion, String client, String psrImplem)
319328
files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n')
320329

321330
for (file in files) {
322-
messages.add([
331+
def commands = [
323332
// Export "php" container id into shared file (We use ''' has we don't want groovy interpolation for $)
324333
// And clean kubernetes' docker prefix "docker://<container-id>" (Take care, pubsub uses Busybox's sed != GNU sed)
325334
[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)
338347
junit: [in: "/home/jenkins/php-api-client/", name: "junit_output.xml"],
339348
script: 'sudo php -d error_reporting="E_ALL" ./bin/phpunit -c phpunit.xml.dist '+file+' --log-junit junit_output.xml'
340349
]
341-
])
342-
}
343-
return messages
344-
})
350+
]
351+
def message = new net.sf.json.JSONObject()
352+
message.put("name",file)
353+
message.put("commands",commands)
354+
messages.add(message)
355+
}
356+
return messages
357+
}, verboseOutputs, dotsPerLine)
345358
}
346359

347360
/**
@@ -361,8 +374,7 @@ def runPim17IntegrationTest(String phpVersion, String client, String psrImplem)
361374
* @param client Name of the HTTP client package to use to run the test with
362375
* @param psrImplem Name of the PSR 7 implementation package to run the test with
363376
*/
364-
def runPim20IntegrationTest(String phpVersion, String client, String psrImplem) {
365-
String pimVersion = "2.0"
377+
def runPim2IntegrationTest(String phpVersion, String client, String psrImplem, String pimVersion) {
366378
String phpApiImageName = getApiClientGCRImageName(phpVersion, client, psrImplem)
367379
String pimImageName = getPimGCRImageName(pimVersion)
368380

@@ -373,9 +385,8 @@ def runPim20IntegrationTest(String phpVersion, String client, String psrImplem)
373385
// Find and store PHP test integration files to launch them in parallels
374386
files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/v2_0/Api -name "*Integration.php"').tokenize('\n')
375387
files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n')
376-
377388
for (file in files) {
378-
messages.add([
389+
def commands = [
379390
// Export "php" container id into shared file (We use ''' has we don't want groovy interpolation for $)
380391
// And clean kubernetes' docker prefix "docker://<container-id>" (Take care, pubsub uses Busybox's sed != GNU sed)
381392
[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)
397408
junit: [in: "/home/jenkins/php-api-client/", name: "junit_output.xml"],
398409
script: 'php -d error_reporting="E_ALL" ./bin/phpunit -c phpunit.xml.dist '+file+' --log-junit junit_output.xml'
399410
]
400-
])
411+
]
412+
def message = new net.sf.json.JSONObject()
413+
message.put("name",file)
414+
message.put("commands",commands)
415+
messages.add(message)
401416
}
402417
return messages
403-
})
418+
}, verboseOutputs, dotsPerLine)
404419
}
405420

406421
/**
@@ -433,12 +448,10 @@ def withBuildNode(String phpVersion, body) {
433448
command: 'cat',
434449
alwaysPullImage: true,
435450
envVars: [
436-
envVar(key: "COMPOSER_HOME", value: "/shared/.composer"),
437451
envVar(key: "COMPOSER_AUTH", value: "{\"github-oauth\":{\"github.com\": \"$token\"}}")],
438452
resourceRequestCpu: '500m',
439453
resourceRequestMemory: '1000Mi')
440454
], volumes: [
441-
nfsVolume(mountPath: '/shared', serverAddress: "${env.NFS_IP}", serverPath: '/exports', readOnly: false),
442455
hostPathVolume(hostPath: "/var/run/docker.sock", mountPath: "/var/run/docker.sock")
443456
]) {
444457
node("build-" + uuid) {
@@ -543,7 +556,10 @@ def withPhpApi(String phpApiImageName, String phpVersion, body) {
543556
* - (Init) php-api-client : Copy php-api-client sources to /home/jenkins/php-api-client (Used for K8s PIM's template)
544557
* - (Run) gcloud : Used to manage pubsub queues and to create PIM's Kubernetes pods (Based on template)
545558
*/
546-
def queue(String phpApiImageName, String pimImageName, String pimVersion, String phpVersion, body) {
559+
560+
def queue(String phpApiImageName, String pimImageName, String pimVersion, String phpVersion, body, verboseOutputs, dotsPerLine) {
561+
def verbosity = (verboseOutputs == "yes") ? "-v" : ""
562+
def linesize = (dotsPerLine.isNumber())? dotsPerLine :"50"
547563
clearTemplateNames()
548564
def uuid = UUID.randomUUID().toString()
549565
// Maximum pods in parallel. Default set to number of messages
@@ -564,7 +580,7 @@ def queue(String phpApiImageName, String pimImageName, String pimVersion, String
564580
}
565581

566582
podTemplate(name: "php-api-client-pubsub", label: "pubsub-" + uuid, containers: [
567-
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")])
583+
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")])
568584
], annotations: [
569585
podAnnotation(key: "pod.beta.kubernetes.io/init-containers", value:
570586
"""
@@ -614,7 +630,7 @@ def queue(String phpApiImageName, String pimImageName, String pimVersion, String
614630
try {
615631
sh "cat /home/jenkins/php-api-client/.ci/k8s/${k8s_template}"
616632
sh "kubectl apply -f /home/jenkins/php-api-client/.ci/k8s/${k8s_template}"
617-
sh "gcloud.phar job:wait ${env.NODE_NAME}-results-subscription ${size} ${env.WORKSPACE} --ansi"
633+
sh "gcloud.phar ${verbosity} job:wait --dotsperline ${linesize} ${env.NODE_NAME}-results-subscription ${size} ${env.WORKSPACE} --ansi"
618634
} finally {
619635
sh "kubectl delete job ${env.NODE_NAME}"
620636
sh "gcloud.phar pubsub:topic:delete ${env.NODE_NAME}"

.ci/k8s/pim_17_ce.dev.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ spec:
103103
resources:
104104
requests: {cpu: "300m", memory: "300Mi"}
105105
- name: pubsub
106-
image: eu.gcr.io/akeneo-ci/gcloud:1.0.17
106+
image: eu.gcr.io/akeneo-ci/gcloud:1.0
107+
imagePullPolicy: Always
107108
command: ["/bin/sh", "-c"]
108109
args:
109110
- |

.ci/k8s/pim_17_ce.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ spec:
8585
resources:
8686
requests: {cpu: "500m", memory: "750Mi"}
8787
- name: pubsub
88-
image: eu.gcr.io/akeneo-ci/gcloud:1.0.17
88+
image: eu.gcr.io/akeneo-ci/gcloud:1.0
89+
imagePullPolicy: Always
90+
8991
command: ["/bin/sh", "-c"]
9092
args:
9193
- |

.ci/k8s/pim_20_ce.dev.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ spec:
140140
timeoutSeconds: 1
141141
initialDelaySeconds: 5
142142
- name: pubsub
143-
image: eu.gcr.io/akeneo-ci/gcloud:1.0.17
143+
image: eu.gcr.io/akeneo-ci/gcloud:1.0
144+
imagePullPolicy: Always
145+
144146
command: ["/bin/sh", "-c"]
145147
args:
146148
- |

.ci/k8s/pim_20_ce.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ spec:
122122
timeoutSeconds: 1
123123
initialDelaySeconds: 5
124124
- name: pubsub
125-
image: eu.gcr.io/akeneo-ci/gcloud:1.0.17
125+
image: eu.gcr.io/akeneo-ci/gcloud:1.0
126+
imagePullPolicy: Always
126127
command: ["/bin/sh", "-c"]
127128
args:
128129
- |

0 commit comments

Comments
 (0)