You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by mh...@apache.org on 2022/08/24 11:33:00 UTC
[openwhisk-runtime-php] branch master updated: Add php 8.1 Runtime (#122)
This is an automated email from the ASF dual-hosted git repository.
mhenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-php.git
The following commit(s) were added to refs/heads/master by this push:
new a4988be Add php 8.1 Runtime (#122)
a4988be is described below
commit a4988be50bc75796b81e874d32ce91b9a5af4925
Author: skywalkeretw <lu...@outlook.com>
AuthorDate: Wed Aug 24 13:32:56 2022 +0200
Add php 8.1 Runtime (#122)
* Add php 8.1 Runtime
* Install libicu57 and postgresql-server-dev-13 as log version no loger supported in debian bullseye
* Install latest version of mongodb (1.14.0)
* Add minor tweaks suggested by akrabat
Co-authored-by: Luke Roy <lu...@Lukes-MacBook-Pro.local>
---
.travis.yml | 5 +
README.md | 21 +++-
core/php8.1Action/CHANGELOG.md | 40 ++++++++
core/php8.1Action/Dockerfile | 113 +++++++++++++++++++++
settings.gradle => core/php8.1Action/build.gradle | 27 +----
core/php8.1Action/compile.php | 82 +++++++++++++++
core/php8.1Action/composer.json | 11 ++
core/php8.1Action/php.ini | 37 +++++++
core/php8.1Action/runner.php | 92 +++++++++++++++++
settings.gradle | 1 +
.../Php81ActionContainerTests.scala | 29 ++----
11 files changed, 408 insertions(+), 50 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 54de878..e9d673b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -51,6 +51,11 @@ deploy:
on:
branch: master
repo: apache/openwhisk-runtime-php
+ - provider: script
+ script: "./tools/travis/publish.sh openwhisk 8.1 nightly"
+ on:
+ branch: master
+ repo: apache/openwhisk-runtime-php
env:
global:
- secure: "CE5mw5ZiXzchr1HcQVr94H8vN8U8Q/te0nPfWgEOUEbFixTRe71RYEKBHno/WztZd36XO1B3/1Ewc37FayFw474FUUdnrkVKh1ctzpmtBhGHw7KTMmSnICcR7ULcN/+WyjzvU5fTNMKEoaLcAcg4qEVqxnN4m3R1E8XJL9c0Kc8Hs2Mry0QqY9meX/DHeYzgs1VUuO/i0mXeXU6U8woP+eeGypaNrWk/U8gR9nA4VB49EVZZ1d8TtdaC9/+wmMjl93YQZccs1K2NTNJfDDU9Tm5RQQeXM4oZYaOaHvdlpo+iWhJ4blyVqY9i6NIx6satm5zV5amfO/hISuyfYdiyA/IiTvbewE4cUMq5W7B2xOUESmZQFqn4ssnCjKRGw2km2VnnAAQOSGMgQ1jUZUOYqtxKjTMYTtM8cZqYdo6URJy6Qz4Lhg/xfQgXdrPZZoKIoo4NcESHLaTfxazEB3nePA91qg4Bx [...]
diff --git a/README.md b/README.md
index 5cf6ec9..704eef4 100644
--- a/README.md
+++ b/README.md
@@ -24,11 +24,16 @@
## PHP versions
-This runtime provides PHP 8.0 and 7.4.
+This runtime provides PHP 8.1, 8.0 and 7.4.
### Give it a try today
To use as a docker action
+PHP 8.1:
+```
+wsk action update myAction myAction.php --docker openwhisk/action-php-v8.1:latest
+```
+
PHP 8.0:
```
wsk action update myAction myAction.php --docker openwhisk/action-php-v8.0:latest
@@ -44,6 +49,11 @@ This works on any deployment of Apache OpenWhisk
### To use on deployment that contains the runtime as a kind
To use as a kind action
+PHP 8.1:
+```
+wsk action update myAction myAction.php --kind php:8.1
+```
+
PHP 8.0:
```
wsk action update myAction myAction.php --kind php:8.0
@@ -57,10 +67,11 @@ wsk action update myAction myAction.php --kind php:7.4
### Local development
```
+./gradlew core:php8.1Action:distDocker
./gradlew core:php8.0Action:distDocker
./gradlew core:php7.4Action:distDocker
```
-This will produce the images `whisk/action-php-v8.0` and `whisk/action-php-v7.4` respectively.
+This will produce the images `whisk/action-php-v8.1`, `whisk/action-php-v8.0` and `whisk/action-php-v7.4` respectively.
Build and Push image
```
@@ -69,7 +80,7 @@ docker login
./gradlew core:php7.4Action:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
```
-Deploy OpenWhisk using ansible environment that contains the kinds `php:8.0` and `php:7.4`
+Deploy OpenWhisk using ansible environment that contains the kinds `php:8.1`, `php:8.0` and `php:7.4`
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.
@@ -93,6 +104,10 @@ wskdev fresh -t local-php
To use as docker action push to your own dockerhub account
```
+docker tag whisk/php8.1Action $user_prefix/action-php-v8.1
+docker push $user_prefix/action-php-v8.1
+```
+```
docker tag whisk/php8.0Action $user_prefix/action-php-v8.0
docker push $user_prefix/action-php-v8.0
```
diff --git a/core/php8.1Action/CHANGELOG.md b/core/php8.1Action/CHANGELOG.md
new file mode 100644
index 0000000..7bec0b5
--- /dev/null
+++ b/core/php8.1Action/CHANGELOG.md
@@ -0,0 +1,40 @@
+<!--
+#
+# 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.
+#
+-->
+
+## Next Release
+Initial release
+
+- Added: PHP: 8.1.9
+- Used openwhisk-runtime-go 1.18.0 to build proxy
+- Added: PHP extensions in addition to the standard ones:
+ - bcmath
+ - curl
+ - gd
+ - intl
+ - mbstring
+ - mysqli
+ - pdo_mysql
+ - pdo_pgsql
+ - pdo_sqlite
+ - soap
+ - zip
+ - mongo
+- Added: Composer packages:
+ - [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle): 7.4.5
+ - [ramsey/uuid](https://packagist.org/packages/ramsey/uuid): 4.4.0
diff --git a/core/php8.1Action/Dockerfile b/core/php8.1Action/Dockerfile
new file mode 100644
index 0000000..75a4604
--- /dev/null
+++ b/core/php8.1Action/Dockerfile
@@ -0,0 +1,113 @@
+#
+# 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.
+#
+
+# build go proxy from source
+FROM golang:1.18 AS builder_source
+ARG GO_PROXY_GITHUB_USER=apache
+ARG GO_PROXY_GITHUB_BRANCH=master
+RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
+ https://github.com/${GO_PROXY_GITHUB_USER}/openwhisk-runtime-go /src ;\
+ cd /src ; env GO111MODULE=on CGO_ENABLED=0 go build main/proxy.go && \
+ mv proxy /bin/proxy
+
+# or build it from a release
+FROM golang:1.18 AS builder_release
+ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
+RUN curl -sL \
+ https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
+ | tar xzf -\
+ && cd openwhisk-runtime-go-*/main\
+ && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
+
+FROM php:8.1-cli-bullseye
+
+# select the builder to use
+ARG GO_PROXY_BUILD_FROM=release
+
+# install PHP extensions
+RUN apt-get -y update \
+ && apt-get -y install --no-install-recommends \
+ unzip \
+ libfreetype6 \
+ libicu67 \
+ libjpeg62-turbo \
+ libpng16-16 \
+ libssl1.1 \
+ libxml2 \
+ libzip4 \
+ libpq5 \
+ zip \
+ libfreetype6-dev \
+ libicu-dev \
+ libjpeg-dev \
+ libpng-dev \
+ libssl-dev \
+ libxml2-dev \
+ libzip-dev \
+ postgresql-server-dev-13 \
+ \
+ && docker-php-ext-install \
+ bcmath \
+ gd \
+ intl \
+ mysqli \
+ opcache \
+ pdo_mysql \
+ pdo_pgsql \
+ soap \
+ zip \
+ \
+ && mkdir -p /usr/src/php/ext/mongodb \
+ && curl -fsSL https://pecl.php.net/get/mongodb-1.14.0 | tar xvz -C "/usr/src/php/ext/mongodb" --strip 1 \
+ && docker-php-ext-install -j$(nproc) mongodb \
+ \
+ && apt-get purge -y --auto-remove $PHPIZE_DEPS \
+ && apt-get purge -y --auto-remove libfreetype6-dev \
+ libicu-dev \
+ libjpeg-dev \
+ libpng-dev \
+ libssl-dev \
+ libxml2-dev \
+ libzip-dev \
+ postgresql-server-dev-13 \
+ && apt-get autoremove -y \
+ && apt-get clean -y \
+ && rm -rf /usr/src/php
+
+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 along with compile and launcher scripts
+RUN mkdir -p /phpAction/action
+WORKDIR /phpAction
+COPY --from=builder_source /bin/proxy /bin/proxy_source
+COPY --from=builder_release /bin/proxy /bin/proxy_release
+RUN mv /bin/proxy_${GO_PROXY_BUILD_FROM} /bin/proxy
+ADD compile.php /bin/compile.php
+ADD runner.php /bin/runner.php
+ENV OW_COMPILER=/bin/compile.php
+
+ENTRYPOINT [ "/bin/proxy" ]
diff --git a/settings.gradle b/core/php8.1Action/build.gradle
similarity index 59%
copy from settings.gradle
copy to core/php8.1Action/build.gradle
index a4d9903..bbb6681 100644
--- a/settings.gradle
+++ b/core/php8.1Action/build.gradle
@@ -15,28 +15,5 @@
* limitations under the License.
*/
-include 'tests'
-
-include 'core:php7.4Action'
-include 'core:php8.0Action'
-
-rootProject.name = 'runtime-php'
-
-gradle.ext.openwhisk = [
- version: '1.0.0-SNAPSHOT'
-]
-
-gradle.ext.scala = [
- version: '2.12.7',
- depVersion : '2.12',
- compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import']
-]
-
-gradle.ext.scalafmt = [
- version: scalamftVersion,
- config: new File(rootProject.projectDir, '.scalafmt.conf')
-]
-
-gradle.ext.akka = [version : '2.6.12']
-gradle.ext.akka_http = [version : '10.2.4']
-
+ext.dockerImageName = 'action-php-v8.1'
+apply from: '../../gradle/docker.gradle'
diff --git a/core/php8.1Action/compile.php b/core/php8.1Action/compile.php
new file mode 100755
index 0000000..d74939b
--- /dev/null
+++ b/core/php8.1Action/compile.php
@@ -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);
+}
diff --git a/core/php8.1Action/composer.json b/core/php8.1Action/composer.json
new file mode 100644
index 0000000..aeb383f
--- /dev/null
+++ b/core/php8.1Action/composer.json
@@ -0,0 +1,11 @@
+{
+ "config": {
+ "platform": {
+ "php": "8.1"
+ }
+ },
+ "require": {
+ "guzzlehttp/guzzle": "7.4.5",
+ "ramsey/uuid": "4.4.0"
+ }
+}
diff --git a/core/php8.1Action/php.ini b/core/php8.1Action/php.ini
new file mode 100644
index 0000000..bee173d
--- /dev/null
+++ b/core/php8.1Action/php.ini
@@ -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
diff --git a/core/php8.1Action/runner.php b/core/php8.1Action/runner.php
new file mode 100755
index 0000000..3bfe34b
--- /dev/null
+++ b/core/php8.1Action/runner.php
@@ -0,0 +1,92 @@
+<?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.
+ */
+
+// open fd/3 as that's where we send the result
+$fd3 = fopen('php://fd/3', 'wb');
+
+// Register a shutdown function so that we can fail gracefully when a fatal error occurs
+register_shutdown_function(static function () use ($fd3) {
+ $error = error_get_last();
+ if ($error && in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR], true)) {
+ file_put_contents('php://stderr', "An error occurred running the action.\n");
+ fwrite($fd3, "An error occurred running the action.\n");
+ }
+ fclose($fd3);
+});
+
+require 'vendor/autoload.php';
+require 'index.php';
+
+// retrieve main function
+$__functionName = $argv[1] ?? 'main';
+
+
+// read stdin
+while ($f = fgets(STDIN)) {
+ // call the function
+ $data = json_decode($f ?? '', true);
+ if (!is_array($data)) {
+ $data = [];
+ }
+
+ // convert all parameters other than value to environment variables
+ foreach ($data as $key => $value) {
+ if ($key !== 'value') {
+ $envKeyName = '__OW_' . strtoupper($key);
+ $_ENV[$envKeyName] = $value;
+ putenv($envKeyName . '=' . $value);
+ }
+ }
+
+ $values = $data['value'] ?? [];
+ try {
+ $result = $__functionName($values);
+
+ // convert result to an array if we can
+ if (is_object($result)) {
+ if (method_exists($result, 'getArrayCopy')) {
+ $result = $result->getArrayCopy();
+ } elseif ($result instanceof stdClass) {
+ $result = (array)$result;
+ }
+ } elseif ($result === null) {
+ $result = [];
+ }
+
+ // process the result
+ if (!is_array($result)) {
+ file_put_contents('php://stderr', 'Result must be an array but has type "'
+ . gettype($result) . '": ' . $result);
+ file_put_contents('php://stdout', 'The action did not return a dictionary or array.');
+ $result = (string)$result;
+ } else {
+ // cast result to an object for json_encode to ensure that an empty array becomes "{}
+ $result = json_encode((object)$result);
+ }
+ } catch (Throwable $e) {
+ file_put_contents('php://stderr', (string)$e);
+ $result = 'An error occurred running the action.';
+ }
+
+ // ensure that the sentinels will be on their own lines
+ file_put_contents('php://stderr', "\n");
+ file_put_contents('php://stdout', "\n");
+
+ // send result to fd/3
+ fwrite($fd3, $result . "\n");
+}
diff --git a/settings.gradle b/settings.gradle
index a4d9903..b9fe9a5 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -19,6 +19,7 @@ include 'tests'
include 'core:php7.4Action'
include 'core:php8.0Action'
+include 'core:php8.1Action'
rootProject.name = 'runtime-php'
diff --git a/settings.gradle b/tests/src/test/scala/runtime/actionContainers/Php81ActionContainerTests.scala
similarity index 59%
copy from settings.gradle
copy to tests/src/test/scala/runtime/actionContainers/Php81ActionContainerTests.scala
index a4d9903..bfaf808 100644
--- a/settings.gradle
+++ b/tests/src/test/scala/runtime/actionContainers/Php81ActionContainerTests.scala
@@ -15,28 +15,13 @@
* limitations under the License.
*/
-include 'tests'
+package runtime.actionContainers
-include 'core:php7.4Action'
-include 'core:php8.0Action'
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
-rootProject.name = 'runtime-php'
-
-gradle.ext.openwhisk = [
- version: '1.0.0-SNAPSHOT'
-]
-
-gradle.ext.scala = [
- version: '2.12.7',
- depVersion : '2.12',
- compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import']
-]
-
-gradle.ext.scalafmt = [
- version: scalamftVersion,
- config: new File(rootProject.projectDir, '.scalafmt.conf')
-]
-
-gradle.ext.akka = [version : '2.6.12']
-gradle.ext.akka_http = [version : '10.2.4']
+@RunWith(classOf[JUnitRunner])
+class Php81ActionContainerTests extends Php7ActionContainerTests {
+ override lazy val phpContainerImageName = "action-php-v8.1"
+}