|
| 1 | +# @ibm-functions/composer |
| 2 | + |
1 | 3 | [](https://travis-ci.org/ibm-functions/composer)
|
2 | 4 | [](https://opensource.org/licenses/Apache-2.0)
|
3 |
| -[](http://slack.openwhisk.org/) |
| 5 | +[](http://slack.openwhisk.org/) |
4 | 7 |
|
5 | 8 | Composer is a new programming model from [IBM
|
6 |
| -Research](https://ibm.biz/serverless-research) for composing [IBM |
7 |
| -Cloud Functions](https://ibm.biz/openwhisk), built on [Apache |
8 |
| -OpenWhisk](https://github.com/apache/incubator-openwhisk). |
9 |
| -With composer, developers can build even more serverless applications including using it for IoT, with workflow |
10 |
| -orchestration, conversation services, and devops automation, to name a |
11 |
| -few examples. |
| 9 | +Research](https://ibm.biz/serverless-research) for composing [IBM Cloud |
| 10 | +Functions](https://ibm.biz/openwhisk), built on [Apache |
| 11 | +OpenWhisk](https://github.com/apache/incubator-openwhisk). With Composer, |
| 12 | +developers can build even more serverless applications including using it for |
| 13 | +IoT, with workflow orchestration, conversation services, and devops automation, |
| 14 | +to name a few examples. |
| 15 | + |
| 16 | +Programming compositions for IBM Cloud Functions is supported by a new developer |
| 17 | +tool called [IBM Cloud Shell](https://github.com/ibm-functions/shell), or just |
| 18 | +_Shell_. Shell offers a CLI and graphical interface for fast, incremental, |
| 19 | +iterative, and local development of serverless applications. While we recommend |
| 20 | +using Shell, Shell is not required to work with compositions. Compositions may |
| 21 | +be managed using a combination of the Composer [compose](bin/compose) shell |
| 22 | +script (for deployment) and the [OpenWhisk |
| 23 | +CLI](https://console.bluemix.net/openwhisk/learn/cli) (for configuration, |
| 24 | +invocation, and life-cycle management). |
12 | 25 |
|
13 |
| -Programming compositions for IBM Cloud Functions is done via a new developer tool called [IBM Cloud Shell](https://github.com/ibm-functions/shell), or just _Shell_. Shell offers a CLI and graphical interface for fast, incremental, iterative, and local development of serverless apps. Composer and shell are currently available as IBM Research previews. We are excited about both and are looking forward to the compositions you build and run using [IBM CloudFunctions](https://ibm.biz/openwhisk) or directly on [Apache |
14 |
| -OpenWhisk](https://github.com/apache/incubator-openwhisk). |
| 26 | +**In contrast to earlier releases of Composer, a REDIS server is not required to |
| 27 | +run compositions**. Composer now synthesizes OpenWhisk [conductor |
| 28 | +actions](https://github.com/apache/incubator-openwhisk/blob/master/docs/conductors.md) |
| 29 | +to implement compositions. Compositions have all the attributes and capabilities |
| 30 | +of an action (e.g., default parameters, limits, blocking invocation, web |
| 31 | +export). |
15 | 32 |
|
16 | 33 | This repository includes:
|
17 |
| -* a [composer](composer.js) node.js module to author compositions using JavaScript |
18 |
| -* a [compose](bin/compose) shell script for deploying compositions, |
19 |
| -* a [tutorial](docs/README.md) for getting started, |
20 |
| -* a [reference manual](docs/COMPOSER.md), |
21 |
| -* example compositions in the [samples](samples) folder, |
22 |
| -* tests in the [test](test) folder. |
| 34 | +* the [composer](composer.js) Node.js module for authoring compositions using |
| 35 | + JavaScript, |
| 36 | +* the [compose](bin/compose) shell script for deploying compositions, |
| 37 | +* [documentation](docs), [examples](samples), and [tests](test). |
| 38 | + |
| 39 | +Composer and Shell are currently available as _IBM Research previews_. As |
| 40 | +Composer and Shell continue to evolve, it may be necessary to redeploy existing |
| 41 | +compositions to take advantage of new capabilities. However existing |
| 42 | +compositions should continue to run fine without redeployment. |
| 43 | + |
| 44 | +## Installation |
| 45 | + |
| 46 | +To install the `composer` module use the Node Package Manager: |
| 47 | +``` |
| 48 | +npm -g install @ibm-functions/composer |
| 49 | +``` |
| 50 | +We recommend to install the module globally (with `-g` option) so the `compose` |
| 51 | +command is added to the path. Otherwise, it can be found in the `bin` folder of |
| 52 | +the module installation. |
| 53 | + |
| 54 | +## Example |
| 55 | + |
| 56 | +A composition is typically defined by means of a Javascript file as illustrated |
| 57 | +in [samples/demo.js](samples/demo.js): |
| 58 | +```javascript |
| 59 | +composer.if( |
| 60 | + composer.action('authenticate', { action: function main({ password }) { return { value: password === 'abc123' } } }), |
| 61 | + composer.action('success', { action: funcßtion main() { return { message: 'success' } } }), |
| 62 | + composer.action('failure', { action: function main() { return { message: 'failure' } } })) |
| 63 | +``` |
| 64 | +Composer offers traditional control-flow concepts as methods. These methods |
| 65 | +are called _combinators_. This example composition composes three actions named |
| 66 | +`authenticate`, `success`, and `failure` using the `composer.if` combinator, |
| 67 | +which implements the usual conditional construct. It take three actions (or |
| 68 | +compositions) as parameters. It invokes the first one and, depending on the |
| 69 | +result of this invocation, invokes either the second or third action. |
| 70 | + |
| 71 | + This composition includes the definitions of the three composed actions. If the |
| 72 | + actions are defined and deployed elsewhere, the composition code can be shorten |
| 73 | + to: |
| 74 | +```javascript |
| 75 | +composer.if('authenticate', 'success', 'failure') |
| 76 | +``` |
| 77 | + |
| 78 | +To deploy this composition use the `compose` command: |
| 79 | +``` |
| 80 | +compose demo.js --deploy demo |
| 81 | +``` |
| 82 | +The `compose` command synthesizes and deploy an action named `demo` that |
| 83 | +implements the composition. It also deploys the composed actions if definitions |
| 84 | +are provided for them. |
| 85 | + |
| 86 | +The `demo` composition may be invoked like any action, for instance using the |
| 87 | +OpenWhisk CLI: |
| 88 | +``` |
| 89 | +wsk action invoke demo -r -p password passw0rd |
| 90 | +``` |
| 91 | +``` |
| 92 | +{ |
| 93 | + message: "failure" |
| 94 | +} |
| 95 | +``` |
23 | 96 |
|
24 | 97 | ## Getting started
|
25 |
| -* [Introduction to Serverless Composition](docs/README.md): Setting up your programming environment and getting started with Shell and Composer |
26 |
| -* [Building a Serverless Translate Bot with Composition](docs/tutorials/translateBot/README.md): A more advanced tutorial that describes using Composition to build a serverless Slack chatbot that does language translation. |
27 |
| -* [Learning more about Composer](docs/COMPOSER.md), a Node.js module to author compositions using JavaScript |
| 98 | +* [Introduction to Serverless Composition](docs/README.md): Setting up your |
| 99 | + programming environment and getting started with Shell and Composer. |
| 100 | +* [Building a Translation Slack Bot with Serverless |
| 101 | + Composition](docs/tutorials/translateBot/README.md): A more advanced tutorial |
| 102 | + using Composition to build a serverless Slack chatbot that does language |
| 103 | + translation. |
| 104 | +* [Composer Reference](docs/COMPOSER.md): A comprehensive reference manual for |
| 105 | + the Node.js programmer. |
28 | 106 |
|
29 | 107 | ## Videos
|
30 |
| -* [IBM Cloud Shell YouTube channel](https://www.youtube.com/channel/UCcu16nIMNclSujJWDOgUI_g): The channel hosts demo videos of IBM Cloud Shell, including editing a composition [using a built-in editor](https://youtu.be/1wmkSYl7EDM) or [an external editor](https://youtu.be/psqoysnVgE4), and [visualizing a composition's execution](https://youtu.be/jTaHgDQDZnQ). |
31 |
| -* Watch [our presentation at Serverlessconf'17](https://acloud.guru/series/serverlessconf/view/ibm-cloud-functions) about Composition and Shell |
32 |
| - |
33 |
| -## Example applications |
34 |
| -* A _Serverless Superman_ [Twitter Bot](https://www.raymondcamden.com/2017/10/20/upgrading-serverless-superman-to-ibm-composer/) |
35 |
| -* An app that [relays SMS to email](https://medium.com/openwhisk/a-composition-story-using-ibm-cloud-functions-to-relay-sms-to-email-d67fc65d29c) |
36 |
| - |
37 |
| -## Feedback |
38 |
| -We welcome your feedback and criticism. Find bugs and we will squash |
39 |
| -them. And will be grateful for your help. As an early adopter, you |
40 |
| -will also be among the first to experience even more features planned |
41 |
| -for the weeks ahead. We look forward to your feedback and encourage |
42 |
| -you to [join us on slack](http://ibm.biz/composer-users). |
| 108 | +* The [IBM Cloud Shell YouTube |
| 109 | + channel](https://www.youtube.com/channel/UCcu16nIMNclSujJWDOgUI_g) hosts demo |
| 110 | + videos of IBM Cloud Shell, including editing a composition [using a built-in |
| 111 | + editor](https://youtu.be/1wmkSYl7EDM) or [an external |
| 112 | + editor](https://youtu.be/psqoysnVgE4), and [visualizing a composition's |
| 113 | + execution](https://youtu.be/jTaHgDQDZnQ). |
| 114 | +* Watch [our presentation at |
| 115 | + Serverlessconf'17](https://acloud.guru/series/serverlessconf/view/ibm-cloud-functions) |
| 116 | + about Composer and Shell. |
| 117 | +* [Conductor Actions and Composer |
| 118 | + v2](https://urldefense.proofpoint.com/v2/url?u=https-3A__youtu.be_qkqenC5b1kE&d=DwIGaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=C3zA0dhyHjF4WaOy8EW8kQHtYUl9-dKPdS8OrjFeQmE&m=vCx7thSf3YtT7x3Pe2DaLYw-dcjU1hNIfDkTM_21ObA&s=MGh9y3vSvssj1xTzwEurJ6TewdE7Dr2Ycs10Tix8sNg&e=) |
| 119 | + (29:30 minutes into the video): A discussion of the composition runtime. |
| 120 | + |
| 121 | +## Blog posts |
| 122 | +* [Serverless Composition with IBM Cloud |
| 123 | + Functions](https://www.raymondcamden.com/2017/10/09/serverless-composition-with-ibm-cloud-functions/) |
| 124 | +* [Building Your First Serverless Composition with IBM Cloud |
| 125 | + Functions](https://www.raymondcamden.com/2017/10/18/building-your-first-serverless-composition-with-ibm-cloud-functions/) |
| 126 | +* [Upgrading Serverless Superman to IBM |
| 127 | + Composer](https://www.raymondcamden.com/2017/10/20/upgrading-serverless-superman-to-ibm-composer/) |
| 128 | +* [Calling Multiple Serverless Actions and Retaining Values with IBM |
| 129 | + Composer](https://www.raymondcamden.com/2017/10/25/calling-multiple-serverless-actions-and-retaining-values-with-ibm-composer/) |
| 130 | +* [Serverless Try/Catch/Finally with IBM |
| 131 | + Composer](https://www.raymondcamden.com/2017/11/22/serverless-trycatchfinally-with-ibm-composer/) |
| 132 | +* [Composing functions into |
| 133 | + applications](https://medium.com/openwhisk/composing-functions-into-applications-70d3200d0fac) |
| 134 | +* [A composition story: using IBM Cloud Functions to relay SMS to |
| 135 | + email](https://medium.com/openwhisk/a-composition-story-using-ibm-cloud-functions-to-relay-sms-to-email-d67fc65d29c) |
| 136 | + |
| 137 | +## Contributions |
| 138 | +We are looking forward your feedback and criticism. We encourage you to [join us |
| 139 | +on slack](http://ibm.biz/composer-users). File bugs and we will squash them. |
| 140 | + |
| 141 | +We welcome contributions to Composer and Shell. See |
| 142 | +[CONTRIBUTING.md](CONTRIBUTING.md). |
0 commit comments