Whisk Deploy — Zip Actions with file Include & Exclude

Priti Desai
Oct 30, 2018 · 3 min read

This blog post is a follow up on a earlier post on how to create a zip action using Whisk Deploy.

OpenWhisk provides an ability to create an action using a .zip archive which can contain any number of action files including all dependencies. Whisk Deploy has a support to specify function pointing to a directory with action files for creating a .zip archive from the entire directory content and then creating a zip action.

File Level Include

$ cd actions/
$ ls -1 ./
common/
greeting1/
greeting2/
manifest.yaml
$ ls -1 common/
utils.js
$ ls -1 greeting1/
index.js
package.json
$ ls -1 greeting2/
index.js
package.json

Here, action file index.js under greeting1/ and action file index.js undergreeting2/ refers to the utils.js from common/.

index.js under actions/greeting1/:

index.js under actions/greeting2/:

manifest.yaml:

include:
- [source]
- [source, destination]

Note: (1)source is considered relative path to where manifest.yaml file is located. destination is considered relative path to the action directory i.e. actions/greeting1 and actions/greeting2 in the following example. (2) If destination is not specified, its considered same as source.

manifest.yaml

include can contain different combination of source and destination:

  • include with just source:
include:
- [actions/common/utils.js]

With this specification, utils.js will be copied under actions/greeting/actions/common/utils.js and can be referred to from index.js with:

var utils = require('./actions/common/utils.js')
  • include with rename:
include:
- ["actions/common/utils.js", "./common/myUtils.js"]

With this specification, utils.js will be copied as actions/greeting/common/myUtils.js and can be referred to from index.js with:

var utils = require('./common/myUtils.js')
  • include with different path:
include:
- ["actions/common/utils.js", "./common/utility/utils.js"]

With this specification, utils.js will be copied as actions/greeting/common/utility/utils.js and can be referred to from index.js with:

var utils = require('./common/utility/utils.js')
  • include with wild character *:
include:
- ["actions/common/*.js", "./common/"]

With this specification, utils.js and any other file with .js extension will be copied under actions/greeting/common/ and can be referred to from index.js with:

var utils = require('./common/utils.js')

Directory Level Include

$ cd actions/
$ ls -1
libs/
greeting3/
manifest.yaml
$ ls -1 libs/
lib1/
lib2/
lib3/
$ ls -1 libs/lib1/
utils.js
$ ls -1 libs/lib2/
utils.js
$ ls -1 libs/lib3/
utils.js
$ ls -1 greeting3/
index.js
package.json

index.js under actions/greeting3/:

manifest.yaml under actions/:

manifest.yaml

Here, the entire libs dir is recursively copied to actions/greeting3/libs/.

  • include with wild character *:

Example 1:

include:
- ["actions/libs/*/utils.js", "libs/"]

With this specification, utils.js file under any directory within libs will be copied under libs/ and can be referred to from index.js similar to the above example:

var lib1 = require('./libs/lib1/utils.js')
var lib2 = require('./libs/lib2/utils.js')
var lib3 = require('./libs/lib3/utils.js')

Example 2:

include:
- ["actions/*/*/utils.js"]

With this specification, utils.js file within two directories under actions will be copied under actions/ and can be referred to from index.js with:

var lib1 = require('./actions/libs/lib1/utils.js')
var lib2 = require('./actions/libs/lib2/utils.js')
var lib3 = require('./actions/libs/lib3/utils.js')

Example 3:

include:
- ["actions/*/*/utils.js", "actions/"]

With this specification, utils.js file within two directories under actions will be copied under actions/ and can be referred to from index.js with:

var lib1 = require('./actions/libs/lib1/utils.js')
var lib2 = require('./actions/libs/lib2/utils.js')
var lib3 = require('./actions/libs/lib3/utils.js')

Exclude

exclude:
- actions/common/*.js
- actions/libs/*/utils.js

Here is a very common usage of combination of include and exclude:

manifest.yaml:

Good Luck 👍!

Apache OpenWhisk

Apache OpenWhisk is a serverless cloud platform that…

Priti Desai

Written by

Developer Advocate @IBM. Implements #serverless with @openwhisk, @knative, & @tekton.

Apache OpenWhisk

Apache OpenWhisk is a serverless cloud platform that executes code in response to events

Priti Desai

Written by

Developer Advocate @IBM. Implements #serverless with @openwhisk, @knative, & @tekton.

Apache OpenWhisk

Apache OpenWhisk is a serverless cloud platform that executes code in response to events

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store