Code Monkey home page Code Monkey logo

test's Introduction

Custom setup for OpenWhisk using Vagrant

The following instructions were tested on Mac OS X El Capitan, Ubuntu 14.04.3 LTS and may work on Windows.

Requirements

Clone the repository and change directory to tools/vagrant/custom

git clone https://github.com/openwhisk/openwhisk.git
cd openwhisk/tools/vagrant/custom

Create VM using custom datastore (Cloudant or CouchDB)

Follow instructions tools/db/README.md on how to configure a datastore for OpenWhisk.

Option 1: Create VM using Cloudant DB

# Provide credentials for cloudant database with admin permissions
OW_DB=cloudant OW_DB_USERNAME=xxxxx OW_DB_PASSWORD=yyyyyy vagrant up

Option 2: Create VM using persistent CouchDB

# Provide credentials for couchdb database with admin permissions
OW_DB=couchdb OW_DB_USERNAME=xxxxx OW_DB_PASSWORD=yyyyyy OW_DB_PROTOCOL=http OW_DB_HOST=1.2.3.4 OW_DB_PORT=5984 vagrant up

Option 3: Create VM using ephemeral CouchDB

Important We advise that you use this method only as a temporary measure. Please note that no data will persist between two creations of the container. For more information on datastore configurations see tools/db/README.md.

# Configure with couchdb docker container running inside the VM
vagrant up

Wait for hello action output

wsk action invoke /whisk.system/samples/echo -p message hello --blocking --result
{
    "message": "hello"
}

Tip: The very first build may take 10 minutes or more depending on network speed. If there are any build failures, it might be due to network timeouts, run ../resume_build on the host.

Tip: By default, each docker command will timeout after 840 seconds (14 minutes). If you're on a really slow connection, this might be too short. You can modify the timeout value in docker.gradle as needed.

Use the wsk CLI inside the VM

vagrant ssh -- wsk action invoke /whisk.system/samples/echo -p message hello --blocking --result

Tip: Login into the VM using vagrant ssh then use the wsk CLI with tab completion on commands and parameters. Hit tab to complete a command or to see available commands and arguments for a given context.

Running tests

vagrant ssh -- ant run

Build and Deploy

When making changes, rebuild and deploy the system with:

# Build and deploy
  vagrant ssh -- ant clean build deploy
  
# Or teardown and deploy
  vagrant ssh -- ant redeploy

To teardown OpenWhisk and remove all Docker containers, run vagrant ssh -- ant teardown. You can then redeploy the system with ant deploy. To do both at once, use ant redeploy.

Tip If you have problems with data stores check that ansible/db_local.ini is present (inside the VM).

Tip To initialize the data store from scratch run ansible-playbook initdb.yml inside the VM as described in ansible setup.

Once deployed, several Docker containers will be running in your virtual machine. You can check that containers are running by using the docker cli with the command vagrant ssh -- docker ps.

Adding OpenWhisk users (Optional)

An OpenWhisk user, also known as a subject, requires a valid authorization key and namespace. OpenWhisk is preconfigured with a guest key located in config/keys/auth.guest. The default namespace is guest.

You may use this key if you like, or use wskadmin inside the VM to create a new key.

wskadmin user create <subject>

This command will create a new subject with the authorization key shown on the console once you run wskadmin. This key is required when making API calls to OpenWhisk, or when using the command line interface (CLI). The namespace is the same as the <subject> name used to create the key.

The same tool may be used to delete a subject.

wskadmin user delete <subject>

Using CLI from outside the VM (Optional)

If you cloned OpenWhisk natively onto a Mac and using a Vagrant machine to host an OpenWhisk deployment, then you can use the CLI from the host machine as well as from inside the virtual machine. To find out the IP address of the virtual machine you can run ssh to get the value.

vagrant ssh -- ip route get 8.8.8.8 | awk '{print $NF; exit}'
10.0.2.15

From your host, configure wsk to use your Vagrant-hosted OpenWhisk deployment and run the "echo" action again to test.

# Set your OpenWhisk Namespace and Authorization Key.
  wsk property set --apihost `vagrant ssh -- ip route get 8.8.8.8 | awk '{print $NF; exit}'` --namespace guest --auth `vagrant ssh -- cat ansible/files/auth.guest`

# Run the hello sample action
  wsk action invoke /whisk.system/samples/echo -p message hello --blocking --result
  {
    "message": "hello"
  }

Tip: To connect to a different host API (i.e. bluemix.net) with the CLI, you will need to configure the CLI with new values for apihost, namespace, and auth key.

SSL certificate configuration (Optional)

OpenWhisk includes a self-signed SSL certificate and the wsk CLI allows untrusted certificates.

ls ansible/roles/nginx/files/openwhisk-*
ansible/roles/nginx/files/openwhisk-cert.pem
ansible/roles/nginx/files/openwhisk-key.pem

Do not use these certificates in production: replace with your own and modify the configuration to use trusted certificates instead.

Misc

# Suspend Vagrant VM when done having fun
  vagrant suspend

# Resume Vagrant VM to have fun again
  vagrant up

# Read the help for wsk CLI
  vagrant ssh -- wsk -h
  vagrant ssh -- wsk <command> -h

Tip: Don't use vagrant resume. See here for related issue.

Using Vagrant VM in GUI mode (Optional)

Create VM with Desktop GUI. The username and password are both set to vagrant by default.

  gui=true ./hello
  gui=true vagrant reload

Tip: Ignore error message Sub-process /usr/bin/dpkg returned an error code (1) when creating Vagrant VM using gui-true. Remember to use gui=true every time you do vagrant reload. Or, you can enable the GUI directly by editing the Vagrant file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.