UNPKG

6.01 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12
13'use strict';
14
15const yargsOpenwhisk = require('./yargs-openwhisk.js');
16const yargsFastly = require('./yargs-fastly.js');
17const yargsGithub = require('./yargs-github.js');
18const yargsAlgolia = require('./yargs-algolia.js');
19const yargsEpsagon = require('./yargs-epsagon.js');
20const yargsCoralogix = require('./yargs-coralogix.js');
21const { getOrCreateLogger } = require('./log-common.js');
22
23module.exports = function strain() {
24 let executor;
25
26 return {
27 set executor(value) {
28 executor = value;
29 },
30 command: ['publish'],
31 desc: 'Activate strains in the Fastly CDN and publish the site.',
32 builder: (yargs) => {
33 yargsOpenwhisk(yargs);
34 yargsFastly(yargs);
35 yargsGithub(yargs);
36 yargsAlgolia(yargs);
37 yargsEpsagon(yargs);
38 yargsCoralogix(yargs);
39 yargs
40 .option('dry-run', {
41 alias: 'dryRun',
42 describe: 'List the actions that would be created, but do not actually deploy.',
43 type: 'boolean',
44 default: false,
45 })
46 .option('api-publish', {
47 alias: 'apiPublish',
48 describe: 'API URL for helix-publish service.',
49 type: 'string',
50 default: 'https://adobeioruntime.net/api/v1/web/helix/helix-services/publish@v7',
51 })
52 .option('api-config-purge', {
53 alias: 'apiConfigPurge',
54 describe: 'API URL for helix bot config service.',
55 type: 'string',
56 default: 'https://app.project-helix.io/config/purge',
57 })
58 .option('update-bot-config', {
59 alias: 'updateBotConfig',
60 describe: 'Update the helix bot configuration on the affected content repositories.',
61 type: 'boolean',
62 })
63 .option('only', {
64 describe: 'Only publish strains with names following the specified pattern, use config from master branch for all others.',
65 type: 'string',
66 })
67 .option('exclude', {
68 describe: 'Don\'t publish strains with names following the specified pattern, use config from master branch instead.',
69 type: 'string',
70 })
71 .option('custom-vcl', {
72 alias: 'customVCL',
73 describe: 'Path(s) to VCL file(s) to override the orginal one(s).',
74 type: 'string',
75 array: true,
76 default: [],
77 })
78 .option('dispatch-version', {
79 alias: 'dispatchVersion',
80 describe: 'Version of the dispatch action to use.',
81 type: 'string',
82 })
83 .option('purge', {
84 describe: 'How to purge the cache after deployment',
85 choices: ['soft', 'hard', 'skip'],
86 default: 'soft',
87 })
88 .option('debug-key', {
89 alias: 'debugKey',
90 describe: 'The key to enable the X-Debug header (default is the fastly service id)',
91 default: '',
92 type: 'string',
93 })
94 .conflicts('only', 'exclude')
95 .demandOption(
96 'fastly-auth',
97 'Authentication is required. You can pass the key via the HLX_FASTLY_AUTH environment variable, too.',
98 )
99 .demandOption(
100 'fastly-serviceid',
101 'Fastly Service ID is required.',
102 )
103 .check((args) => {
104 if (args.githubToken && args.updateBotConfig === undefined) {
105 // eslint-disable-next-line no-param-reassign
106 args.updateBotConfig = true;
107 } else if (args.updateBotConfig && !args.githubToken) {
108 return new Error('Github token is required in order to update bot config.\n'
109 + 'Provide one via --github-token or via the HLX_GITHUB_TOKEN environment variable.\n'
110 + 'You can use `hlx auth` to automatically obtain a new token.');
111 }
112 return true;
113 })
114 .group(['wsk-auth', 'wsk-namespace', 'fastly-auth', 'fastly-serviceid'], 'Deployment Options')
115 .group(['wsk-host', 'dry-run', 'epsagon-app-name', 'epsagon-token', 'coralogix-app-name', 'coralogix-token'], 'Advanced Options')
116 .group(['github-token', 'update-bot-config'], 'Helix Bot Options')
117 .help();
118 },
119 handler: async (argv) => {
120 if (!executor) {
121 // eslint-disable-next-line global-require
122 const RemotePublish = require('./remotepublish.cmd'); // lazy load the handler to speed up execution time
123 executor = new RemotePublish(getOrCreateLogger(argv));
124 }
125
126 await executor
127 .withWskAuth(argv.wskAuth)
128 .withWskHost(argv.wskHost)
129 .withWskNamespace(argv.wskNamespace)
130 .withFastlyNamespace(argv.fastlyNamespace)
131 .withDebugKey(argv.debugKey)
132 .withFastlyAuth(argv.fastlyAuth)
133 .withDryRun(argv.dryRun)
134 .withPublishAPI(argv.apiPublish)
135 .withGithubToken(argv.githubToken)
136 .withUpdateBotConfig(argv.updateBotConfig)
137 .withConfigPurgeAPI(argv.apiConfigPurge)
138 .withFilter(argv.only, argv.exclude)
139 .withCustomVCLs(argv.customVCL)
140 .withDispatchVersion(argv.dispatchVersion)
141 .withPurge(argv.purge)
142 .withAlgoliaAppID(argv.algoliaAppId)
143 .withAlgoliaAPIKey(argv.algoliaApiKey)
144 .withEpsagonAppName(argv.epsagonAppName)
145 .withEpsagonToken(argv.epsagonToken)
146 .withCoralogixAppName(argv.coralogixAppName)
147 .withCoralogixToken(argv.coralogixToken)
148 .run();
149 },
150 };
151};