Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 687f686

Browse files
committed
support for blackbox actions
Fixes #46 Fixes #762
1 parent 4855c01 commit 687f686

File tree

4 files changed

+110
-26
lines changed

4 files changed

+110
-26
lines changed

app/content/js/ui.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,20 @@ const ui = (function() {
14081408
if (renderThirdParty(entity)) {
14091409
// then the third party rendering took care of it
14101410
} else {
1411-
if (entity.exec.code) {
1411+
// this is the container for the code
1412+
const code = sidecar.querySelector('.action-content .action-source')
1413+
1414+
if (entity.exec.kind === 'blackbox') {
1415+
// show the image name
1416+
const clicky = document.createElement('a')
1417+
clicky.className = 'clickable clickable-blatant'
1418+
code.appendChild(document.createTextNode('dockerhub image: '))
1419+
code.appendChild(clicky)
1420+
clicky.innerText = entity.exec.image
1421+
clicky.setAttribute('href', `https://hub.docker.com/r/${entity.exec.image}`)
1422+
clicky.setAttribute('target', '_blank')
1423+
1424+
} else if (entity.exec.code) {
14121425
//
14131426
// show the action's code
14141427
//
@@ -1417,7 +1430,6 @@ const ui = (function() {
14171430
//
14181431
// render the textual source code
14191432
//
1420-
const code = sidecar.querySelector('.action-content .action-source')
14211433

14221434
code.className = `action-source ${uiNameForKind(entity.exec.kind.substring(0, entity.exec.kind.indexOf(':')))}`
14231435
code.innerText = beautify(entity.exec.kind, entity.exec.code)

app/plugins/ui/commands/openwhisk-core.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -567,36 +567,44 @@ specials.actions = {
567567
} else if (verb !== 'update' || argv[0]) {
568568
// for action create, or update and the user gave a
569569
// positional param... find the input file
570-
const filepath = ui.findFile(expandHomeDir(argv[0])),
571-
isBinary = argv[0].endsWith('.zip'),
572-
encoding = isBinary ? 'base64' : 'utf8'
570+
if (options.docker) {
571+
// blackbox action!
572+
options.action.exec.kind = 'blackbox'
573+
options.action.exec.image = argv[0]
573574

574-
options.action.exec.code = fs.readFileSync(filepath).toString(encoding)
575+
} else {
576+
// otherwise, find the file named by argv[0]
577+
const filepath = ui.findFile(expandHomeDir(argv[0])),
578+
isBinary = argv[0].endsWith('.zip'),
579+
encoding = isBinary ? 'base64' : 'utf8'
575580

576-
if (!options.action.annotations) options.action.annotations = []
577-
options.action.annotations.push({ key: 'file', value: filepath })
581+
options.action.exec.code = fs.readFileSync(filepath).toString(encoding)
578582

579-
if (isBinary) {
580-
// add an annotation to indicate that this is a managed action
581-
options.action.annotations.push({ key: 'wskng.combinators', value: [{
582-
type: 'action.kind',
583-
role: 'replacement',
584-
badge: 'zip'
585-
}]})
583+
if (!options.action.annotations) options.action.annotations = []
584+
options.action.annotations.push({ key: 'file', value: filepath })
586585

587-
options.action.annotations.push({ key: 'binary', value: true })
588-
}
586+
if (isBinary) {
587+
// add an annotation to indicate that this is a managed action
588+
options.action.annotations.push({ key: 'wskng.combinators', value: [{
589+
type: 'action.kind',
590+
role: 'replacement',
591+
badge: 'zip'
592+
}]})
593+
594+
options.action.annotations.push({ key: 'binary', value: true })
595+
}
589596

590-
eventBus.emit('/action/update', { file: filepath, action: { name: options.name, namespace: options.namespace } })
597+
eventBus.emit('/action/update', { file: filepath, action: { name: options.name, namespace: options.namespace } })
591598

592-
// set the default kind
593-
if (!options.action.exec.kind) {
594-
if (options.kind) {
595-
options.action.exec.kind = options.kind
596-
} else {
597-
const extension = filepath.substring(filepath.lastIndexOf('.') + 1)
598-
if (extension) {
599-
options.action.exec.kind = extensionToKind[extension] || extension
599+
// set the default kind
600+
if (!options.action.exec.kind) {
601+
if (options.kind) {
602+
options.action.exec.kind = options.kind
603+
} else {
604+
const extension = filepath.substring(filepath.lastIndexOf('.') + 1)
605+
if (extension) {
606+
options.action.exec.kind = extensionToKind[extension] || extension
607+
}
600608
}
601609
}
602610
}

app/plugins/ui/commands/openwhisk-usage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const actionMix = params.concat(annotations).concat(limits).concat([
8484
{ name: '--kind', allowed: ['nodejs', 'python', 'swift', 'php'], allowedIsPrefixMatch: true, defaultValue: 'nodejs', docs: 'the action runtime' },
8585
{ name: '--sequence', boolean: true, example: 'a1,a2,a3', docs: 'create a sequence of the given actions' },
8686
{ name: '--copy', boolean: true, advanced: true, docs: 'copy the action named by the second parameter to a new action named by the first' },
87+
{ name: '--docker', boolean: true, docs: 'create a blackbox action from a dockerhub image' },
8788
{ name: '--web', boolean: true, docs: 'web export the action' },
8889
{ name: '--content-type', hidden: true }
8990
])
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2018 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const common = require('../../../lib/common'),
18+
openwhisk = require('../../../lib/openwhisk'),
19+
ui = require('../../../lib/ui'),
20+
assert = require('assert'),
21+
keys = ui.keys,
22+
cli = ui.cli,
23+
sidecar = ui.sidecar,
24+
actionName = 'foo',
25+
actionName2 = 'foo2'
26+
27+
describe('blackbox actions', function() {
28+
before(common.before(this))
29+
after(common.after(this))
30+
31+
it('should have an active repl', () => cli.waitForRepl(this.app))
32+
33+
it('should create a blackbox action variant 1', () => cli.do(`wsk action create --docker bb1 openwhisk/example`, this.app)
34+
.then(cli.expectOK)
35+
.then(sidecar.expectOpen)
36+
.then(sidecar.expectShowing('bb1'))
37+
.then(() => this.app.client.getText(ui.selectors.SIDECAR_ACTION_SOURCE))
38+
.then(txt => assert.equal(txt, 'dockerhub image: openwhisk/example'))
39+
.catch(common.oops(this)))
40+
41+
it('should create a blackbox action variant 2', () => cli.do(`wsk action create bb2 --docker openwhisk/example`, this.app)
42+
.then(cli.expectOK)
43+
.then(sidecar.expectOpen)
44+
.then(sidecar.expectShowing('bb2'))
45+
.catch(common.oops(this)))
46+
47+
it('should create a blackbox action variant 3', () => cli.do(`wsk action create bb3 openwhisk/example --docker`, this.app)
48+
.then(cli.expectOK)
49+
.then(sidecar.expectOpen)
50+
.then(sidecar.expectShowing('bb3'))
51+
.catch(common.oops(this)))
52+
53+
it(`should invoke bb2`, () => cli.do(`invoke bb2`, this.app)
54+
.then(cli.expectOK)
55+
.then(sidecar.expectOpen)
56+
.then(sidecar.expectShowing('bb2'))
57+
.then(() => this.app.client.getText(ui.selectors.SIDECAR_ACTIVATION_RESULT))
58+
.then(ui.expectStruct({
59+
"args": {},
60+
"msg": "Hello from arbitrary C program!"
61+
}))
62+
.catch(common.oops(this)))
63+
})

0 commit comments

Comments
 (0)