From 68610b1cf99bd4c2acb20891f7a099acbfbdf74f Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Mon, 21 Sep 2015 13:18:22 -0700 Subject: [PATCH] Staged upgrade for npm The version of npm that ships with trusty is able to upgrade itself to npm v2, but cannot upgrade to npm v3. Furthermore, performing a staged upgrade picks up the default `profile` parameter from npm, so that value has to be overridden globally in order to ensure that /usr/bin is not polluted. This patch adds the following: - A staged upgrade step, triggered when the detected version of npm is "1", to upgrade to version 2. - A new global npmrc configuration file, containing the profile setting. - Renamed jenkins/global npmrc templates. Values that made more sense to keep globally have been moved there. Change-Id: Ia633ccabb49d74a10c904a6e8ba73945d77fb32d --- .../manifests/release_slave.pp | 27 ++++++++++++++++--- .../templates/npmrc_global.erb | 3 +++ .../{npmrc.erb => npmrc_jenkins.erb} | 2 -- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 modules/openstack_project/templates/npmrc_global.erb rename modules/openstack_project/templates/{npmrc.erb => npmrc_jenkins.erb} (89%) diff --git a/modules/openstack_project/manifests/release_slave.pp b/modules/openstack_project/manifests/release_slave.pp index 982d76e179..4cadc5a35e 100644 --- a/modules/openstack_project/manifests/release_slave.pp +++ b/modules/openstack_project/manifests/release_slave.pp @@ -55,13 +55,26 @@ class openstack_project::release_slave ( package { ['nodejs', 'nodejs-legacy', 'npm']: ensure => latest, - before => Exec['upgrade npm'], + before => [ + Exec['upgrade npm'] + ] + } + + exec { 'assert npm@2': + command => 'npm install npm@2 -g --upgrade', + path => '/usr/local/bin:/usr/bin', + onlyif => '[ `npm --version | cut -c 1` = "1" ]', + require => [ + Package['npm'], + File['/etc/npmrc'], + ], } exec { 'upgrade npm': command => 'npm install npm -g --upgrade', path => '/usr/local/bin:/usr/bin', - onlyif => '[ `npm view npm version` != `npm --version` ]' + onlyif => '[ `npm view npm version` != `npm --version` ]', + require => Exec['assert npm@2'], } file { '/home/jenkins/.pypirc': @@ -78,10 +91,18 @@ class openstack_project::release_slave ( owner => 'jenkins', group => 'jenkins', mode => '0600', - content => template('openstack_project/npmrc.erb'), + content => template('openstack_project/npmrc_jenkins.erb'), require => File['/home/jenkins'], } + file { '/etc/npmrc': + ensure => present, + owner => 'root', + group => 'root', + mode => '0666', + content => template('openstack_project/npmrc_global.erb'), + } + file { '/home/jenkins/.jenkinsci-curl': ensure => present, owner => 'jenkins', diff --git a/modules/openstack_project/templates/npmrc_global.erb b/modules/openstack_project/templates/npmrc_global.erb new file mode 100644 index 0000000000..bdd42b825e --- /dev/null +++ b/modules/openstack_project/templates/npmrc_global.erb @@ -0,0 +1,3 @@ +tag-version-prefix= +sign-git-tag=true +prefix=/usr/local diff --git a/modules/openstack_project/templates/npmrc.erb b/modules/openstack_project/templates/npmrc_jenkins.erb similarity index 89% rename from modules/openstack_project/templates/npmrc.erb rename to modules/openstack_project/templates/npmrc_jenkins.erb index 9b267d8ad2..cf6550c5e6 100644 --- a/modules/openstack_project/templates/npmrc.erb +++ b/modules/openstack_project/templates/npmrc_jenkins.erb @@ -4,8 +4,6 @@ init.author.name=<%= jenkins_gitfullname %> init.author.email=<%= jenkins_gitemail %> init.author.url=<%= npm_userurl %> -tag-version-prefix= -sign-git-tag=true //registry.npmjs.org/:username=<%= npm_username %> //registry.npmjs.org/:_password=<%= Base64.encode64(npm_userpassword) %>