mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
more tutorial
This commit is contained in:
1
examples/tutorial/hello/php/.gitignore
vendored
Normal file
1
examples/tutorial/hello/php/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
vendor/
|
||||
6
examples/tutorial/hello/php/Dockerfile
Normal file
6
examples/tutorial/hello/php/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM funcy/php
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["php", "hello.php"]
|
||||
48
examples/tutorial/hello/php/README.md
Normal file
48
examples/tutorial/hello/php/README.md
Normal file
@@ -0,0 +1,48 @@
|
||||
## Quick Example for a PHP Function (4 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to Oracle Functions.
|
||||
|
||||
### 1. Prepare the `func.yaml` file:
|
||||
|
||||
At func.yaml you will find:
|
||||
|
||||
```yml
|
||||
name: USERNAME/hello
|
||||
version: 0.0.1
|
||||
path: /hello
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker funcy/php:dev composer install
|
||||
```
|
||||
|
||||
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
|
||||
the application name is `phpapp` and the route for incoming requests is `/hello`. These informations are relevant for
|
||||
the moment you try to test this function.
|
||||
|
||||
### 2. Build:
|
||||
|
||||
```sh
|
||||
# build the function
|
||||
fn build
|
||||
# test it
|
||||
cat hello.payload.json | fn run
|
||||
# push it to Docker Hub
|
||||
fn push
|
||||
# Create a route to this function on Oracle Functions
|
||||
fn routes create phpapp /hello
|
||||
```
|
||||
|
||||
`-v` is optional, but it allows you to see how this function is being built.
|
||||
|
||||
### 3. Queue jobs for your function
|
||||
|
||||
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
|
||||
|
||||
```sh
|
||||
cat hello.payload.json | fn call phpapp /hello
|
||||
```
|
||||
|
||||
Here's a curl example to show how easy it is to do in any language:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/phpapp/hello
|
||||
```
|
||||
4
examples/tutorial/hello/php/composer.json
Normal file
4
examples/tutorial/hello/php/composer.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"require": {
|
||||
}
|
||||
}
|
||||
5
examples/tutorial/hello/php/func.yaml
Normal file
5
examples/tutorial/hello/php/func.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
name: USERNAME/hello
|
||||
version: 0.0.1
|
||||
path: /hello
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker funcy/php:dev composer install
|
||||
3
examples/tutorial/hello/php/hello.payload.json
Normal file
3
examples/tutorial/hello/php/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
10
examples/tutorial/hello/php/hello.php
Normal file
10
examples/tutorial/hello/php/hello.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
stream_set_blocking(STDIN, 0);
|
||||
$payload = json_decode(file_get_contents("php://stdin"), true);
|
||||
if (isset($payload['name'])) {
|
||||
echo "Hello ", $payload['name'],"!\n\n";
|
||||
} else {
|
||||
echo "Hello World!\n\n";
|
||||
}
|
||||
Reference in New Issue
Block a user