ci-cd-pipeline-app-murano/murano-apps/CiCd2/package/Classes/CiCd2.yaml

182 lines
5.2 KiB
YAML

Namespaces:
=: org.openstack.ci_cd_pipeline_murano_app.v2
std: io.murano
res: io.murano.resources
sys: io.murano.system
cicd: org.openstack.ci_cd_pipeline_murano_app
puppet: org.openstack.ci_cd_pipeline_murano_app.puppet
net: org.openstack.ci_cd_pipeline_murano_app.utils.net
conf: io.murano.configuration
Name: CiCd2
Extends: std:Application
Properties:
nodes:
Default: ['review', 'jenkins', 'openldap']
Contract: [$.string().notNull()]
Usage: Const
server:
Contract: $.class(puppet:PuppetInstance)
Usage: InOut
clients:
Contract:
- $.class(puppet:PuppetClient)
Usage: InOut
name:
Contract: $.string().notNull()
Default: 'CiCd2'
puppetfileLink:
Contract: $.string().notNull()
Default: 'https://raw.githubusercontent.com/akhivin/cicd-dependencies/master/Puppetfile'
master:
Contract: $.class(puppet:PuppetServer)
Usage: InOut
clientsByName:
Contract: {}
Usage: InOut
mainManifestPath:
Default: '/etc/puppet/environments/production/manifests/site.pp'
Usage: Const
Contract: $.string().notNull()
flavor:
Contract: $.string().notNull()
osImage:
Contract: $.string().notNull()
keyPair:
Contract: $.string().notNull()
availabilityZone:
Contract: $.string().notNull()
Methods:
.init:
Body:
- $._environment: $.find(std:Environment).require()
deploy:
Body:
- $._environment.reporter.report($this,
'Using Puppetfile to install dependencies={0}'.format(
$this.puppetfileLink))
- $._environment.reporter.report($this, 'Nodes list={0}'.format($this.nodes))
- $rules:
- FromPort: 1
ToPort: 65535
IpProtocol: tcp
External: false
- FromPort: 1
ToPort: 65535
IpProtocol: tcp
External: true
- $this._environment.securityGroupManager.addGroupIngress(
rules => $rules)
# Deploy node for master and slave nodes in pararallel
- Parallel:
- If: $.server = null
Then:
- $this.server: new(puppet:PuppetInstance, $this._environment,
name => 'master',
flavor => $this.flavor,
image => $this.osImage,
keyname => $this.keyPair,
availabilityZone => $this.availabilityZone,
assignFloatingIp => true)
- $this.server.deploy()
- If: len($this.clients) = 0
Then:
- $this.clients: $this.nodes.select(
new(puppet:PuppetClient,
$this._environment,
instance => new(
puppet:PuppetInstance,
$this._environment,
name => concat('puppet_', $),
flavor => $this.flavor,
image => $this.osImage,
keyname => $this.keyPair,
availabilityZone => $this.availabilityZone,
assignFloatingIp => true),
role => $))
- $this.clients.pselect($.instance.deploy())
- $this.clientsByName: dict($this.clients.select([$.role, $]))
- $this.master: new(puppet:PuppetServer,
masterInstance => $this.server,
environment => $this._environment,
manifest => $this.mainManifestPath)
# add every node with the role assigned to it
- $this.clients.select(
$this.master.addClient($))
- $this.master.configure()
- $._environment.reporter.report($this, 'Preparing data for Gerrit')
- $gerritConfigurator: new(GerritConfigurator)
- $gerritConfigurator.configure($this.master.masterInstance)
- $._environment.reporter.report($this, 'Preparing data for Jenkins')
- $jenkinsConfigurator: new(JenkinsConfigurator)
- $jenkinsConfigurator.configure($this.master.masterInstance)
- $._environment.reporter.report($this, 'Preparing data for LDAP')
- $ldapConfigurator: new(LdapConfigurator)
- $ldapConfigurator.configure($this.master.masterInstance)
- $this._environment.reporter.report($this, 'Installing dependencies')
- $this.master.installDependencies(
environment => 'production',
puppetfileLink => $this.puppetfileLink)
- $resources: new(sys:Resources)
- $mainManifestContent: $resources.string('scripts/site.pp')
- new(conf:Linux).putFile(
$this.server.agent,
$mainManifestContent,
$this.mainManifestPath)
- $this._environment.reporter.report($this, 'Running manifests')
- $this.applyManifests()
applyManifests:
Usage: Action
Body:
- $this.master.runPuppetAgents()
- $this.printInfo()
printInfo:
Usage: Action
Body:
# Murano does not guarantee an order the lines to be printed
# at the same time it's impossible to print multiline messages.
# See LP#1611019
- $this._environment.reporter.report($this,
"Dependencies={0}".format($this.puppetfileLink))
- $this.clients.select($this._environment.reporter.report($this,
'{0} can be accessed on {1}'.format(
$.role,
$.instance.floatingIpAddress)))