diff --git a/murano-apps/Zuul/package/Classes/Zuul.yaml b/murano-apps/Zuul/package/Classes/Zuul.yaml index 289bb9a..72906b2 100644 --- a/murano-apps/Zuul/package/Classes/Zuul.yaml +++ b/murano-apps/Zuul/package/Classes/Zuul.yaml @@ -75,6 +75,8 @@ Methods: - $linux.runCommand($.instance.agent, 'service zuul start') - $linux.runCommand($.instance.agent, 'service zuul-merger restart') + - $._switchProjectConfig() + - $._createPeriodicLayoutUpdate() - $._environment.reporter.report($this, 'Zuul is available at http://{0}:80'.format($host)) - $.setAttr(deployed, true) @@ -91,6 +93,31 @@ Methods: - $.instance.setHieraValue('gerrit_user', 'zuul') - $.instance.setHieraValue('gerrit_ssh_host_key', $.gerrit.instance.getHieraValue('gerrit_ssh_rsa_pubkey_contents')) + _switchProjectConfig: + Body: + - $resources: new(sys:Resources) + - $linux: new(conf:Linux) + - $script: $resources.string('switch_to_local_project_config.sh') + - $._environment.reporter.report($this, '[Zuul] Switching to project-config from installed Gerrit...') + - $projectConfigURL: format( + 'ssh://{0}@{1}:29418/open-paas/project-config', + $.instance.getHieraValue('gerrit_user'), + $.instance.getHieraValue('gerrit_server') + ) + - $.instance.setHieraValue('project_config_repo', $projectConfigURL) + - $linux.runCommand($.instance.agent, $script) + + _createPeriodicLayoutUpdate: + Body: + - $resources: new(sys:Resources) + - $linux: new(conf:Linux) + - $script: $resources.string('update_layout.sh') + - $._environment.reporter.report($this, '[Zuul] Creating autoupdating layout.yaml file...') + - $linux.putFile($.instance.agent, $script, '/usr/local/bin/update_layout.sh') + - $manifest: $resources.string('update_layout.pp') + - $linux.putFile($.instance.agent, $manifest, '/usr/local/bin/update_layout.pp') + - $linux.runCommand($.instance.agent, 'puppet apply /usr/local/bin/update_layout.pp') + destroy: Body: - $.reportDestroyed() diff --git a/murano-apps/Zuul/package/Resources/switch_to_local_project_config.sh b/murano-apps/Zuul/package/Resources/switch_to_local_project_config.sh new file mode 100755 index 0000000..2777d7d --- /dev/null +++ b/murano-apps/Zuul/package/Resources/switch_to_local_project_config.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +REPO_URL=$(hiera -c /etc/puppet/hiera.yaml project_config_repo) + +cp /var/lib/zuul/ssh/id_rsa /home/zuul/.ssh/id_rsa && chown zuul:zuul /home/zuul/.ssh/id_rsa + +cd /etc/project-config +git remote set-url origin "$REPO_URL" +git config --global user.email "zuul@example.com" +git config --global user.name "Zuul" + +chown -R zuul:zuul /etc/project-config diff --git a/murano-apps/Zuul/package/Resources/update_layout.pp b/murano-apps/Zuul/package/Resources/update_layout.pp new file mode 100644 index 0000000..d7dea81 --- /dev/null +++ b/murano-apps/Zuul/package/Resources/update_layout.pp @@ -0,0 +1,7 @@ +cron { "update_layout": + user => 'root', + ensure => present, + command => "bash /usr/local/bin/update_layout.sh", + hour => '*', + minute => '*/5', +} \ No newline at end of file diff --git a/murano-apps/Zuul/package/Resources/update_layout.sh b/murano-apps/Zuul/package/Resources/update_layout.sh new file mode 100755 index 0000000..766550d --- /dev/null +++ b/murano-apps/Zuul/package/Resources/update_layout.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +cd /etc/project-config + +# Check for new changes. +su zuul -c "git pull" + +sha_from_repo=$(sha1sum zuul/layout.yaml | awk '{print $1}') +sha_local=$(sha1sum /etc/zuul/layout/layout.yaml | awk '{print $1}') + +# Determine whether a change is made. +if [ "$sha_local" != "$sha_from_repo" ]; then + cp zuul/layout.yaml /etc/zuul/layout/layout.yaml + service zuul force-reload +fi