44

Notes on working on the OpenWHisk PHP Runtime - Rob Allen

 5 years ago
source link: https://www.tuicool.com/articles/hit/eAriy2V
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

These are some notes for working on the OpenWhisk PHP Runtime , but are probably applicable to the other runtimes too.

Setting up

I have a clone of the runtimes I’m interested in and core side-by-side in a directory.

You then need various tools for development, which are documented here for macOS & Ubuntu in the Prerequites section.

Build the container

The PHP runtime creates two containers, one for PHP 7.1 and one for PHP 7.2. To build them we use Gradle:

$ ./gradlew :core:php7.2Action:distDocker
$ ./gradlew :core:php7.1Action:distDocker

This will create the images action-php-v7.1 and action-php-v7.2 with aliases whisk/action-php-v7.1 & whisk/action-php-v7.2 respectively.

Tests

Run the tests using:

$ ./gradlew :tests:test

This will run all the tests for both containers. If you need to run just one container’s test, then use the --tests filter:

$ ./gradlew tests:test --tests actionContainers.Php72ActionContainerTests

The tests use the BasicActionRunnerTests from core. If you have modified those, then you need to import them into your local Maven repo using:

$ cd path/to/incubator-openwhisk
$ ./gradlew :tests:install

Interactive testing of a container

You can test the container using your local install of OpenWhisk.

Alternatively you can test directly against the container using the handy invoke.py script that lives in core’s tools/actionProxy directory:

Firstly run action container:

$ docker run -i -t -p 8080:8080 action-php-v7.2

Then, in a different terminal:

$ cd path/to/test/actions
$ /path/to/incubator-openwhisk/tools/actionProxy/invoke.py init hello.php
$ /path/to/incubator-openwhisk/tools/actionProxy/invoke.py run '{"name": "Rob"}'

Note that you don’t pass the action name to invoke.py because we’re working at the container level and there can be only one action for each container instance. This means that you need to stop the container and restart it to init a new action.

You can test zip files too by passing your zip file to invoke.py init :

$ cp hello.php index.php 
$ zip hello.zip index.php
$ /path/to/incubator-openwhisk/tools/actionProxy/invoke.py init hello.zip
$ /path/to/incubator-openwhisk/tools/actionProxy/invoke.py run '{"name": "Rob"}'

Note that as the zip file must have a file called index.php in it, so we copy hello.php to index.php first.

Checking the formatting of Scala files

Travis runs on each PR raised. One thing it will do is check the formatting of the Scala. Check locally using:

./gradlew :tests:checkTestScalafmt

Fin

The tooling available for working on a single action runtime makes it reasonably easy to concentrate on the job in hand and you don’t need to worry about building the rest of OpenWhisk at the same time.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK