@adobe/aio-cli-plugin-app 13.2.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -37
- package/oclif.manifest.json +73 -54
- package/package.json +4 -8
- package/src/TemplatesCommand.js +1 -1
- package/src/commands/app/build.js +1 -1
- package/src/commands/app/clean-build.js +110 -0
- package/src/commands/app/config/set/log-forwarding.js +7 -1
- package/src/commands/app/deploy.js +8 -4
- package/src/commands/app/get-url.js +4 -14
- package/src/commands/app/init.js +1 -1
- package/src/commands/app/run.js +1 -17
- package/src/commands/app/undeploy.js +4 -1
- package/src/lib/actions-watcher.js +1 -3
- package/src/lib/app-helper.js +0 -117
- package/src/lib/audit-logger.js +0 -1
- package/src/lib/auth-helper.js +63 -0
- package/src/lib/defaults.js +4 -1
- package/src/lib/run-dev.js +6 -23
- package/bin/openwhisk-standalone-config/get-runtimes.js +0 -55
- package/bin/openwhisk-standalone-config/runtimes.json +0 -55
- package/src/lib/owlocal.js +0 -86
- package/src/lib/run-local-runtime.js +0 -154
- package/src/lib/vscode.js +0 -85
package/src/lib/owlocal.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 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
|
-
const path = require('path')
|
|
14
|
-
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:owlocal', { provider: 'debug' })
|
|
15
|
-
const execa = require('execa')
|
|
16
|
-
const url = require('url')
|
|
17
|
-
|
|
18
|
-
const OW_LOCAL_DOCKER_PORT = 3233
|
|
19
|
-
|
|
20
|
-
/** @private */
|
|
21
|
-
function isWindowsOrMac () {
|
|
22
|
-
return (
|
|
23
|
-
process.platform === 'win32' ||
|
|
24
|
-
process.platform === 'darwin'
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** @private */
|
|
29
|
-
function owJarPath (owJarUrl) {
|
|
30
|
-
const { pathname } = new url.URL(owJarUrl)
|
|
31
|
-
const idx = pathname.indexOf('/openwhisk/')
|
|
32
|
-
let jarPath
|
|
33
|
-
|
|
34
|
-
if (idx === -1) {
|
|
35
|
-
jarPath = path.join('openwhisk', 'openwhisk-standalone.jar') // default path
|
|
36
|
-
aioLogger.warn(`Could not parse openwhisk jar path from ${owJarUrl}, using default ${jarPath}`)
|
|
37
|
-
} else {
|
|
38
|
-
jarPath = pathname
|
|
39
|
-
.substring(idx + 1) // skip initial forward slash
|
|
40
|
-
.split(path.posix.sep) // split on forward slashes
|
|
41
|
-
.join(path.sep) // join on os path separator (for Windows)
|
|
42
|
-
aioLogger.debug(`Parsed openwhisk jar path from ${owJarUrl}, using ${jarPath}`)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return jarPath
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** @private */
|
|
49
|
-
function getDockerNetworkAddress () {
|
|
50
|
-
try {
|
|
51
|
-
// Docker for Windows and macOS do not allow routing to the containers via
|
|
52
|
-
// IP address, only port forwarding is allowed
|
|
53
|
-
if (!isWindowsOrMac()) {
|
|
54
|
-
const args = ['network', 'inspect', 'bridge']
|
|
55
|
-
const result = execa.sync('docker', args)
|
|
56
|
-
const json = JSON.parse(result.stdout)
|
|
57
|
-
return `http://${json[0].IPAM.Config[0].Gateway}:${OW_LOCAL_DOCKER_PORT}`
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
aioLogger.debug(`getDockerNetworkAddress ${error}`)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return `http://localhost:${OW_LOCAL_DOCKER_PORT}`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// gets these values if the keys are set in the environment, if not it will use the defaults set
|
|
67
|
-
const {
|
|
68
|
-
OW_JAR_URL = 'https://github.com/adobe/aio-cli-plugin-app/releases/download/6.2.0/openwhisk-standalone.jar',
|
|
69
|
-
OW_CONFIG_RUNTIMES_FILE = path.resolve(__dirname, '../../bin/openwhisk-standalone-config/runtimes.json'),
|
|
70
|
-
OW_LOCAL_APIHOST = getDockerNetworkAddress(),
|
|
71
|
-
OW_LOCAL_NAMESPACE = 'guest',
|
|
72
|
-
OW_LOCAL_AUTH = '23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP',
|
|
73
|
-
OW_LOCAL_LOG_FILE
|
|
74
|
-
} = process.env
|
|
75
|
-
|
|
76
|
-
module.exports = {
|
|
77
|
-
getDockerNetworkAddress,
|
|
78
|
-
OW_LOCAL_DOCKER_PORT,
|
|
79
|
-
OW_JAR_URL,
|
|
80
|
-
OW_JAR_PATH: owJarPath(OW_JAR_URL),
|
|
81
|
-
OW_CONFIG_RUNTIMES_FILE,
|
|
82
|
-
OW_LOCAL_APIHOST,
|
|
83
|
-
OW_LOCAL_NAMESPACE,
|
|
84
|
-
OW_LOCAL_AUTH,
|
|
85
|
-
OW_LOCAL_LOG_FILE
|
|
86
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 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
|
-
const path = require('path')
|
|
14
|
-
const fs = require('fs-extra')
|
|
15
|
-
const cloneDeep = require('lodash.clonedeep')
|
|
16
|
-
const utils = require('./app-helper')
|
|
17
|
-
const dedent = require('dedent-js')
|
|
18
|
-
const rtLib = require('@adobe/aio-lib-runtime')
|
|
19
|
-
const rtLibUtils = rtLib.utils
|
|
20
|
-
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:run-dev-local', { provider: 'debug' })
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
OW_CONFIG_RUNTIMES_FILE,
|
|
24
|
-
OW_JAR_URL, OW_JAR_PATH,
|
|
25
|
-
OW_LOCAL_APIHOST,
|
|
26
|
-
OW_LOCAL_NAMESPACE,
|
|
27
|
-
OW_LOCAL_AUTH,
|
|
28
|
-
OW_LOCAL_LOG_FILE
|
|
29
|
-
} = require('../lib/owlocal')
|
|
30
|
-
|
|
31
|
-
const OW_WAIT_INIT_TIME = 2000
|
|
32
|
-
const OW_WAIT_PERIOD_TIME = 500
|
|
33
|
-
const OW_TIMEOUT = 60000
|
|
34
|
-
|
|
35
|
-
const LOCAL_RUNTIME = {
|
|
36
|
-
namespace: OW_LOCAL_NAMESPACE,
|
|
37
|
-
auth: OW_LOCAL_AUTH,
|
|
38
|
-
apihost: OW_LOCAL_APIHOST
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @typedef {object} RunDevLocalObject
|
|
43
|
-
* @property {string} config the modified dev config
|
|
44
|
-
* @property {Function} cleanup callback function to cleanup available resources
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @typedef {object} RuntimeCredentials
|
|
49
|
-
* @property {string} namespace the runtime namespace
|
|
50
|
-
* @property {string} auth the runtime auth key
|
|
51
|
-
* @property {string} apihost the runtime apihost
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Checks the system for pre-requisites to run local Openwhisk, then runs it.
|
|
56
|
-
*
|
|
57
|
-
* @param {object} config the app config
|
|
58
|
-
* @param {object} dataDir global config folder to store the ow jar
|
|
59
|
-
* @param {Function} [log] function to log application logs
|
|
60
|
-
* @param {boolean} [verbose=false] set to true to have verbose logging (openwhisk)
|
|
61
|
-
* @returns {RunDevLocalObject} the RunDevLocalObject
|
|
62
|
-
*/
|
|
63
|
-
async function runDevLocal (config, dataDir, log = () => undefined, verbose = false) {
|
|
64
|
-
const owJarFile = path.join(dataDir, OW_JAR_PATH)
|
|
65
|
-
const devConfig = loadLocalDevConfig(config)
|
|
66
|
-
|
|
67
|
-
// take following steps only when we have a backend
|
|
68
|
-
log('checking if java is installed...')
|
|
69
|
-
if (!await utils.hasJavaCLI()) {
|
|
70
|
-
throw new Error('could not find java CLI, please make sure java is installed')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
log('checking if docker is installed...')
|
|
74
|
-
if (!await utils.hasDockerCLI()) {
|
|
75
|
-
throw new Error('could not find docker CLI, please make sure docker is installed')
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
log('checking if docker is running...')
|
|
79
|
-
if (!await utils.isDockerRunning()) {
|
|
80
|
-
throw new Error('docker is not running, please make sure to start docker')
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!fs.existsSync(owJarFile)) {
|
|
84
|
-
log(`downloading OpenWhisk standalone jar from ${OW_JAR_URL} to ${owJarFile}, this might take a while... (to be done only once!)`)
|
|
85
|
-
await utils.downloadOWJar(OW_JAR_URL, owJarFile)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
log('starting local OpenWhisk stack...')
|
|
89
|
-
const owLocalLogFile = OW_LOCAL_LOG_FILE || path.join(config.app.dist, 'openwhisk-local.log.txt')
|
|
90
|
-
const owExecaOptions = {
|
|
91
|
-
stdio: [
|
|
92
|
-
null, // stdin
|
|
93
|
-
verbose ? fs.openSync(owLocalLogFile, 'w') : null, // stdout
|
|
94
|
-
'inherit' // stderr
|
|
95
|
-
]
|
|
96
|
-
}
|
|
97
|
-
const res = await utils.runOpenWhiskJar(owJarFile, OW_CONFIG_RUNTIMES_FILE, OW_LOCAL_APIHOST, OW_WAIT_INIT_TIME, OW_WAIT_PERIOD_TIME, OW_TIMEOUT, owExecaOptions)
|
|
98
|
-
|
|
99
|
-
log(`writing credentials to tmp wskdebug config '${devConfig.envFile}'`)
|
|
100
|
-
await writeLocalEnvFile(devConfig, LOCAL_RUNTIME)
|
|
101
|
-
|
|
102
|
-
const cleanup = () => {
|
|
103
|
-
aioLogger.debug('stopping local OpenWhisk stack...')
|
|
104
|
-
res.proc.kill()
|
|
105
|
-
|
|
106
|
-
aioLogger.debug('removing wskdebug tmp .env file...')
|
|
107
|
-
if (fs.existsSync(devConfig.envFile)) {
|
|
108
|
-
fs.unlinkSync(devConfig.envFile)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
config: devConfig,
|
|
114
|
-
cleanup
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @param {object} config the app config
|
|
120
|
-
* @param {Function} [log] function to log application logs
|
|
121
|
-
* @returns {RunDevLocalObject} the RunDevLocalObject
|
|
122
|
-
*/
|
|
123
|
-
function loadLocalDevConfig (config, log) {
|
|
124
|
-
const devConfig = cloneDeep(config)
|
|
125
|
-
devConfig.envFile = path.join(config.app.dist, '.env.local')
|
|
126
|
-
log && log('setting local openwhisk credentials...')
|
|
127
|
-
devConfig.ow = { ...devConfig.ow, ...LOCAL_RUNTIME }
|
|
128
|
-
return devConfig
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Writes the local debugging .env file
|
|
133
|
-
*
|
|
134
|
-
* @param {object} appConfig the app config
|
|
135
|
-
* @param {RuntimeCredentials} runtimeCredentials the runtime credentials
|
|
136
|
-
*/
|
|
137
|
-
async function writeLocalEnvFile (appConfig, runtimeCredentials) {
|
|
138
|
-
const { root, envFile } = appConfig
|
|
139
|
-
const { dist } = appConfig.app
|
|
140
|
-
const { namespace, auth, apihost } = runtimeCredentials
|
|
141
|
-
|
|
142
|
-
fs.ensureDirSync(dist)
|
|
143
|
-
const envFilePath = rtLibUtils._absApp(root, envFile)
|
|
144
|
-
|
|
145
|
-
await fs.outputFile(envFilePath, dedent(`
|
|
146
|
-
# This file is auto-generated, do not edit.
|
|
147
|
-
# The items below are temporary credentials for local debugging
|
|
148
|
-
OW_NAMESPACE=${namespace}
|
|
149
|
-
OW_AUTH=${auth}
|
|
150
|
-
OW_APIHOST=${apihost}
|
|
151
|
-
`))
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
module.exports = { runLocalRuntime: runDevLocal, loadLocalDevConfig }
|
package/src/lib/vscode.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 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
|
-
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:vscode', { provider: 'debug' })
|
|
14
|
-
const rtLibUtils = require('@adobe/aio-lib-runtime').utils
|
|
15
|
-
const fs = require('fs-extra')
|
|
16
|
-
const path = require('path')
|
|
17
|
-
const yeoman = require('yeoman-environment')
|
|
18
|
-
const generators = require('@adobe/generator-aio-app')
|
|
19
|
-
|
|
20
|
-
const LAUNCH_JSON_FILE = '.vscode/launch.json'
|
|
21
|
-
const LAUNCH_JSON_FILE_BACKUP = '.vscode/launch.json.save'
|
|
22
|
-
|
|
23
|
-
/** @private */
|
|
24
|
-
function files (config) {
|
|
25
|
-
return () => ({
|
|
26
|
-
backupFile: rtLibUtils._absApp(config.root, LAUNCH_JSON_FILE_BACKUP),
|
|
27
|
-
mainFile: rtLibUtils._absApp(config.root, LAUNCH_JSON_FILE)
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** @private */
|
|
32
|
-
function update (config) {
|
|
33
|
-
const _files = files(config)
|
|
34
|
-
return async (props) => {
|
|
35
|
-
const { backupFile, mainFile } = _files()
|
|
36
|
-
|
|
37
|
-
fs.ensureDirSync(path.dirname(mainFile))
|
|
38
|
-
if (fs.existsSync(mainFile)) {
|
|
39
|
-
if (!fs.existsSync(backupFile)) {
|
|
40
|
-
fs.moveSync(mainFile, backupFile)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const env = yeoman.createEnv()
|
|
45
|
-
// by default yeoman runs the install, we control installation from the app plugin
|
|
46
|
-
env.options = { skipInstall: true }
|
|
47
|
-
const gen = env.instantiate(generators['add-vscode-config'], {
|
|
48
|
-
options: {
|
|
49
|
-
'app-config': config,
|
|
50
|
-
'env-file': config.envFile,
|
|
51
|
-
'frontend-url': props.frontEndUrl,
|
|
52
|
-
'skip-prompt': true
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
await env.runGenerator(gen)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** @private */
|
|
60
|
-
function cleanup (config) {
|
|
61
|
-
const _files = files(config)
|
|
62
|
-
return () => {
|
|
63
|
-
const { backupFile, mainFile } = _files()
|
|
64
|
-
|
|
65
|
-
if (fs.existsSync(mainFile) && !fs.existsSync(backupFile)) {
|
|
66
|
-
aioLogger.debug(`removing ${mainFile}...`)
|
|
67
|
-
const vscodeDir = path.dirname(mainFile)
|
|
68
|
-
fs.unlinkSync(mainFile)
|
|
69
|
-
if (fs.readdirSync(vscodeDir).length === 0) {
|
|
70
|
-
fs.rmdirSync(vscodeDir)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (fs.existsSync(backupFile)) {
|
|
75
|
-
aioLogger.debug(`restoring previous ${mainFile}`)
|
|
76
|
-
fs.moveSync(backupFile, mainFile, { overwrite: true })
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports = (config) => ({
|
|
82
|
-
files: files(config),
|
|
83
|
-
update: update(config),
|
|
84
|
-
cleanup: cleanup(config)
|
|
85
|
-
})
|