Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit bef3e17

Browse files
authored
Handle google-cloud restructure for auto_prepend_file path (#425)
* Add script to locate the stackdriver prepend file * Remove unused constant * Use realpath * Fix prepend.php filename * Run integration test of build pipeline with enable_stackdriver_integration: true * Rename test directory for deployment host name length * Fix test directory in yaml config * shorten deploy tag for stackdriver deployment test * Set the google/cloud version for the build pipeline with stackdriver test
1 parent 1d5c89f commit bef3e17

26 files changed

+2249
-10
lines changed

integration-tests.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,15 @@ steps:
4040
- 'E2E_PROJECT_ID=${_E2E_PROJECT_ID}'
4141
- 'RUNTIME_BUILDER_ROOT=${_RUNTIME_BUILDER_ROOT}'
4242
- 'TEST_VM_IMAGE=${_TEST_VM_IMAGE}'
43+
44+
# build_pipeline_stackdriver test
45+
- name: gcr.io/${_GOOGLE_PROJECT_ID}/php-test-runner:$_TAG
46+
args: ['/workspace/testapps/build_pipeline_std/tests']
47+
waitFor: ['test-runner']
48+
id: build_pipeline_stackdriver
49+
env:
50+
- 'SERVICE_ACCOUNT_JSON=${_SERVICE_ACCOUNT_JSON}'
51+
- 'TAG=${_TAG}-build-pipeline-std'
52+
- 'E2E_PROJECT_ID=${_E2E_PROJECT_ID}'
53+
- 'RUNTIME_BUILDER_ROOT=${_RUNTIME_BUILDER_ROOT}'
54+
- 'TEST_VM_IMAGE=${_TEST_VM_IMAGE}'

php-base/stackdriver-files/enable_stackdriver_integration.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ echo "Enabling stackdriver integration..."
2828
# To start the batch daemon
2929
cp /stackdriver-files/batch-daemon.conf /etc/supervisor/conf.d
3030

31-
if [ "${1}" = "--individual" ]; then
32-
# For enabling automatic error reporting for google/cloud-error-reporting
33-
cp /stackdriver-files/stackdriver-errorreporting-individual.ini ${PHP_DIR}/lib/conf.d
34-
else
35-
# For enabling automatic error reporting for google/cloud
36-
cp /stackdriver-files/stackdriver-errorreporting.ini ${PHP_DIR}/lib/conf.d
31+
# Detect the stackdriver prepend path
32+
set +e
33+
PREPEND_PATH=`php /stackdriver-files/locate_stackdriver_prepend.php`
34+
set -e
35+
if [ $? -ne 0 ]; then
36+
if [ "${1}" = "--individual" ]; then
37+
PREPEND_PATH="/app/vendor/google/cloud-error-reporting/prepend.php"
38+
else
39+
PREPEND_PATH="/app/vendor/google/cloud/src/ErrorReporting/prepend.php"
40+
fi
3741
fi
42+
echo "auto_prepend_file=$PREPEND_PATH" > ${PHP_DIR}/lib/conf.d/stackdriver-prepend.ini
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright 2018 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
$appDir = getenv('APP_DIR');
19+
$appDir = $appDir ?: '/app';
20+
21+
// Use the application's vendor/autoload.php
22+
require_once $appDir . '/vendor/autoload.php';
23+
24+
use Google\Cloud\ErrorReporting\Bootstrap;
25+
26+
if (class_exists(Bootstrap::class)) {
27+
$reflection = new \ReflectionClass(Bootstrap::class);
28+
if ($reflection->hasMethod('prependFileLocation')) {
29+
echo Bootstrap::prependFileLocation() . PHP_EOL;
30+
} else {
31+
// default to same directory as the Bootstrap.php
32+
echo realpath(dirname($reflection->getFileName()) . '/prepend.php') . PHP_EOL;
33+
}
34+
} else {
35+
die('cannot find ErrorReporting\Bootstrap class');
36+
}

php-base/stackdriver-files/stackdriver-errorreporting-individual.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

php-base/stackdriver-files/stackdriver-errorreporting.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cloudbuild.yaml
2+
Dockerfile

testapps/build_pipeline_std/app.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
runtime: php
2+
env: flex
3+
4+
runtime_config:
5+
document_root: web
6+
whitelist_functions: phpinfo,exec
7+
enable_stackdriver_integration: true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"require": {
3+
"php": "7.1.*",
4+
"ext-grpc": "*",
5+
"ext-mailparse": "*",
6+
"ext-mbstring": "*",
7+
"ext-opencensus": "*",
8+
"ext-pdo_sqlite": "*",
9+
"google/cloud": "^0.39.2",
10+
"grpc/grpc": "*",
11+
"silex/silex": "^1.3"
12+
},
13+
"scripts": {
14+
"post-install-cmd": [
15+
"php logging-client.php"
16+
]
17+
},
18+
"autoload": {
19+
"classmap": ["web"]
20+
}
21+
}

0 commit comments

Comments
 (0)