Implementing the generate-ingest command
This is basically just generating the appropriate ingest.json for the evergreen backend from the realized section of the BoM
This commit is contained in:
parent
f4361816dd
commit
94f76d4e88
|
@ -112,3 +112,4 @@ $RECYCLE.BIN/
|
|||
# Others
|
||||
lib/
|
||||
data/
|
||||
ingest.json
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const Ingest = require('../cli/ingest');
|
||||
|
||||
describe('Ingest', () => {
|
||||
it('should be constructable', () => {
|
||||
expect(new Ingest()).toBeInstanceOf(Ingest);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,85 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const logger = require('winston');
|
||||
const request = require('request-promise');
|
||||
|
||||
const UrlResolver = require('./url-resolver');
|
||||
|
||||
/*
|
||||
* Class responsible for computing the ingest.json based off of a given
|
||||
* realized essentials.yaml file
|
||||
*/
|
||||
class Ingest {
|
||||
constructor(manifest) {
|
||||
this.manifest = manifest;
|
||||
this.ingest = {
|
||||
timestamp: Date.now(),
|
||||
core: {},
|
||||
plugins: [],
|
||||
environments: {},
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Use the manifest passed in to compute all the URLs and fetch the checksums
|
||||
* for all the references
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
resolveReferences() {
|
||||
let tasks = [];
|
||||
|
||||
const coreUrl = UrlResolver.artifactForCore(this.manifest.data.status.core);
|
||||
|
||||
this.ingest.core = {
|
||||
url: coreUrl,
|
||||
checksum: {},
|
||||
};
|
||||
|
||||
tasks.push(
|
||||
request(`${coreUrl}.sha256`)
|
||||
.then((res) => {
|
||||
Object.assign(this.ingest.core.checksum,
|
||||
{
|
||||
type: 'sha256',
|
||||
signature: res.split(' ')[0]
|
||||
});
|
||||
}));
|
||||
|
||||
this.manifest.data.status.plugins.forEach((plugin) => {
|
||||
let record = Object.assign(plugin, {
|
||||
checksum: {},
|
||||
});
|
||||
const url = UrlResolver.artifactForPlugin(plugin);
|
||||
|
||||
tasks.push(
|
||||
this.fetchHeadersFor(url).then((res) => {
|
||||
Object.assign(record.checksum, {
|
||||
type: 'sha256',
|
||||
signature: res.headers['x-checksum-sha256'],
|
||||
});
|
||||
})
|
||||
);
|
||||
this.ingest.plugins.push(record);
|
||||
});
|
||||
|
||||
return Promise.all(tasks);
|
||||
}
|
||||
|
||||
fetchHeadersFor(url) {
|
||||
return request({
|
||||
method: 'HEAD',
|
||||
uri: url,
|
||||
resolveWithFullResponse: true,
|
||||
});
|
||||
}
|
||||
|
||||
saveSync() {
|
||||
const fileName = 'ingest.json';
|
||||
logger.info(`Writing out ingest to ${fileName}`);
|
||||
return fs.writeFileSync(fileName,
|
||||
JSON.stringify(this.ingest, undefined, 2));
|
||||
}
|
||||
}
|
||||
module.exports = Ingest;
|
|
@ -1,8 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const logger = require('winston');
|
||||
const request = require('request-promise');
|
||||
const logger = require('winston');
|
||||
const request = require('request-promise');
|
||||
const compareVersions = require('compare-versions');
|
||||
|
||||
const PluginManifest = require('./plugin-manifest');
|
||||
|
@ -137,7 +136,7 @@ class ManifestResolver {
|
|||
fetchManifestForPlugin(plugin) {
|
||||
const start = Date.now();
|
||||
return request({
|
||||
uri: `${UrlResolver.artifactForPlugin(plugin)}!META-INF/MANIFEST.MF`,
|
||||
uri: `${UrlResolver.artifactForPlugin(plugin)}!META-INF/MANIFEST.MF`,
|
||||
}).then((res) => {
|
||||
logger.debug(`Fetching ${plugin.artifactId} took ${Date.now() - start}`);
|
||||
return res;
|
||||
|
|
|
@ -22,7 +22,7 @@ class UrlResolver {
|
|||
return `${INCREMENTALS}org/jenkins-ci/main/jenkins-war/${core.version}/jenkins-war-${core.version}.war`;
|
||||
}
|
||||
return `${WAR_MIRROR}${core.version}/jenkins.war`;
|
||||
};
|
||||
}
|
||||
/*
|
||||
* Compute the Artifactory URL for the given plugin record
|
||||
*
|
||||
|
@ -38,7 +38,6 @@ class UrlResolver {
|
|||
url = `${INCREMENTALS}${groupPath}/`;
|
||||
}
|
||||
return url + pluginFilename;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,32 +1,15 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const compareVersions = require('compare-versions');
|
||||
const logger = require('winston');
|
||||
const request = require('request-promise');
|
||||
const yargs = require('yargs');
|
||||
|
||||
const Ingest = require('./cli/ingest');
|
||||
const Manifest = require('./cli/manifest');
|
||||
const ManifestResolver = require('./cli/manifest-resolver');
|
||||
const UpdateCenter = require('./cli/update-center');
|
||||
|
||||
logger.level = process.env.LOG_LEVEL || 'info';
|
||||
|
||||
const INCREMENTALS = 'https://repo.jenkins-ci.org/incrementals/';
|
||||
|
||||
|
||||
/*
|
||||
* Workflows:
|
||||
*
|
||||
* Propose changes: consult the latest changes from the update center to see if
|
||||
* there are updated released versions available
|
||||
*
|
||||
* save: take the specified dependencies and save the status of the file
|
||||
*
|
||||
* generate-ingest: generate the ingest.json based off of what is in the save?
|
||||
*/
|
||||
|
||||
yargs.command('propose-updates',
|
||||
'Fetch the latest Update Center and propose updates',
|
||||
() => {},
|
||||
|
@ -34,6 +17,7 @@ yargs.command('propose-updates',
|
|||
logger.error('This command has not yet been implemented');
|
||||
}
|
||||
);
|
||||
|
||||
yargs.command('save',
|
||||
'Resolve dependencies specified essentials.yaml and re-save the file',
|
||||
() => {},
|
||||
|
@ -76,25 +60,15 @@ yargs.command('save',
|
|||
});
|
||||
}
|
||||
);
|
||||
|
||||
yargs.command('generate-ingest',
|
||||
'Generate the ingest.json for upload based on essentials.yaml',
|
||||
() => {},
|
||||
(argv) => {
|
||||
const manifest = Manifest.loadFile();
|
||||
const ingest = new Ingest(manifest);
|
||||
ingest.resolveReferences().then(() => { ingest.saveSync(); });
|
||||
}
|
||||
);
|
||||
/* parse the commands */
|
||||
yargs.argv;
|
||||
|
||||
const UPDATE_CENTER = 'https://updates.jenkins.io/update-center.actual.json';
|
||||
|
||||
let tasks = [];
|
||||
|
||||
//let r = request({
|
||||
// url: UPDATE_CENTER,
|
||||
// json: true,
|
||||
//}).then((uc) => {
|
||||
// Object.keys(uc.plugins).forEach(n => logger.info(n));
|
||||
//});
|
||||
//tasks.push(r);
|
||||
//
|
||||
//Promise.all(tasks).then(r => logger.info('Finished!'));
|
||||
|
|
Loading…
Reference in New Issue