Skip to content

Commit

Permalink
PHP 7.3 runtime (apache#46)
Browse files Browse the repository at this point in the history
* PHP 7.3 runtime

This runtime uses the Go runtime's ActionProxy as the front end. This
speeds things up nicely.

However, it also means that the detailed error reporting for invalid
data being uploaded to /init is not possible as this is handled by the
proxy. As a result, the specific tests that this affects have been
moved to the PHP 7.1 and 7.2 test classes.

Also, it's not possible to send back specific error messages for output
with the action proxy, so the fatal error test no longer checks for the
specific error text.
  • Loading branch information
akrabat authored and csantanapr committed Dec 12, 2018
1 parent ab65b67 commit 8256de1
Show file tree
Hide file tree
Showing 14 changed files with 580 additions and 92 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@

## PHP versions

This runtime provides PHP 7.2 and 7.1.
This runtime provides PHP 7.3, 7.2 and 7.1.

### Give it a try today
To use as a docker action

PHP 7.3:
```
wsk action update myAction myAction.php --docker openwhisk/action-php-v7.3:latest
```

PHP 7.2:
```
wsk action update myAction myAction.php --docker openwhisk/action-php-v7.2:latest
Expand All @@ -41,9 +46,14 @@ wsk action update myAction myAction.php --docker openwhisk/action-php-v7.1:lates

This works on any deployment of Apache OpenWhisk

### To use on deployment that contains the rutime as a kind
### To use on deployment that contains the runtime as a kind
To use as a kind action

PHP 7.3:
```
wsk action update myAction myAction.php --kind php:7.3
```

PHP 7.2:
```
wsk action update myAction myAction.php --kind php:7.2
Expand All @@ -56,19 +66,21 @@ wsk action update myAction myAction.php --kind php:7.1

### Local development
```
./gradlew core:php7.3Action:distDocker
./gradlew core:php7.2Action:distDocker
./gradlew core:php7.1Action:distDocker
```
This will produce the images `whisk/action-php-v7.2` & `whisk/action-php-v7.1`
This will produce the images `whisk/action-php-v7.3`, `whisk/action-php-v7.2` & `whisk/action-php-v7.1`

Build and Push image
```
docker login
./gradlew core:php7.3Action:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
./gradlew core:php7.2Action:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
./gradlew core:php7.1Action:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
```

Deploy OpenWhisk using ansible environment that contains the kinds `php:7.2` & `php:7.1`
Deploy OpenWhisk using ansible environment that contains the kinds `php:7.3`, `php:7.2` & `php:7.1`
Assuming you have OpenWhisk already deploy locally and `OPENWHISK_HOME` pointing to root directory of OpenWhisk core repository.

Set `ROOTDIR` to the root directory of this repository.
Expand All @@ -92,6 +104,10 @@ wskdev fresh -t local-php

To use as docker action push to your own dockerhub account
```
docker tag whisk/php7.2Action $user_prefix/action-php-v7.3
docker push $user_prefix/action-php-v7.3
```
```
docker tag whisk/php7.2Action $user_prefix/action-php-v7.2
docker push $user_prefix/action-php-v7.2
```
Expand All @@ -101,7 +117,7 @@ docker push $user_prefix/action-php-v7.1
```
Then create the action using your the image from dockerhub
```
wsk action update myAction myAction.php --docker $user_prefix/action-php-v7.2
wsk action update myAction myAction.php --docker $user_prefix/action-php-v7.3
```
The `$user_prefix` is usually your dockerhub user id.

Expand Down
38 changes: 38 additions & 0 deletions core/php7.3Action/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

## 1.0.0
Initial release

- Added: PHP: 7.3.0
- Added: PHP extensions in addition to the standard ones:
- bcmath
- curl
- gd
- intl
- mbstring
- mysqli
- pdo_mysql
- pdo_pgsql
- pdo_sqlite
- soap
- zip
- Added: Composer packages:
- [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle): 6.3.3
- [ramsey/uuid](https://packagist.org/packages/ramsey/uuid): 3.8.0
71 changes: 71 additions & 0 deletions core/php7.3Action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM openwhisk/actionloop:410d006 as builder

FROM php:7.3.0-cli-stretch

# install dependencies
RUN \
apt-get -y update && \
apt-get -y install \
libfreetype6-dev \
libicu-dev \
libicu57 \
libjpeg-dev \
libpng-dev \
libxml2-dev \
libzip-dev \
postgresql-server-dev-9.6 \
unzip \
zlib1g-dev

# Install useful PHP extensions
RUN \
docker-php-ext-install \
bcmath \
gd \
intl \
mysqli \
opcache \
pdo_mysql \
pdo_pgsql \
soap \
zip

COPY php.ini /usr/local/etc/php

# install composer
RUN curl -s -f -L -o /tmp/installer.php https://getcomposer.org/installer \
&& php /tmp/installer.php --no-ansi --install-dir=/usr/bin --filename=composer \
&& composer --ansi --version --no-interaction --no-plugins --no-scripts


# install default Composer dependencies
RUN mkdir -p /phpAction/composer
COPY composer.json /phpAction/composer
RUN cd /phpAction/composer && /usr/bin/composer install --no-plugins --no-scripts --prefer-dist --no-dev -o && rm composer.lock

# install proxy binary alogn with compile and launcher scripts
RUN mkdir -p /phpAction/action
WORKDIR /phpAction
COPY --from=builder /bin/proxy /bin/proxy
ADD compile /bin/compile
ADD runner.php /bin/runner.php
ENV OW_COMPILER=/bin/compile

ENTRYPOINT [ "/bin/proxy" ]
19 changes: 19 additions & 0 deletions core/php7.3Action/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

ext.dockerImageName = 'action-php-v7.3'
apply from: '../../gradle/docker.gradle'
82 changes: 82 additions & 0 deletions core/php7.3Action/compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env php
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* compile
*
* This file is launched by the action proxy.
* It copies runner.php to right source directory and creates a bash exec script
* that the action proxy will call to start everything off
*/

main($argc, $argv);
exit;

function main($argc, $argv)
{
if ($argc < 4) {
print("usage: <main-function-name> <source-dir> <bin-dir>");
exit(1);
}
$main = $argv[1];
$src = realpath($argv[2]);
$bin = realpath($argv[3]);

$shim = $bin.'/exec';

sources($src);
build($shim, $src, $main);
}

/**
* Sort out the source code
*
* 1. Copy src/exec to src/index.php if necessary
* 2. Ensure vendor directory exists
*/
function sources(string $src)
{
// If the file uploaded by the user is a plain PHP file, then
// the filename will be called exec by the action proxy.
// Rename it to index.php
if (file_exists($src . '/exec')) {
rename($src . '/exec', $src . '/index.php');
}

// put vendor in the right place if it doesn't exist
if (!is_dir($src . '/vendor')) {
exec('cp -a /phpAction/composer/vendor ' . escapeshellarg($src . '/vendor'));
}
}

/**
* Create bin/exec shim
*/
function build(string $shim, string $src, string $main) : void
{
$contents = <<<EOT
#!/bin/bash
cd $src
exec php -f /bin/runner.php -- "$main"
EOT;

file_put_contents($shim, $contents);
chmod($shim, 0755);
}
11 changes: 11 additions & 0 deletions core/php7.3Action/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"config": {
"platform": {
"php": "7.3"
}
},
"require": {
"guzzlehttp/guzzle": "6.3.3",
"ramsey/uuid": "3.8.0"
}
}
37 changes: 37 additions & 0 deletions core/php7.3Action/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; Licensed to the Apache Software Foundation (ASF) under one or more
; contributor license agreements. See the NOTICE file distributed with
; this work for additional information regarding copyright ownership.
; The ASF licenses this file to You under the Apache License, Version 2.0
; (the "License"); you may not use this file except in compliance with
; the License. You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.

[PHP]
short_open_tag = Off
output_buffering = Off
expose_php = Off
max_execution_time = 0
memory_limit = -1
error_reporting = E_ALL
display_errors = Off
log_errors = On
log_errors_max_len = 0
html_errors = Off
variables_order = "EGPCS"
request_order = "GP"
post_max_size = 0
enable_dl = Off
zend.assertions = -1

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.max_accelerated_files=7963
opcache.validate_timestamps=0
Loading

0 comments on commit 8256de1

Please sign in to comment.