vscode-dev-containers/build/vscdc

300 строки
12 KiB
Plaintext
Исходник Постоянная ссылка Обычный вид История

2020-01-15 01:53:59 +03:00
#!/usr/bin/env node
/*--------------------------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
*-------------------------------------------------------------------------------------------------------------*/
const push = require('./src/push').push;
2020-04-02 20:12:33 +03:00
const patch = require('./src/patch');
2020-01-15 01:53:59 +03:00
const package = require('./src/package').package;
2020-08-01 00:21:35 +03:00
const prep = require('./src/prep');
2020-01-15 01:53:59 +03:00
const generateComponentGovernanceManifest = require('./src/cgmanifest').generateComponentGovernanceManifest;
const configUtils = require('./src/utils/config');
const packageJson = require('../package.json');
console.log('vscode-dev-containers CLI\nCopyright (c) Microsoft Corporation. All rights reserved.\n')
require('yargs')
.command('pack', 'package dev container definitions', (yargs) => {
yargs
.options({
'release': {
describe: 'vscode-dev-containers release tag or a branch',
default: `v${packageJson.version}`
},
'registry': {
describe: 'container registry to push images to',
default: configUtils.getConfig('containerRegistry', 'docker.io')
},
'registry-path': {
describe: 'container registry path',
default: configUtils.getConfig('containerRegistryPath', 'vscode/devcontainers')
},
'stub-registry': {
describe: 'registry to add to stub',
default: configUtils.getConfig('stubRegistry',
configUtils.getConfig('containerRegistry', 'docker.io'))
2020-01-15 01:53:59 +03:00
},
'stub-registry-path': {
describe: 'stub registry path',
default: configUtils.getConfig('stubRegistryPath',
configUtils.getConfig('containerRegistryPath', ''))
2020-01-15 01:53:59 +03:00
},
'github-repo': {
describe: 'vscode-dev-containers repo name',
default: configUtils.getConfig('githubRepoName', 'microsoft/vscode-dev-containers')
},
2020-02-03 21:37:46 +03:00
'package-only': {
describe: 'whether to prep/build/push before packaging',
2020-01-15 01:53:59 +03:00
type: 'boolean',
2020-02-03 21:37:46 +03:00
default: false
},
2020-02-05 22:17:09 +03:00
'prep-and-package-only': {
describe: 'prep and package, but do not build/push',
2020-02-03 21:37:46 +03:00
type: 'boolean',
default: false
2020-01-15 01:53:59 +03:00
},
'update-latest': {
describe: 'whether to tag latest and {MAJOR}',
type: 'boolean',
default: true
},
'clean': {
describe: 'whether to clean up staging folder when done',
type: 'boolean',
default: true
2020-08-23 19:08:45 +03:00
},
'skip-push': {
describe: 'A space separated list of definition IDs to skip build and push.',
type: 'array',
default: []
2020-01-15 01:53:59 +03:00
}
})
}, packCommand)
.command('push [devcontainer]', 'push dev container images to a repository', (yargs) => {
yargs
.positional('devcontainer', {
describe: 'ID of dev container to push',
default: null
})
.options({
'release': {
describe: 'vscode-dev-containers release tag or branch',
default: `v${packageJson.version}`
},
'registry': {
describe: 'container registry to push images to',
default: configUtils.getConfig('containerRegistry', 'docker.io')
},
'registry-path': {
describe: 'container registry path',
default: configUtils.getConfig('containerRegistryPath', '')
},
'stub-registry': {
describe: 'registry to add to stub',
default: configUtils.getConfig('stubRegistry',
configUtils.getConfig('containerRegistry', 'docker.io'))
2020-01-15 01:53:59 +03:00
},
'stub-registry-path': {
describe: 'stub registry path',
default: configUtils.getConfig('stubRegistryPath',
configUtils.getConfig('containerRegistryPath', ''))
2020-01-15 01:53:59 +03:00
},
'github-repo': {
describe: 'vscode-dev-containers repo name',
default: configUtils.getConfig('githubRepoName', 'microsoft/vscode-dev-containers')
},
'update-latest': {
describe: 'whether to tag latest and {MAJOR} if pushing',
type: 'boolean',
default: true
},
2020-02-05 21:44:06 +03:00
'prep-only': {
2020-02-05 22:17:09 +03:00
describe: 'prep the containers for build/push, but do not actually do it',
2020-01-15 01:53:59 +03:00
type: 'boolean',
default: false
2020-02-03 21:37:46 +03:00
},
2020-02-05 22:17:09 +03:00
'push': {
describe: 'whether to push after prep/build',
type: 'boolean',
default: true
},
2020-02-03 21:37:46 +03:00
'page': {
describe: 'Page number (of total) to push',
type: 'integer',
default: 1
},
'page-total': {
describe: 'Total number of pages to use when parallelizing builds',
type: 'integer',
default: 1
},
'replace-images': {
describe: 'Whether to replace released images. Does not apply to dev tag.',
type: 'boolean',
default: false
2020-08-23 19:08:45 +03:00
},
'skip': {
describe: 'A space separated list of definition IDs to skip building and pushing.',
type: 'array',
default: []
2020-01-15 01:53:59 +03:00
}
})
}, pushCommand)
.command('update-script-sources <release>', 'updates all script source URLs in Dockerfiles to a tag or branch', (yargs) => {
2020-01-15 01:53:59 +03:00
yargs
2020-02-06 06:33:18 +03:00
.positional('release', {
describe: 'release tag to branch use for script URLs',
2020-01-15 01:53:59 +03:00
})
.options({
'github-repo': {
describe: 'vscode-dev-containers repo name',
default: configUtils.getConfig('githubRepoName', 'microsoft/vscode-dev-containers')
},
2020-02-06 06:33:18 +03:00
'update-sha': {
describe: 'update script SHAs to match file',
2020-01-15 01:53:59 +03:00
type: 'boolean',
default: true
}
})
}, updateScriptSourcesCommand)
.command('cg [devcontainer]', 'generate cgmanifest.json', (yargs) => {
2020-01-15 01:53:59 +03:00
yargs
.positional('devcontainer', {
describe: 'limits manifest generation to single definition',
default: null
})
2020-01-15 01:53:59 +03:00
.options({
'release': {
describe: 'vscode-dev-containers release tag or branch',
default: 'master'
},
'registry': {
describe: 'container registry to push images to',
default: configUtils.getConfig('containerRegistry', 'docker.io')
},
'registry-path': {
describe: 'container registry path',
default: configUtils.getConfig('containerRegistryPath', '')
},
'github-repo': {
describe: 'vscode-dev-containers repo name',
default: configUtils.getConfig('githubRepoName', 'microsoft/vscode-dev-containers')
2020-01-15 01:53:59 +03:00
},
'build': {
2020-02-05 21:44:06 +03:00
describe: 'whether to to build the image first step',
2020-01-15 01:53:59 +03:00
default: true
2020-08-23 19:08:45 +03:00
},
'prune': {
describe: 'whether to prune images between definitions',
default: false
2020-01-15 01:53:59 +03:00
}
})
}, cgCommand)
2020-01-25 05:28:37 +03:00
.command('patch', 'patch existing images', (yargs) => {
yargs
.options({
2020-04-02 20:12:33 +03:00
'all': {
describe: 'run all patches not already complete',
type: 'boolean',
default: false
},
2020-01-25 05:28:37 +03:00
'patch-path': {
describe: 'path to the folder containing the patch files',
default: '.'
},
'registry': {
describe: 'container registry to push images to',
default: configUtils.getConfig('containerRegistry', 'docker.io')
},
'registry-path': {
describe: 'container registry path',
default: configUtils.getConfig('containerRegistryPath', '')
}
})
}, patchCommand)
2020-08-01 00:21:35 +03:00
.command('copy-library-scripts', 'copy files from script-library folder into appropriate definitions', () => {}, copyLibraryScriptsCommand)
2020-01-15 01:53:59 +03:00
.demandCommand()
.help()
.argv;
function pushCommand(argv) {
push(argv.githubRepo, argv.release, argv.updateLatest, argv.registry, argv.registryPath, argv.stubRegistry,
2020-08-24 00:12:31 +03:00
argv.stubRegistryPath, argv.push, argv.prepOnly, argv.skip, argv.page, argv.pageTotal, argv.replaceImages, argv.devcontainer)
2020-01-15 01:53:59 +03:00
.catch((reason) => {
console.error(`(!) Push failed - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-01-15 01:53:59 +03:00
process.exit(1);
});
}
function packCommand(argv) {
package(argv.githubRepo, argv.release, argv.updateLatest, argv.registry, argv.registryPath,
2020-08-23 19:08:45 +03:00
argv.stubRegistry, argv.stubRegistryPath, argv.prepAndPackageOnly, argv.packageOnly, argv.clean, argv.skipPush)
2020-01-15 01:53:59 +03:00
.catch((reason) => {
console.error(`(!) Packaging failed - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-01-15 01:53:59 +03:00
process.exit(1);
});
}
function updateScriptSourcesCommand(argv) {
2020-08-01 00:21:35 +03:00
prep.updateAllScriptSourcesInRepo(argv.githubRepo, argv.release, argv.updateSha)
2020-01-15 01:53:59 +03:00
.catch((reason) => {
2020-08-01 00:21:35 +03:00
console.error(`(!) Failed to update script sources - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-01-15 01:53:59 +03:00
process.exit(1);
});
}
2020-08-01 00:21:35 +03:00
function copyLibraryScriptsCommand() {
prep.copyLibraryScriptsForAllDefinitions()
.catch((reason) => {
console.error(`(!) Failed to copy library scripts to definitions - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-08-01 00:21:35 +03:00
process.exit(1);
});
}
2020-01-15 01:53:59 +03:00
function cgCommand(argv) {
2020-08-23 19:08:45 +03:00
generateComponentGovernanceManifest(argv.githubRepo, argv.release, argv.registry, argv.registryPath, argv.build, argv.prune, argv.devcontainer)
2020-01-15 01:53:59 +03:00
.catch((reason) => {
console.error(`(!) Component governance manifest generation failed - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-01-15 01:53:59 +03:00
process.exit(1);
});
}
2020-01-25 05:28:37 +03:00
function patchCommand(argv) {
2020-04-02 20:12:33 +03:00
if (argv.all) {
patch.patchAll(argv.registry, argv.registryPath)
.catch((reason) => {
console.error(`(!) Patching failed - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-04-02 20:12:33 +03:00
process.exit(1);
});
} else {
patch.patch(argv.patchPath, argv.registry, argv.registryPath)
.catch((reason) => {
console.error(`(!) Patching failed - ${reason}`);
if(reason.stack) {
console.error(` ${reason.stack}`);
}
2020-04-02 20:12:33 +03:00
process.exit(1);
});
}
2020-01-25 05:28:37 +03:00
}