1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | 'use strict';
|
14 |
|
15 | const yargsOpenwhisk = require('./yargs-openwhisk.js');
|
16 | const yargsFastly = require('./yargs-fastly.js');
|
17 | const yargsBuild = require('./yargs-build.js');
|
18 | const yargsParams = require('./yargs-params.js');
|
19 | const yargsCoralogix = require('./yargs-coralogix.js');
|
20 | const yargsEpsagon = require('./yargs-epsagon.js');
|
21 | const { getOrCreateLogger } = require('./log-common.js');
|
22 |
|
23 | module.exports = function deploy() {
|
24 | let executor;
|
25 |
|
26 | return {
|
27 | set executor(value) {
|
28 | executor = value;
|
29 | },
|
30 | command: 'deploy [files..]',
|
31 | desc: 'Deploy packaged functions to Adobe I/O runtime',
|
32 | builder: (yargs) => {
|
33 | yargsOpenwhisk(yargs);
|
34 | yargsFastly(yargs);
|
35 | yargsBuild(yargs);
|
36 | yargsEpsagon(yargs);
|
37 | yargsCoralogix(yargs);
|
38 | yargsParams(yargs, {
|
39 | name: 'default',
|
40 | describe: 'Adds a default parameter to the function',
|
41 | type: 'array',
|
42 | default: [],
|
43 | });
|
44 | yargs
|
45 | .option('auto', {
|
46 | describe: 'Enable auto-deployment',
|
47 | type: 'boolean',
|
48 | default: false,
|
49 | demandOption: true,
|
50 | })
|
51 | .option('dry-run', {
|
52 | alias: 'dryRun',
|
53 | describe: 'List the actions that would be created, but do not actually deploy',
|
54 | type: 'boolean',
|
55 | default: false,
|
56 | })
|
57 | .option('circleci-auth', {
|
58 | alias: 'circleciAuth',
|
59 | describe: 'API Key for CircleCI API ($HLX_CIRCLECI_AUTH)',
|
60 | type: 'string',
|
61 | default: '',
|
62 | })
|
63 | .option('target', {
|
64 | alias: 'o',
|
65 | default: '.hlx/build',
|
66 | type: 'string',
|
67 | describe: 'Target directory of created action packages.',
|
68 | })
|
69 | .option('dirty', {
|
70 | describe: 'Allows deploying a working copy with uncommitted changes (dangerous)',
|
71 | type: 'boolean',
|
72 | default: false,
|
73 | })
|
74 | .option('add', {
|
75 | describe: 'Adds missing strains to the config',
|
76 | type: 'string',
|
77 | })
|
78 | .option('package', {
|
79 | describe: 'Automatically create or update outdated action packages.',
|
80 | type: 'string',
|
81 | choices: ['auto', 'ignore', 'always'],
|
82 | default: 'auto',
|
83 | })
|
84 | .option('minify', {
|
85 | describe: 'Enables minification of the final action bundle.',
|
86 | type: 'boolean',
|
87 | default: false,
|
88 | })
|
89 | .option('svc-resolve-git-ref', {
|
90 | alias: 'svcResolveGitRef',
|
91 | describe: 'Service name for git-resolve-ref service',
|
92 | type: 'string',
|
93 | default: 'helix-services/resolve-git-ref@v1',
|
94 | })
|
95 | .option('updated-at', {
|
96 | alias: 'updatedAt',
|
97 | describe: 'Informative Unix timestamp for the deployed actions.',
|
98 | type: 'string',
|
99 | default: new Date().getTime(),
|
100 | })
|
101 | .option('updated-by', {
|
102 | alias: 'updatedBy',
|
103 | describe: 'Informative user name for the deployed actions.',
|
104 | type: 'string',
|
105 | })
|
106 | .group(['auto', 'wsk-auth', 'wsk-namespace', 'default', 'default-file', 'dirty'], 'Deployment Options')
|
107 | .group(['wsk-host', 'target', 'epsagon-app-name', 'epsagon-token', 'coralogix-app-name', 'coralogix-token'], 'Advanced Options')
|
108 | .group(['package', 'minify', 'target'], 'Package options')
|
109 | .check((args) => {
|
110 | if (!args.auto) {
|
111 |
|
112 | return true;
|
113 | }
|
114 | const message = 'Auto-deployment requires: ';
|
115 | const missing = [];
|
116 | if (!args.circleciAuth) {
|
117 | missing.push('--circleci-auth');
|
118 | }
|
119 | if (!args.fastlyAuth) {
|
120 | missing.push('--fastly-auth');
|
121 | }
|
122 | if (!args.fastlyNamespace) {
|
123 | missing.push('--fastly-namespace');
|
124 | }
|
125 | if (!args.wskAuth) {
|
126 | missing.push('--wsk-auth');
|
127 | }
|
128 | if (!args.wskNamespace) {
|
129 | missing.push('--wsk-namespace');
|
130 | }
|
131 | if (!args.wskHost) {
|
132 | missing.push('--wsk-host');
|
133 | }
|
134 | if (missing.length === 0) {
|
135 | return true;
|
136 | }
|
137 | return new Error(message + missing.join(', '));
|
138 | })
|
139 | .help();
|
140 | },
|
141 | handler: async (argv) => {
|
142 | if (!executor) {
|
143 |
|
144 | const DeployCommand = require('./deploy.cmd');
|
145 | executor = new DeployCommand(getOrCreateLogger(argv));
|
146 | }
|
147 |
|
148 | await executor
|
149 | .withEnableAuto(argv.auto)
|
150 | .withEnableDirty(argv.dirty)
|
151 | .withWskAuth(argv.wskAuth)
|
152 | .withWskHost(argv.wskHost)
|
153 | .withWskNamespace(argv.wskNamespace)
|
154 | .withWskActionMemory(argv.wskActionMemory)
|
155 | .withWskActionConcurrency(argv.wskActionConcurrency)
|
156 | .withTarget(argv.target)
|
157 | .withFiles(argv.files)
|
158 | .withDefault(argv.default)
|
159 | .withDefaultFile(argv.defaultFile)
|
160 | .withDryRun(argv.dryRun)
|
161 | .withCircleciAuth(argv.circleciAuth)
|
162 | .withFastlyAuth(argv.fastlyAuth)
|
163 | .withFastlyNamespace(argv.fastlyNamespace)
|
164 | .withCreatePackages(argv.package)
|
165 | .withAddStrain(argv.add)
|
166 | .withMinify(argv.minify)
|
167 | .withResolveGitRefService(argv.svcResolveGitRef)
|
168 | .withCustomPipeline(argv.customPipeline)
|
169 | .withEpsagonAppName(argv.epsagonAppName)
|
170 | .withEpsagonToken(argv.epsagonToken)
|
171 | .withCoralogixAppName(argv.coralogixAppName)
|
172 | .withCoralogixToken(argv.coralogixToken)
|
173 | .withUpdatedAt(argv.updatedAt)
|
174 | .withUpdatedBy(argv.updatedBy)
|
175 | .run();
|
176 | },
|
177 |
|
178 | };
|
179 | };
|