Are you getting familiar with Apache OpenWhisk? Are you writing a simple JavaScript action with hello.js?


cat hello.js
function main() {
    return {payload:  'Hello World'};
}

Would you like to automate the deployment of this Hello World action?

If so, keep going with this post and I’ll show you how to use openwhisk-wskdeploy to automate deployment of the Hello World action.

Prerequisite

To complete the steps to automate deployment, you’ll need the following:

Step 1: Create a manifest file (manifest.yaml)

Use the following code to create your manifest file:


packages:
    helloworld:
        actions:
            helloworld:
                location: src/hello.js
                runtime: nodejs:6
                outputs:
                    payload:
                        type: string
                        description: a simple greeting message, Hello World.

Step 2: Create a deployment file (deployment.yaml)

Use the following code to create your deployment file:


application:
    name: SampleHelloWorld
    namespace: _
    packages:
        helloworld:
            actions:
                helloworld:

This deployment file is completely optional. You can deploy helloworld with just the manifest file you created in step 1.

Step 3: Set up your directory structure

Make sure you have directory structure similar to the following:


ls -1R ~/SampleHelloWorldApp/
deployment.yaml
manifest.yaml
src/

./src:
hello.js

Step 4: Deploy the Hello World action

To deploy Hello World, use the following code:


./wskdeploy -p ~/SampleHelloWorldApp/
         ____      ___                   _    _ _     _     _
        /\   \    / _ \ _ __   ___ _ __ | |  | | |__ (_)___| | __
   /\  /__\   \  | | | | '_ \ / _ \ '_ \| |  | | '_ \| / __| |/ /
  /  \____ \  /  | |_| | |_) |  __/ | | | |/\| | | | | \__ \   <
  \   \  /  \/    \___/| .__/ \___|_| |_|__/\__|_| |_|_|___/_|\_\
   \___\/              |_|

Packages:
Name: helloworld
  * action: helloworld
    bindings:


Triggers:

 Rules

Do you really want to deploy this? (y/N): y
Deploying package helloworld ... Done!
Deploying action helloworld/helloworld ... Done!

Deployment completed successfully.

Step 5: Verify your deployment

To verify your deployment, use the following:


wsk action invoke --blocking --result helloworld/helloworld
{
    "payload": "Hello World"
}

And that's all there is to it! It's fast, it's simple, and you'll be on your way with Apache OpenWhisk!

I hope you find this short guide useful. Watch for future posts where I'll outline more complex deployment automation with actions, triggers, and rules.

Join The Discussion

Your email address will not be published. Required fields are marked *