Skip to content

Commit

Permalink
Merge pull request #7 from kaidohallik/separate-docker-question
Browse files Browse the repository at this point in the history
Separate Docker question for Jenkins pipeline and Gitlab CI
  • Loading branch information
pascalgrimaud authored Feb 19, 2017
2 parents a9896b7 + e221407 commit 72965e6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
6 changes: 3 additions & 3 deletions generators/ci-cd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ module.exports = PipelineGenerator.extend({
insight.trackWithEvent('generator', 'ci-cd');
},
setTemplateVariables: function() {
if (this.abort || this.integrations === undefined) return;
this.gitLabIndent = this.integrations.includes('gitlab') ? ' ' : '';
this.indent = this.integrations.includes('docker') ? ' ' : '';
if (this.abort || this.jenkinsIntegrations === undefined) return;
this.gitLabIndent = this.jenkinsIntegrations.includes('gitlab') ? ' ' : '';
this.indent = this.jenkinsIntegrations.includes('docker') ? ' ' : '';
this.indent += this.gitLabIndent;
}
},
Expand Down
53 changes: 38 additions & 15 deletions generators/ci-cd/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,67 @@ function askPipelines() {
function askIntegrations() {
if (this.abort || this.pipelines.length === 0) return;
var done = this.async();
var choices = [];
if (this.pipelines.includes('jenkins') || this.pipelines.includes('gitlab')) {
choices.push({name: '[Docker] Perform the build in a docker container', value: 'docker'});
}
var herokuChoices = [];
if (this.pipelines.includes('jenkins')) {
choices.push({name: '[Sonar] Analyze code with Sonar', value: 'sonar'});
choices.push({name: '[Gitlab] Send build status to Gitlab', value: 'gitlab'});
herokuChoices.push({name: 'In Jenkins pipeline', value: 'jenkins'});
}
if (this.pipelines.includes('gitlab')) {
herokuChoices.push({name: 'In Gitlab CI', value: 'gitlab'});
}
if (this.herokuAppName) {
choices.push({name: '[Heroku] Deploy to heroku', value: 'heroku'});
if (this.pipelines.includes('circle')) {
herokuChoices.push({name: 'In Circle CI', value: 'circle'});
}

var prompts = [
{
when: this.pipelines.includes('jenkins'),
type: 'checkbox',
name: 'integrations',
message: 'What tasks/integrations do you want to include ?',
name: 'jenkinsIntegrations',
message: 'Jenkins pipeline: what tasks/integrations do you want to include?',
default: [],
choices: choices
choices: [
{name: 'Perform the build in a docker container', value: 'docker'},
{name: 'Analyze code with Sonar', value: 'sonar'},
{name: 'Send build status to Gitlab', value: 'gitlab'}
]
},
{
when: response => this.pipelines.includes('jenkins') && response.integrations.includes('sonar'),
when: response => this.pipelines.includes('jenkins') && response.jenkinsIntegrations.includes('sonar'),
type: 'input',
name: 'jenkinsSonarName',
message: 'What is the name of the Sonar server ?',
default: 'Sonar'
},
{
when: response => response.integrations.includes('heroku'),
when: this.pipelines.includes('gitlab'),
type: 'confirm',
name: 'gitlabUseDocker',
message: 'In Gitlab CI perform the build in a docker container (hint: gitlab.com uses docker container)?',
default: false
},
{
when: (this.pipelines.includes('jenkins') || this.pipelines.includes('gitlab') || this.pipelines.includes('circle')) && this.herokuAppName,
type: 'checkbox',
name: 'heroku',
message: 'Deploy to heroku?',
default: [],
choices: herokuChoices
},
{
when: function (response) {
return response.heroku !== undefined && (response.heroku.includes('jenkins') || response.heroku.includes('gitlab') || response.heroku.includes('circle'));
},
type: 'input',
name: 'herokuApiKey',
message: 'What is the Heroku API Key ?',
message: 'What is the Heroku API Key?',
default: ''
},
];
this.prompt(prompts).then(props => {
this.integrations = props.integrations;
this.jenkinsIntegrations = props.jenkinsIntegrations;
this.jenkinsSonarName = props.jenkinsSonarName;
this.gitlabUseDocker = props.gitlabUseDocker;
this.heroku = props.heroku;
this.herokuApiKey = props.herokuApiKey;
done();
});
Expand Down
8 changes: 4 additions & 4 deletions generators/ci-cd/templates/_.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%_ if (integrations.includes('docker')) { _%>
<%_ if (gitlabUseDocker) { _%>
image: openjdk:8
<%_ } _%>

Expand All @@ -21,7 +21,7 @@ stages:
- build
- test
- package
<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('gitlab')) { _%>
- deploy
<%_ } _%>

Expand Down Expand Up @@ -93,7 +93,7 @@ gradle-repackage:
artifacts:
paths:
- build/libs/*.war
<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('gitlab')) { _%>
gradle-deploy:
stage: deploy
script:
Expand Down Expand Up @@ -165,7 +165,7 @@ gatling-test:
paths:
- target/gatling/*
<%_ } _%>
<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('gitlab')) { _%>
maven-deploy:
stage: deploy
script:
Expand Down
14 changes: 7 additions & 7 deletions generators/ci-cd/templates/_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ node {
checkout scm
}

<%_ if (integrations.includes('gitlab')) { _%>
<%_ if (jenkinsIntegrations.includes('gitlab')) { _%>
gitlabCommitStatus('build') {
<%_ } _%>
<%_ if (integrations.includes('docker')) { _%>
<%_ if (jenkinsIntegrations.includes('docker')) { _%>
<%= gitLabIndent %> docker.image('openjdk:8').inside('-u root<% if (buildTool === 'maven') { %> -e MAVEN_OPTS="-Duser.home=./"<% } else if (buildTool === 'gradle') { %> -e GRADLE_USER_HOME=.gradle<% } %>') {
<%_ } _%>
<%= indent %> stage('check java') {
Expand Down Expand Up @@ -72,7 +72,7 @@ node {
<%= indent %> }

<%_ } _%>
<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('jenkins')) { _%>
<%= indent %> stage('package and deploy') {
<%= indent %> sh "HEROKU_API_KEY=\"<%= herokuApiKey %>\" ./mvnw com.heroku.sdk:heroku-maven-plugin:1.1.1:deploy-war -DskipTests -Pprod -Dheroku.appName=<%= herokuAppName %>"
<%_ } else { _%>
Expand Down Expand Up @@ -135,14 +135,14 @@ node {
<%= indent %> archiveArtifacts artifacts: '**/build/libs/*.war', fingerprint: true
<%= indent %> }

<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('jenkins')) { _%>
<%= indent %> stage('deployment') {
<%= indent %> sh "HEROKU_API_KEY=\"<%= herokuApiKey %>\" ./gradlew deployHeroku --no-daemon"
<%= indent %> }

<%_ } _%>
<%_ } _%>
<%_ if (integrations.includes('sonar')) { _%>
<%_ if (jenkinsIntegrations.includes('sonar')) { _%>
<%= indent %> stage('quality analysis') {
<%= indent %> withSonarQubeEnv('<%= jenkinsSonarName %>') {
<%_ if (buildTool === 'maven') { _%>
Expand All @@ -153,10 +153,10 @@ node {
<%= indent %> }
<%= indent %> }
<%_ } _%>
<%_ if (integrations.includes('docker')) { _%>
<%_ if (jenkinsIntegrations.includes('docker')) { _%>
<%= gitLabIndent %> }
<%_ } _%>
<%_ if (integrations.includes('gitlab')) { _%>
<%_ if (jenkinsIntegrations.includes('gitlab')) { _%>
}
<%_ } _%>
}
4 changes: 2 additions & 2 deletions generators/ci-cd/templates/_circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ test:
<%_ } _%>
<%_ } _%>
<%_ if (buildTool === 'maven') { _%>
<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('circle')) { _%>
- HEROKU_API_KEY=\"<%= herokuApiKey %>\" ./mvnw com.heroku.sdk:heroku-maven-plugin:1.1.1:deploy-war -DskipTests -Pprod -Dheroku.appName=<%= herokuAppName %>
<%_ } else { _%>
- ./mvnw package -Pprod -DskipTests
<%_ } _%>
<%_ } else if (buildTool === 'gradle') { _%>
- ./gradlew bootRepackage -Pprod -x test --no-daemon
<%_ if (integrations.includes('heroku')) { _%>
<%_ if (heroku.includes('circle')) { _%>
- HEROKU_API_KEY="<%= herokuApiKey %>" ./gradlew deployHeroku --no-daemon
<%_ } _%>
<%_ } _%>

0 comments on commit 72965e6

Please sign in to comment.