Taxonomy Icon

Serverless

This tutorial discusses how to sync OpenWhisk projects between client and server using Whisk Deploy in managed deployment mode. Whisk Deploy is a utility to deploy OpenWhisk projects using a manifest file written in YAML. It deploys OpenWhisk entities including Packages, Actions, Sequences, Triggers, and Rules using a single wskdeploy command. You can refer to a companion video on syncing OpenWhisk projects.

Learning objectives

By following this tutorial, you learn how to:

  • Use the wskdeploy CLI to sync projects.

Prerequisites

To follow this tutorial, you need:

Estimated time

  • Completing the steps in this tutorial should take around 30 minutes.

Steps

Brief introduction to Whisk Deploy

Whisk Deploy, in managed deployment mode, deploys all OpenWhisk entities from the manifest file and attaches a hidden annotation called managed to all entities from that manifest file. The managed annotation contains following keys:

managed:
    __OW_PROJECT_NAME: MyProjectName
    __OW_PROJECT_HASH: SHA1("OpenWhisk " + <size_of_manifest_file> + "\0" + <contents_of_manifest_file>)
    __OW_FILE: Absolute path of manifest file on file system

Note: Where the text &OpenWhisk& is a constant prefix and &\0& is the NULL character. The <size_of_manifest_file> and <contents_of_manifest_file> vary depending on the file.

Now, subsequent deployments of the same project in managed deployment mode, calculates a new __OW_PROJECT_HASH on client and compares it with the __OW_PROJECT_HASH of each entity on the OpenWhisk server in that project.

  • Scenario 1: If __OW_PROJECT_HASH on client is same as __OW_PROJECT_HASH on the server i.e. there were no changes in the project on the client side, the project on server side is left as is except wskdeploy redeploys all the entities from manifest file to capture any changes in deployment file.

  • Scenario 2: If __OW_PROJECT_HASH on client is different from __OW_PROJECT_HASH on the server i.e. there were some changes in the project on the client side, wskdeploy redeploys all the entities from the manifest file on the client and updates their __OW_PROJECT_HASH on the server. wskdeploy also searches all the entities including actions, sequences, and triggers which has the same __OW_PROJECT_NAME i.e. it belonged to the same project but has different __OW_PROJECT_HASH i.e. its been deleted from the manifest file on the client.

Project name in the manifest file is mandatory to sync that project between the client and the server:

project:
    name: MyProjectName
    packages:
        package1:
            ....

OpenWhisk entities which are deployed using some other tool or automation and were part of the same project but has been deleted from that project now, are left unmodified. These kind of entities are classified as external entities and are not overwritten.

Undeployment of such project can be driven by wskdeploy with the manifest file having only project name.

project:
    name: MyProjectName

Lets look at a sample project to understand managed deployment. Whisk Deploy GitHub repo has a sample project with many different manifest files to demonstrate managed deployment.

Deploy MyFirstManagedProject using managed deployment

$wskdeploy -m tests/src/integration/managed-deployment/manifest.yaml --managed
Deployment completed successfully.

Here is a list of entities deployed on OpenWhisk Server:

Sync Client and Server — Deleting ManagedPackage-2

./wskdeploy -m tests/src/integration/managed-deployment/00-manifest-minus-second-package.yaml --managed
Deployment completed successfully.

Here is a list of entities deployed on OpenWhisk Server:

Sync Client and Server — Deleting Sequence ManagedSequence-2

./wskdeploy -m tests/src/integration/managed-deployment/01-manifest-minus-sequence-2.yaml --managed
Deployment completed successfully.

Here is a list of entities deployed on OpenWhisk Server:

Sync Client and Server — Deleting Action Helloworld-3

./wskdeploy -m tests/src/integration/managed-deployment/02-manifest-minus-action-3.yaml --managed
Deployment completed successfully.

Here is a list of entities deployed on OpenWhisk Server:

Sync Client and Server — Deleting ManagedPackage-1

./wskdeploy -m tests/src/integration/managed-deployment/04-manifest-minus-package.yaml --managed
Deployment completed successfully.

Here is a list of entities deployed on OpenWhisk Server:

Summary

In this guide, you learned how to use the wskdeploy tool to sync our OpenWhisk projects. Enjoy!