/ibm-cloud-functions-typescript-template

Template for IBM Cloud Functions with TypeScript and webpack.

Primary LanguageTypeScriptMIT LicenseMIT

Template for IBM Cloud Functions with TypeScript and webpack.

How to use

  1. Register IBM Cloud Lite
  2. Install ibmcloud cli & login
    brew install ibm-cloud-cli
    # it conflicts with /Application/Docker.app that not installed by brew cask
    ibmcloud plugin install cloud-functions
    ibmcloud login --apikey <APIKEY>
    ibmcloud resource groups
    ibmcloud target -g <default group id>
    ibmcloud fn namespace list
    ibmcloud fn namespace target <namespace which u want to use>
  3. Use this template and clone a repository
    git clone <your generated repo>
    cd reponame
  4. Build & deploy
    yarn
    yarn build
  5. Install direnv and make .envrc and apply
    brew install direnv
    # follow intro like add a line to .zshrc
    touch .envrc
    .envrc:
    export WEBHOOK_URL='your discord webhook url'
    export TARGET_ACTION_NAME='/1111-2222-3333/test/webhook'
    direnv allow .
  6. Deploy
    yarn deploy
    # $ ibmcloud fn deploy --manifest manifest.yaml
    # Success: Deployment completed successfully.
  7. Enjoy!

Tips: Call an action from other action

After deploying, check the name of the action with the following command:

ibmcloud fn package list
# packages
# /aaaa-bbbb-dddd-8226-aaaa/test                             private
#  ^ test's project name
ibmcloud fn action list /aaaa-bbbb-dddd-8226-aaaa/test
# actions
# /aaaa-bbbb-dddd-8226-aaaa/test/test                  private nodejs:12
#  ^ action's name

In this case, /aaaa-bbbb-dddd-8226-aaaa/test/test is action's name.
To deploy, rewrite .envrc as

export TARGET_ACTION_NAME="/aaaa-bbbb-dddd-8226-aaaa/test/test"

And,

direnv allow .
yarn deploy

Customize manifest.yaml

Read https://github.com/apache/openwhisk-wskdeploy/tree/master/specification/html.

Reference