From 1d713072c78409b4f608c251f5c849d0d6105760 Mon Sep 17 00:00:00 2001 From: Alexander Klimetschek Date: Thu, 6 Feb 2020 22:57:13 -0800 Subject: [PATCH 1/3] support blackbox images --- src/runtime-helpers.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/runtime-helpers.js b/src/runtime-helpers.js index 4462aa73..9e8e02de 100644 --- a/src/runtime-helpers.js +++ b/src/runtime-helpers.js @@ -348,7 +348,7 @@ function checkWebFlags (flag) { function createActionObject (thisAction, objAction) { if (thisAction['function'].endsWith('.zip')) { - if (!thisAction['runtime']) { + if (!thisAction['runtime'] && !thisAction['docker']) { throw (new Error(`Invalid or missing property "runtime" in the manifest for this action: ${objAction.name}`)) } objAction.action = fs.readFileSync(thisAction['function']) @@ -356,13 +356,10 @@ function createActionObject (thisAction, objAction) { objAction.action = fs.readFileSync(thisAction['function'], { encoding: 'utf8' }) } - if (thisAction['runtime']) { - // thisAction['runtime'] = thisAction['runtime'].replace('@', ':') - Conflict in documentation - objAction['kind'] = thisAction['runtime'] - } - - if (thisAction['main']) { - objAction['exec'] = { main: thisAction['main'] } + objAction.exec = { + main: thisAction.main, + kind: thisAction.docker ? 'blackbox' : thisAction.runtime, + image: thisAction.docker } if (thisAction.limits) { @@ -600,7 +597,7 @@ async function deployPackage (entities, ow, logger) { logger(`Info: package [${pkg.name}] has been successfully deployed.\n`) } for (const action of entities.actions) { - if (action['exec'] && action['exec']['kind']) { + if (action['exec'] && action['exec']['kind'] === 'sequence') { action['exec']['components'] = action['exec']['components'].map(sequence => { /* Input => Output From 9af849b379f7fd1097ba75f6d6497bb3cf4d0613 Mon Sep 17 00:00:00 2001 From: Alexander Klimetschek Date: Wed, 26 Feb 2020 17:06:36 -0800 Subject: [PATCH 2/3] fix existing test cases --- src/runtime-helpers.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/runtime-helpers.js b/src/runtime-helpers.js index 9e8e02de..d626eb8f 100644 --- a/src/runtime-helpers.js +++ b/src/runtime-helpers.js @@ -356,10 +356,17 @@ function createActionObject (thisAction, objAction) { objAction.action = fs.readFileSync(thisAction['function'], { encoding: 'utf8' }) } - objAction.exec = { - main: thisAction.main, - kind: thisAction.docker ? 'blackbox' : thisAction.runtime, - image: thisAction.docker + if (thisAction.main || thisAction.docker || thisAction.runtime) { + objAction.exec = {} + if (thisAction.main) { + objAction.exec.main = thisAction.main + } + if (thisAction.docker) { + objAction.exec.kind = 'blackbox' + objAction.exec.image = thisAction.docker + } else if (thisAction.runtime) { + objAction.exec.kind = thisAction.runtime + } } if (thisAction.limits) { From fc20135743c8584c2c6fcf7aae3ea5645abfebc2 Mon Sep 17 00:00:00 2001 From: Alexander Klimetschek Date: Wed, 26 Feb 2020 17:15:55 -0800 Subject: [PATCH 3/3] add unit test for blackbox action --- test/__fixtures__/deploy/manifest_docker.yaml | 13 ++++++++++ test/commands/runtime/deploy/index.test.js | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/__fixtures__/deploy/manifest_docker.yaml diff --git a/test/__fixtures__/deploy/manifest_docker.yaml b/test/__fixtures__/deploy/manifest_docker.yaml new file mode 100644 index 00000000..a8d1ee1b --- /dev/null +++ b/test/__fixtures__/deploy/manifest_docker.yaml @@ -0,0 +1,13 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements; and to You under the Apache License, Version 2.0. + +# Example: Blackbox action with a custom docker image +packages: + demo_package: + actions: + sampleAction: + function: /deploy/main.js + main: split + web: false + docker: my/docker-image:1.0.0 + diff --git a/test/commands/runtime/deploy/index.test.js b/test/commands/runtime/deploy/index.test.js index 21e71ec8..07824593 100644 --- a/test/commands/runtime/deploy/index.test.js +++ b/test/commands/runtime/deploy/index.test.js @@ -96,6 +96,7 @@ describe('instance methods', () => { 'deploy/manifest_api.yaml': fixtureFile('deploy/manifest_api.yaml'), 'deploy/manifest_main.yaml': fixtureFile('deploy/manifest_main.yaml'), 'deploy/manifest_final.yaml': fixtureFile('deploy/manifest_final.yaml'), + 'deploy/manifest_docker.yaml': fixtureFile('deploy/manifest_docker.yaml'), 'deploy/manifest_api_incorrect.yaml': fixtureFile('deploy/manifest_api_incorrect.yaml'), 'deploy/deployment_syncMissingAction.yaml': fixtureFile('deploy/deployment_syncMissingAction.yaml'), 'deploy/manifest_multiple_packages.yaml': fixtureFile('deploy/manifest_multiple_packages.yaml'), @@ -359,6 +360,29 @@ describe('instance methods', () => { }) }) + test('deploys actions with docker image', () => { + const cmd = ow.mockResolved(owAction, '') + const mainAction = fixtureFile('deploy/main.js') + command.argv = ['-m', '/deploy/manifest_docker.yaml'] + return command.run() + .then(() => { + expect(cmd).toHaveBeenCalledWith({ + name: 'demo_package/sampleAction', + action: mainAction, + annotations: { + 'raw-http': false, + 'web-export': false + }, + exec: { + image: 'my/docker-image:1.0.0', + kind: 'blackbox', + main: 'split' + } + }) + expect(stdout.output).toMatch('') + }) + }) + test('deploys actions with manifest inputs when no actions present in deployment file', () => { const cmd = ow.mockResolved(owAction, '') command.argv = ['-m', '/deploy/manifest_dep.yaml', '--deployment', '/deploy/deployment_wrongTrigger.yaml']