UNPKG

@darkobits/dockerize

Version:
119 lines (117 loc) 3.86 kB
#!/usr/bin/env node import os from "os"; import cli from "@darkobits/saffron"; import { DEFAULT_UBUNTU_VERSION } from "../etc/constants.js"; import dockerize from "../lib/dockerize.js"; import log from "../lib/log.js"; cli.command({ command: '* [cwd]', builder: ({ command }) => { command.positional('cwd', { description: 'Directory of the project to Dockerize. [Default: cwd]', type: 'string', required: false }); command.option('tag', { group: 'Optional Arguments:', description: 'Tag to use for the image. [Default: Package name]', required: false, type: 'string' }); command.option('node-version', { group: 'Optional Arguments:', description: 'Node version to install in the image. [Default: LTS]', required: false, type: 'string', conflicts: ['dockerfile'] }); command.option('ubuntu-version', { group: 'Optional Arguments:', description: `Ubuntu version to use as a base image. [Default: ${DEFAULT_UBUNTU_VERSION}]`, required: false, type: 'string', conflicts: ['dockerfile'] }); command.option('label', { group: 'Optional Arguments:', description: 'Labels to apply to the image. May be used multiple times.', required: false, type: 'string' }); command.option('env', { group: 'Optional Arguments:', description: 'Environment variables to set in the image. May be used multiple times.', required: false, type: 'string', conflicts: ['dockerfile'] }); command.option('extra-args', { group: 'Optional Arguments:', description: 'Optional extra arguments to pass to "docker build".\nThis is treated as a single string and should be quoted.', required: false, type: 'string' }); command.option('npmrc', { group: 'Optional Arguments:', description: 'Path to an .npmrc file to use when installing packages.\nOr set to true to use the closest .npmrc file.', required: false, type: 'string', conflicts: ['dockerfile'] }); command.option('push', { group: 'Optional Arguments:', description: 'Whether to call `docker push` after building images.', required: false, type: 'boolean', default: false }); command.option('dockerfile', { group: 'Advanced:', description: 'Path to a custom Dockerfile to use.', required: false, type: 'string', conflicts: ['env', 'nodeVersion', 'npmrc'] }); command.example('$0', 'Dockerize the NodeJS project in the current directory using default options.'); command.example('$0 --label="foo=bar" --label="baz=qux" --extra-args="--squash"', 'Dockerize the NodeJS project in the current directory, apply two labels, and pass the --squash argument to Docker.'); }, handler: async ({ argv }) => { try { log.configure({ level: process.env.LOG_LEVEL ?? 'info' }); await dockerize({ cwd: argv.cwd || process.cwd(), tag: argv.tag, nodeVersion: argv.nodeVersion, ubuntuVersion: argv.ubuntuVersion, labels: argv.label, env: argv.env, extraArgs: argv.extraArgs, dockerfile: argv.dockerfile, npmrc: argv.npmrc, push: argv.push }); } catch (err) { let message; let stackLines; if (err && err.name === 'ArgumentError') { message = err.message; stackLines = err.stack.split(os.EOL).filter(line => !line.startsWith('- ')); } else { [message, ...stackLines] = err.stack.split(os.EOL); } log.error(message); log.verbose(stackLines.join(os.EOL)); process.exit(1); } } }); cli.init(yargs => { yargs.scriptName(log.chalk.cyan('dockerize')); }); //# sourceMappingURL=cli.js.map