diff --git a/lib/manager/bundler/artifacts.js b/lib/manager/bundler/artifacts.js index 2c7fc312861a64dd5e951c73a07477b3ab93ec0b..8994a36363eee2e310e8c74981f191e5514e92d0 100644 --- a/lib/manager/bundler/artifacts.js +++ b/lib/manager/bundler/artifacts.js @@ -4,6 +4,14 @@ const { exec } = require('child-process-promise'); const fs = require('fs-extra'); const upath = require('upath'); +const { getPkgReleases } = require('../../datasource/docker'); +const { + isValid, + isVersion, + matches, + sortVersions, +} = require('../../versioning/ruby'); + module.exports = { getArtifacts, }; @@ -48,20 +56,65 @@ async function getArtifacts( let cmd; if (config.binarySource === 'docker') { logger.info('Running bundler via docker'); + let tag = 'latest'; + let rubyConstraint; + const rubyVersionFile = upath.join( + upath.dirname(packageFileName), + '.ruby-version' + ); + logger.debug('Checking ' + rubyVersionFile); + const rubyVersionFileContent = await platform.getFile(rubyVersionFile); + if (rubyVersionFileContent) { + logger.debug('Using ruby version specified in .ruby-version'); + rubyConstraint = rubyVersionFileContent.replace(/\n/g, '').trim(); + } else { + rubyConstraint = + config && config.compatibility && config.compatibility.ruby + ? config.compatibility.ruby + : undefined; + } + if (rubyConstraint && isValid(rubyConstraint)) { + logger.debug('Found ruby compatibility'); + const rubyReleases = await getPkgReleases({ + fullname: 'renovate/ruby', + qualifiers: {}, + }); + if (rubyReleases && rubyReleases.releases) { + let versions = rubyReleases.releases.map(release => release.version); + versions = versions.filter(version => isVersion(version)); + versions = versions.filter(version => + matches(version, rubyConstraint) + ); + versions = versions.sort(sortVersions); + if (versions.length) { + tag = versions.pop(); + } + } + } + const bundlerConstraint = + config && config.compatibility && config.compatibility.bundler + ? config.compatibility.bundler + : undefined; + let bundlerVersion = ''; + if (bundlerConstraint && isVersion(bundlerConstraint)) { + bundlerVersion = ' -v ' + bundlerConstraint; + } cmd = `docker run --rm `; const volumes = [config.localDir]; cmd += volumes.map(v => `-v ${v}:${v} `).join(''); const envVars = []; cmd += envVars.map(e => `-e ${e} `); cmd += `-w ${cwd} `; - cmd += `renovate/bundler bundler`; + cmd += `renovate/ruby:${tag} bash -l -c "ruby --version && `; + cmd += 'gem install bundler' + bundlerVersion; + cmd += ' && bundle'; } else { logger.info('Running bundler via global bundler'); cmd = 'bundler'; } - const args = 'lock'; - logger.debug({ cmd, args }, 'bundler command'); - ({ stdout, stderr } = await exec(`${cmd} ${args}`, { + cmd += ' lock"'; + logger.debug({ cmd }, 'bundler command'); + ({ stdout, stderr } = await exec(cmd, { cwd, shell: true, env,