Initial version of puppet-based Jenkins

Current version of Jenkins app installs Jenkins and
JJB and creates jobs whose templates are located at /etc/project-config/
(this is a place where JJB looks for jobs template by default)

This application uses new libraries:
https://gerrit.mirantis.com/#/c/58907/
https://gerrit.mirantis.com/#/c/58860/

Change-Id: I80329809b245a63ad8d7e2966f9142c11562996b
This commit is contained in:
Anastasia Kuznetsova 2016-03-14 16:17:19 +03:00 committed by Alexey Khivin
parent 49fe6a2126
commit 4e467411b3
19 changed files with 34 additions and 477 deletions

View File

@ -1,8 +1,10 @@
Namespaces:
=: io.murano.apps
=: io.murano.opaas
std: io.murano
res: io.murano.resources
sys: io.murano.system
opaas: io.murano.opaas
puppet: io.murano.opaas.puppet
Name: Jenkins
@ -11,12 +13,8 @@ Extends: std:Application
Properties:
name:
Contract: $.string().notNull()
ldap:
Contract: $.class(OpenLDAP)
gerrit:
Contract: $.class(Gerrit)
instance:
Contract: $.class(res:Instance).notNull()
Contract: $.class(puppet:PuppetInstance).notNull()
Methods:
initialize:
@ -25,39 +23,29 @@ Methods:
deploy:
Body:
- $.super($.deploy())
- If: not $.getAttr(deployed, false)
Then:
- $._environment.reporter.report($this, 'Creating VM for Jenkins')
- $._environment.reporter.report($this, 'Creating security group for Jenkins')
- $securityGroupIngress:
- ToPort: 8080
FromPort: 8080
IpProtocol: tcp
External: true
- $._environment.securityGroupManager.addGroupIngress($securityGroupIngress)
- $._environment.reporter.report($this, 'Creating VM for Jenkins {0}'.format($.instance.openstackId))
- $.instance.deploy()
- $._environment.reporter.report($this, 'Jenkins VM {0} created'.format($.instance.openstackId))
- $this.projectConfig: new(puppet:ProjectConfig)
- $this.projectConfig.installOnTheNode($this.instance)
- $resources: new(sys:Resources)
- $template: $resources.yaml('DeployJenkins.template')
- $._environment.reporter.report($this, 'Jenkins deploying')
- $.instance.agent.call($template, $resources)
- If: $.ldap != null
Then:
- $._environment.reporter.report($this, 'Jenkins waits OpenLDAP to be deployed...')
- $.ldap.deploy()
- $.connectLDAP()
- If: $.gerrit != null and $.ldap != null
Then:
- $._environment.reporter.report($this, 'Jenkins waits Gerrit to be deployed...')
- $.gerrit.deploy()
- $.connectGerrit()
- $sshKey: $.getKey()
- $.gerrit.putKey($sshKey)
- $.installJJB()
- $.configureJJB()
- $.createTestJob()
- If: $.instance.assignFloatingIp
Then:
- $host: $.instance.floatingIpAddress
@ -66,88 +54,6 @@ Methods:
- $._environment.reporter.report($this, 'Jenkins is available at {0}:8080'.format($host))
- $.setAttr(deployed, true)
installJJB:
Body:
- $resources: new(sys:Resources)
- $._environment.reporter.report($this, 'Installing Jenkins Job Builder')
- $template: $resources.yaml('InstallJJB.template')
- $.instance.agent.call($template, $resources)
configureJJB:
Body:
- $resources: new(sys:Resources)
- $._environment.reporter.report($this, 'Configuring Jenkins Job Builder')
- If: $.ldap != null
Then:
- If: $.ldap.ldapUser != '' and $.ldap.ldapUser != null
Then:
- $user: $.ldap.ldapUser
- $password: $.ldap.ldapPass
Else:
- $user: 'jenkins'
- $password: 'openstack'
Else:
- $user: ''
- $password: ''
- $template: $resources.yaml('ConfigureJJB.template').bind(dict(
jenkinsip => $.instance.ipAddresses[0],
user => $user,
password => $password
))
- $.instance.agent.call($template, $resources)
- $._environment.reporter.report($this, 'Jenkins Job Builder is configured!')
createTestJob:
Body:
- $resources: new(sys:Resources)
- $._environment.reporter.report($this, 'Creating test job via Jenkins Job Builder')
- $template: $resources.yaml('CreateTestJob.template')
- $.instance.agent.call($template, $resources)
connectLDAP:
Body:
- $.ldap.configureOpenLDAPUser($.ldap.domain, 'jenkins', 'openstack')
- $ldapInstance: $.ldap.instance
- If: $ldapInstance.assignFloatingIp
Then:
- $ldapHost: $ldapInstance.floatingIpAddress
Else:
- $ldapHost: $ldapInstance.ipAddresses[0]
- $resources: new(sys:Resources)
- $._environment.reporter.report($this, 'Connecting Jenkins to OpenLDAP server')
- $template: $resources.yaml('ConnectLDAP.template').bind(dict(
openLDAPip => $ldapHost,
domain => $.ldap.domain
))
- $.instance.agent.call($template, $resources)
- $._environment.reporter.report($this, 'Jenkins is connected to OpenLDAP server!')
connectGerrit:
Body:
- $._environment.reporter.report($this, 'Connecting Jenkins with Gerrit')
- $gerritInstance: $.gerrit.instance
- If: $gerritInstance.assignFloatingIp
Then:
- $gerritHost: $gerritInstance.floatingIpAddress
Else:
- $gerritHost: $gerritInstance.ipAddresses[0]
- $resources: new(sys:Resources)
- $template: $resources.yaml('ConnectGerrit.template').bind(dict(
gerritIp => $gerritHost,
domain => $.ldap.domain
))
- $.instance.agent.call($template, $resources)
- $._environment.reporter.report($this, 'Jenkins is connected with Gerrit!')
getKey:
Body:
- $._environment.reporter.report($this, 'Get SSH key from Jenkins')
- $resources: new(sys:Resources)
- $template: $resources.yaml('GetKey.template')
- $sshKey: $.instance.agent.call($template, $resources)
- Return: format('{0}', $sshKey)
destroy:
Body:

View File

@ -1,22 +0,0 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Configure Jenkins Job Builder
Parameters:
jenkinsip: $jenkinsip
user: $user
password: $password
Body: |
return configure('{0} {1} {2}'.format(args.jenkinsip, args.user, args.password)).stdout
Scripts:
configure:
Type: Application
Version: 1.0.0
EntryPoint: configureJJB.sh
Files: []
Options:
captureStdout: true
captureStderr: true
verifyExitcode: false

View File

@ -1,21 +0,0 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Connect LDAP
Parameters:
gerritIp: $gerritIp
domain: $domain
Body: |
return configure('{0} {1}'.format(args.gerritIp, args.domain)).stdout
Scripts:
configure:
Type: Application
Version: 1.0.0
EntryPoint: connectGerrit.sh
Files: []
Options:
captureStdout: true
captureStderr: true
verifyExitcode: false

View File

@ -1,21 +0,0 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Connect LDAP
Parameters:
openLDAPip: $openLDAPip
domain: $domain
Body: |
return configure('{0} {1}'.format(args.openLDAPip, args.domain)).stdout
Scripts:
configure:
Type: Application
Version: 1.0.0
EntryPoint: connectLDAP.sh
Files: []
Options:
captureStdout: true
captureStderr: true
verifyExitcode: false

View File

@ -1,17 +0,0 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Create Test Job using Jenkins Job Builder
Body: |
return create().stdout
Scripts:
create:
Type: Application
Version: 1.0.0
EntryPoint: createTestJob.sh
Files: []
Options:
captureStdout: true
captureStderr: true
verifyExitcode: false

View File

@ -1,20 +1,17 @@
FormatVersion: 2.0.0
FormatVersion: 2.1.0
Version: 1.0.0
Name: Deploy Jenkins
Parameters:
appName: $appName
Body: |
return deploy(args.appName).stdout
return deploy().stdout
Scripts:
deploy:
Type: Application
Version: 1.0.0
EntryPoint: deployJenkins.sh
Files: []
EntryPoint: deploy.sh
Files: ['site.pp']
Options:
captureStdout: true
captureStderr: true
verifyExitcode: false

View File

@ -1,22 +0,0 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Get ssh key
Parameters:
sshKey: $sshKey
Body: |
key = ''
with open('/var/lib/jenkins/.ssh/jenkins-id_rsa.pub','r') as f:
key = f.read()
return key
Scripts:
noop:
Type: Application
Version: 1.0.0
EntryPoint: noop.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -1,17 +0,0 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Install Jenkins Job Builder
Body: |
return deploy().stdout
Scripts:
deploy:
Type: Application
Version: 1.0.0
EntryPoint: installJJB.sh
Files: []
Options:
captureStdout: true
captureStderr: true
verifyExitcode: false

View File

@ -1,18 +0,0 @@
#!/bin/bash
JENKINS_IP="$1"
USER="$2"
PASSWORD="$3"
cd ~/jenkins-job-builder
cp etc/jenkins_jobs.ini-sample etc/jenkins_jobs.ini
sed -i "s/https:\/\/jenkins.example.com/http:\/\/$JENKINS_IP:8080\//g" etc/jenkins_jobs.ini
if [ -n "$USER" ];
then
sed -i "s/user=jenkins/user=$USER/g" etc/jenkins_jobs.ini;
sed -i "s/password=1234567890abcdef1234567890abcdef/password=$PASSWORD/g" etc/jenkins_jobs.ini;
fi

View File

@ -1,117 +0,0 @@
#!/bin/bash
GERRIT_IP="$1"
DOMAIN="$2"
cat << CONFIG >> /var/lib/jenkins/credentials.xml
<?xml version='1.0' encoding='UTF-8'?>
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials@1.18">
<domainCredentialsMap class="hudson.util.CopyOnWriteMap\$Hash">
<entry>
<com.cloudbees.plugins.credentials.domains.Domain>
<specifications/>
</com.cloudbees.plugins.credentials.domains.Domain>
<java.util.concurrent.CopyOnWriteArrayList>
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials@1.10">
<scope>GLOBAL</scope>
<id>10055155-5c33-4318-8161-96a3ccd270a8</id>
<description></description>
<username>jenkins</username>
<passphrase>aE53R1jYUuH1K2BgkbGqfw==</passphrase>
<privateKeySource class="com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey\$FileOnMasterPrivateKeySource">
<privateKeyFile>/var/lib/jenkins/.ssh/jenkins-id_rsa</privateKeyFile>
</privateKeySource>
</com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey>
</java.util.concurrent.CopyOnWriteArrayList>
</entry>
</domainCredentialsMap>
</com.cloudbees.plugins.credentials.SystemCredentialsProvider>
CONFIG
cat << CONFIG >> /var/lib/jenkins/gerrit-trigger.xml
<?xml version='1.0' encoding='UTF-8'?>
<com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl plugin="gerrit-trigger@2.12.0">
<servers class="java.util.concurrent.CopyOnWriteArrayList">
<com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer>
<name>Gerrit</name>
<noConnectionOnStartup>false</noConnectionOnStartup>
<config class="com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config">
<gerritHostName>${GERRIT_IP}</gerritHostName>
<gerritSshPort>29418</gerritSshPort>
<gerritProxy></gerritProxy>
<gerritUserName>jenkins</gerritUserName>
<gerritEMail>jenkins@${DOMAIN}</gerritEMail>
<gerritAuthKeyFile>/var/lib/jenkins/.ssh/jenkins-id_rsa</gerritAuthKeyFile>
<gerritAuthKeyFilePassword>aE53R1jYUuH1K2BgkbGqfw==</gerritAuthKeyFilePassword>
<useRestApi>false</useRestApi>
<restCodeReview>false</restCodeReview>
<restVerified>false</restVerified>
<gerritBuildCurrentPatchesOnly>false</gerritBuildCurrentPatchesOnly>
<gerritVerifiedCmdBuildSuccessful>gerrit review &lt;CHANGE&gt;,&lt;PATCHSET&gt; --message &apos;Build Successful &lt;BUILDS_STATS&gt;&apos; --verified &lt;VERIFIED&gt; --code-review &lt;CODE_REVIEW&gt;</gerritVerifiedCmdBuildSuccessful>
<gerritVerifiedCmdBuildUnstable>gerrit review &lt;CHANGE&gt;,&lt;PATCHSET&gt; --message &apos;Build Unstable &lt;BUILDS_STATS&gt;&apos; --verified &lt;VERIFIED&gt; --code-review &lt;CODE_REVIEW&gt;</gerritVerifiedCmdBuildUnstable>
<gerritVerifiedCmdBuildFailed>gerrit review &lt;CHANGE&gt;,&lt;PATCHSET&gt; --message &apos;Build Failed &lt;BUILDS_STATS&gt;&apos; --verified &lt;VERIFIED&gt; --code-review &lt;CODE_REVIEW&gt;</gerritVerifiedCmdBuildFailed>
<gerritVerifiedCmdBuildStarted>gerrit review &lt;CHANGE&gt;,&lt;PATCHSET&gt; --message &apos;Build Started &lt;BUILDURL&gt; &lt;STARTED_STATS&gt;&apos; --verified &lt;VERIFIED&gt; --code-review &lt;CODE_REVIEW&gt;</gerritVerifiedCmdBuildStarted>
<gerritVerifiedCmdBuildNotBuilt>gerrit review &lt;CHANGE&gt;,&lt;PATCHSET&gt; --message &apos;No Builds Executed &lt;BUILDS_STATS&gt;&apos; --verified &lt;VERIFIED&gt; --code-review &lt;CODE_REVIEW&gt;</gerritVerifiedCmdBuildNotBuilt>
<gerritFrontEndUrl>http://${GERRIT_IP}:8080/</gerritFrontEndUrl>
<gerritBuildStartedVerifiedValue>0</gerritBuildStartedVerifiedValue>
<gerritBuildStartedCodeReviewValue>0</gerritBuildStartedCodeReviewValue>
<gerritBuildSuccessfulVerifiedValue>1</gerritBuildSuccessfulVerifiedValue>
<gerritBuildSuccessfulCodeReviewValue>0</gerritBuildSuccessfulCodeReviewValue>
<gerritBuildFailedVerifiedValue>-1</gerritBuildFailedVerifiedValue>
<gerritBuildFailedCodeReviewValue>0</gerritBuildFailedCodeReviewValue>
<gerritBuildUnstableVerifiedValue>0</gerritBuildUnstableVerifiedValue>
<gerritBuildUnstableCodeReviewValue>-1</gerritBuildUnstableCodeReviewValue>
<gerritBuildNotBuiltVerifiedValue>0</gerritBuildNotBuiltVerifiedValue>
<gerritBuildNotBuiltCodeReviewValue>0</gerritBuildNotBuiltCodeReviewValue>
<enableManualTrigger>true</enableManualTrigger>
<enablePluginMessages>true</enablePluginMessages>
<buildScheduleDelay>3</buildScheduleDelay>
<dynamicConfigRefreshInterval>30</dynamicConfigRefreshInterval>
<categories class="linked-list">
<com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory>
<verdictValue>Code-Review</verdictValue>
<verdictDescription>Code Review</verdictDescription>
</com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory>
<com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory>
<verdictValue>Verified</verdictValue>
<verdictDescription>Verified</verdictDescription>
</com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory>
</categories>
<replicationConfig>
<enableReplication>false</enableReplication>
<slaves class="linked-list"/>
<enableSlaveSelectionInJobs>false</enableSlaveSelectionInJobs>
</replicationConfig>
<watchdogTimeoutMinutes>0</watchdogTimeoutMinutes>
<watchTimeExceptionData>
<daysOfWeek/>
<timesOfDay class="linked-list"/>
</watchTimeExceptionData>
<notificationLevel>ALL</notificationLevel>
</config>
</com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer>
</servers>
<pluginConfig>
<numberOfReceivingWorkerThreads>3</numberOfReceivingWorkerThreads>
<numberOfSendingWorkerThreads>1</numberOfSendingWorkerThreads>
<replicationCacheExpirationInMinutes>360</replicationCacheExpirationInMinutes>
</pluginConfig>
</com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl>
CONFIG
cat << CONFIG >> /var/lib/jenkins/hudson.plugins.git.GitTool.xml
<?xml version='1.0' encoding='UTF-8'?>
<hudson.plugins.git.GitTool_-DescriptorImpl plugin="git-client@1.16.1">
<installations class="hudson.plugins.git.GitTool-array">
<hudson.plugins.git.GitTool>
<name>Default</name>
<home>git</home>
<properties/>
</hudson.plugins.git.GitTool>
</installations>
</hudson.plugins.git.GitTool_-DescriptorImpl>
CONFIG
# Restart jenkins
service jenkins restart
# Grab jenkins key from gerrit

View File

@ -1,54 +0,0 @@
#!/bin/bash
OPENLDAP_IP="$1"
DOMAIN="$2"
NAME="`echo "$DOMAIN" | cut -d. -f1`"
TLD="`echo "$DOMAIN" | cut -d. -f2`"
cat << CONFIG >> /var/lib/jenkins/config.xml
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>1.0</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.AuthorizationStrategy\$Unsecured"/>
<securityRealm class="hudson.security.LDAPSecurityRealm" plugin="ldap@1.6">
<server>ldap://${OPENLDAP_IP}</server>
<rootDN>dc=${NAME},dc=${TLD}</rootDN>
<inhibitInferRootDN>false</inhibitInferRootDN>
<userSearchBase></userSearchBase>
<userSearch>uid={0}</userSearch>
<managerDN>cn=admin,dc=${NAME},dc=${TLD}</managerDN>
<managerPassword>b3BlbnN0YWNr</managerPassword>
<disableMailAddressResolver>false</disableMailAddressResolver>
</securityRealm>
<disableRememberMe>false</disableRememberMe>
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy\$DefaultProjectNamingStrategy"/>
<workspaceDir>\${JENKINS_HOME}/workspace/\${ITEM_FULLNAME}</workspaceDir>
<buildsDir>\${ITEM_ROOTDIR}/builds</buildsDir>
<markupFormatter class="hudson.markup.EscapedMarkupFormatter"/>
<jdks/>
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
<clouds/>
<scmCheckoutRetryCount>0</scmCheckoutRetryCount>
<views>
<hudson.model.AllView>
<owner class="hudson" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View\$PropertyList"/>
</hudson.model.AllView>
</views>
<primaryView>All</primaryView>
<slaveAgentPort>0</slaveAgentPort>
<label></label>
<nodeProperties/>
<globalNodeProperties/>
</hudson>
CONFIG
service jenkins restart

View File

@ -1,6 +0,0 @@
cd ~/jenkins-job-builder
jenkins-jobs test -o output tests/yamlparser/fixtures/templates002.yaml
cat etc/jenkins_jobs.ini
ping -c 5 `grep 'url' etc/jenkins_jobs.ini | awk '{split($0,a,"/"); split(a[3],a,":"); print a[1]}'`
jenkins-jobs --conf etc/jenkins_jobs.ini update tests/yamlparser/fixtures/templates002.yaml

View File

@ -0,0 +1,3 @@
#!/bin/bash
puppet apply site.pp

View File

@ -1,20 +0,0 @@
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
# Install prerequisites
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update
# Jenkins
apt-get -y install jenkins
# Open firewall for jenkins
iptables -I INPUT 1 -p tcp -m tcp --dport 8080 -j ACCEPT -m comment --comment "by Murano, Jenkins"
service jenkins restart
# Create an ssh-key that can be used between Gerrit and Jenkins
sudo -u jenkins ssh-keygen -t rsa -N "" -f /var/lib/jenkins/.ssh/jenkins-id_rsa
chmod 400 /var/lib/jenkins/.ssh/jenkins-id_rsa
chmod 600 /var/lib/jenkins/.ssh/jenkins-id_rsa.pub

View File

@ -1,8 +0,0 @@
cd ~
git clone https://git.openstack.org/openstack-infra/jenkins-job-builder
cd jenkins-job-builder
sudo apt-get install python-tox --assume-yes
tox -e venv -- sudo python setup.py install
tox -e venv -- sudo pip install -r requirements.txt

View File

@ -1,3 +0,0 @@
#!/bin/bash
echo "Ok"

View File

@ -0,0 +1,9 @@
node default {
class { 'openstack_project::jenkins':
jenkins_password => '',
jenkins_ssh_private_key => '',
ssl_cert_file => '/etc/ssl/certs/ssl-cert-snakeoil.pem',
ssl_key_file => '/etc/ssl/private/ssl-cert-snakeoil.key',
ssl_chain_file => '',
}
}

View File

@ -2,13 +2,11 @@ Version: 2
Application:
?:
type: io.murano.apps.Jenkins
type: io.murano.opaas.Jenkins
name: $.appConfiguration.name
ldap: $.appConfiguration.OpenLDAP
gerrit: $.appConfiguration.GerritServer
instance:
?:
type: io.murano.resources.LinuxMuranoInstance
type: io.murano.opaas.puppet.PuppetInstance
name: generateHostname($.instanceConfiguration.unitNamingPattern, 1)
flavor: $.instanceConfiguration.flavor
image: $.instanceConfiguration.osImage
@ -22,7 +20,7 @@ Forms:
- name: name
type: string
label: Application Name
initial: Jenkins
initial: JenkinsPuppet
description: >-
Enter a desired name for the application. Just A-Z, a-z, 0-9, dash and
underline are allowed
@ -33,16 +31,6 @@ Forms:
Select to true to assign floating IP automatically
initial: true
required: false
- name: OpenLDAP
type: io.murano.apps.OpenLDAP
required: false
description: >-
Specify OpenLDAP domain for authentication
- name: GerritServer
type: io.murano.apps.Gerrit
required: false
description: >-
Specify Gerrit server
- instanceConfiguration:
fields:
- name: title

View File

@ -1,12 +1,12 @@
Format: 1.0
Type: Application
FullName: io.murano.apps.Jenkins
FullName: io.murano.opaas.Jenkins
Name: Jenkins
Description: |
Jenkins is an open source continuous integration tool written in Java.
Author: 'Mirantis, Inc'
Tags: [Server, Java, CI, Jenkins]
Classes:
io.murano.apps.Jenkins: Jenkins.yaml
io.murano.opaas.Jenkins: Jenkins.yaml
UI: ui.yaml
Logo: logo.png