Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maven tool support to DockerCompose #180

Open
wants to merge 2 commits into
base: release/2.1.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ venv
# vscode
.vscode/
local-storage.json
jcasc-schema.json
25 changes: 25 additions & 0 deletions src/eu/indigo/Maven.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package eu.indigo

import eu.indigo.JenkinsDefinitions

/**
* Definitions for Maven automation project
* @see: https://www.baeldung.com/maven-goals-phases
*/
@groovy.transform.InheritConstructors
class Maven extends JenkinsDefinitions implements Serializable {

private static final long serialVersionUID = 0L

/**
* Run Maven environment
*
* @param args.mavenFile Maven configuration file to override the default pom.xml
* @param args.options List of options for mvn command
* @param goals List of phases and/or goals separated by spaces to run with Maven
*/
def runEnv(Map args, String goals) {
return "maven -f \"${args.mavenFile}\" $options $goals"
}

}
1 change: 1 addition & 0 deletions src/eu/indigo/compose/ComposeFactory.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ComposeFactory implements Serializable {

def static factory
def static tox
def static maven
def static processStages(projectConfig) { return factory.processStages(projectConfig) }

}
9 changes: 8 additions & 1 deletion src/eu/indigo/compose/ComposeFactoryBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ComposeFactoryBuilder implements Serializable {

def factory
def tox
def maven

def setFactory(factory) {
this.factory = factory
Expand All @@ -21,9 +22,15 @@ class ComposeFactoryBuilder implements Serializable {
return this
}

def setMaven(maven) {
this.maven = maven
return this
}

ComposeFactory build() {
new ComposeFactory(factory: this.factory,
tox: this.tox)
tox: this.tox,
maven: this.maven)
}

}
28 changes: 28 additions & 0 deletions src/eu/indigo/compose/DockerCompose.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ class DockerCompose extends JenkinsDefinitions implements Serializable {
steps.sh "docker-compose $cmd"
}

/**
* Run docker compose exec
*
* @param service Service name
* @param goals Test environment to run with maven
* @param maven Maven object with implementations for python virtenv orquestration
* @param args.composeFile configuration file to override the default docker-compose.yml
* @param args.options Options to be passed to mvn command
* @param args.mavenFile Maven configuration file to override the default pom.xml
* @param args.workdir Path to workdir directory for this command
* @see https://docs.docker.com/compose/reference/exec/
*/
def composeMavenRun(Map args, String service, String goals, Maven maven) {
if (_DEBUG_) { steps.echo "** composeMavenRun() **" }

String credsVars = getCredsVars()
if (_DEBUG_) { steps.echo "service: ${service}\noptions: ${args.options}\ngoals: ${goals}\nmavenFile: " + escapeWhitespace(args.mavenFile) + "\ncredsVars: $credsVars" }
if (_DEBUG_) { steps.echo "maven command: " + maven.runEnv(goals, args.options, mavenFile: escapeWhitespace(args.mavenFile)) }
String cmd = parseParam(_f, escapeWhitespace(args.composeFile)) + ' ' + parseParam(_w, escapeWhitespace(args.workdir)) + ' exec -T ' +
" $credsVars $service " + maven.runEnv(goal, args.options, mavenFile: escapeWhitespace(args.mavenFile))
steps.sh "docker-compose $cmd"
}

/**
* Run tools and command within the containers
*
Expand All @@ -291,6 +314,11 @@ class DockerCompose extends JenkinsDefinitions implements Serializable {
toxFile: stageMap.tox.tox_file, workdir: workspace)
}
}
if (stageMap.maven) {
composeMavenRun(stageMap.container, stageMap.maven.goals, projectConfig.nodeAgent.maven,
composeFile: projectConfig.config.deploy_template, options: stageMap.maven.options,
mavenFile: stageMap.maven.maven_file, workdir: workspace)
}
if (stageMap.commands) {
stageMap.commands.each { command ->
composeExec(stageMap.container, command,
Expand Down
11 changes: 10 additions & 1 deletion src/eu/indigo/compose/parser/ConfigParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ConfigParser extends JenkinsDefinitions implements Serializable {
'ssh_user_private_key'
]
List supportedBuildTools = [
'tox'
'tox',
'maven'
]
Map defaultValues = [
config: [
Expand Down Expand Up @@ -75,6 +76,14 @@ class ConfigParser extends JenkinsDefinitions implements Serializable {
tox_file: 'tox.ini',
testenv: []
]
],
maven: [
container: 'maven',
maven: [
maven_file: 'pom.xml',
options: '',
goals: ''
]
]
]

Expand Down
1 change: 1 addition & 0 deletions vars/pipelineConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def call(Map configs) {
projectConfig.nodeAgent = new ComposeFactoryBuilder()
.setFactory(new DockerCompose(this))
.setTox(new Tox(this))
.setMaven(new Maven(this))
.build()
break
default:
Expand Down