UNPKG

1.06 kBJavaScriptView Raw
1const cli = require('heroku-cli-util')
2const log = require('../lib/log')
3const Sanbashi = require('../lib/sanbashi')
4
5module.exports = function (topic) {
6 return {
7 topic: topic,
8 command: 'login',
9 flags: [{name: 'verbose', char: 'v', hasValue: false}],
10 description: 'login to the Heroku Container Registry',
11 help: `Usage:
12 heroku container:login`,
13 needsApp: false,
14 needsAuth: true,
15 run: cli.command(login)
16 }
17}
18
19async function login (context, heroku) {
20 let herokuHost = process.env.HEROKU_HOST || 'heroku.com'
21 let registry = `registry.${ herokuHost }`
22 let password = context.auth.password
23
24 try {
25 let user = await dockerLogin(registry, password, context.flags.verbose)
26 }
27 catch (err) {
28 cli.error(`Error: docker login exited with ${ err }`)
29 cli.hush(err.stack || err)
30 cli.exit(1)
31 }
32}
33
34function dockerLogin (registry, password, verbose) {
35 let args = [
36 'login',
37 '--username=_',
38 `--password=${ password }`,
39 registry
40 ]
41 log(verbose, args)
42 return Sanbashi.cmd('docker', args)
43}