Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Commit

Permalink
Add PHP8 Compatibility
Browse files Browse the repository at this point in the history
Fix compiler error for compile_ast
Make the extension compatible with newer versions of php
Convert final steps of docker build into a script
Change `whitelist` to `allowed `
Make unit tests compatible with latest version of phpunit
Add configuration for app engine project id
Update CircleCI configuration
Maintain backwards compat. for zval str dtor
Make warning/notify tests backwards compatible
Prevent seg fault when iterating logpoints in `ast_process`
Install gcloud tools for Dockerfile using apt
Remove memory leaks when creating debugger ast
Update string assertions in phpunit tests
Refactor Dockerfile to handle env vars needed for test build
Add substitutions to cloudbuild
Update php image versions used by cloudbuild
Set cloud build timeout to 2100 seconds
  • Loading branch information
frost-byte committed May 18, 2021
1 parent bfc88af commit f855707
Show file tree
Hide file tree
Showing 32 changed files with 738 additions and 460 deletions.
31 changes: 31 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2.1
jobs:
build:
docker:
- image: google/cloud-sdk
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD

steps:
- checkout
- run:
name: "Setup Environment"
command: |
echo 'export APPENGINE_PROJECT_ID="${APPENGINE_PROJECT_ID}"' >> $BASH_ENV
echo 'export GOOGLE_PROJECT_ID="${GOOGLE_PROJECT_ID}"' >> $BASH_ENV
echo 'export GOOGLE_COMPUTE_REGION="${GOOGLE_COMPUTE_REGION}"' >> $BASH_ENV
echo 'export GOOGLE_APPLICATION_CREDENTIALS=`echo ${GOOGLE_CREDENTIALS_BASE64} | base64 -di`' >> $BASH_ENV
apt-get update -y
apt-get -y --only-upgrade install google-cloud-sdk-kubectl-oidc google-cloud-sdk google-cloud-sdk-kpt google-cloud-sdk-cloud-build-local
gcloud --quiet config configurations create ${CLOUDSDK_ACTIVE_CONFIG_NAME}
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
echo $GOOGLE_CREDENTIALS_BASE64 | base64 -di | gcloud auth activate-service-account --key-file=-
gcloud --quiet config set compute/region ${GOOGLE_COMPUTE_REGION}
- run:
name: "Run Tests"
command: ./scripts/run_test_suite.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ tests/**/*.diff
tests/**/*.sh
vendor/
composer.lock
.vscode/c_cpp_properties.json
.vscode/tasks.json
.vscode/settings.json
29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,45 @@

ARG BASE_IMAGE
FROM $BASE_IMAGE
ARG GOOGLE_CREDENTIALS_BASE64
ARG CLOUDSDK_ACTIVE_CONFIG_NAME
ARG GOOGLE_PROJECT_ID
ARG PHP_DOCKER_GOOGLE_CREDENTIALS

RUN mkdir -p /build && \
apt-get update -y && \
apt-get install -y -q --no-install-recommends \
apt-transport-https \
build-essential \
ca-certificates \
g++ \
gcc \
gnupg \
libc-dev \
make \
autoconf \
curl \
git-core \
nano \
valgrind \
unzip

RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y

COPY . /build/

WORKDIR /build
RUN chmod 0755 /build/build.sh

ENV GOOGLE_CREDENTIALS_BASE64=${GOOGLE_CREDENTIALS_BASE64:-}
ENV CLOUDSDK_ACTIVE_CONFIG_NAME=${CLOUDSDK_ACTIVE_CONFIG_NAME:-default}
ENV GOOGLE_PROJECT_ID=${GOOGLE_PROJECT_ID:-google-cloud}
ENV PHP_DOCKER_GOOGLE_CREDENTIALS=${PHP_DOCKER_GOOGLE_CREDENTIALS:-/build/gcp-creds.json}
ENV GOOGLE_APPLICATION_CREDENTIALS=${PHP_DOCKER_GOOGLE_CREDENTIALS}
RUN /build/scripts/install_test_dependencies.sh

ENV TEST_PHP_ARGS="-q" \
REPORT_EXIT_STATUS=1

RUN phpize && \
./configure --enable-stackdriver-debugger && \
make clean && \
make && \
make test || ((find . -name '*.diff' | xargs cat) && false) && \
make install && \
(composer -V || scripts/install_composer.sh) && \
scripts/run_functional_tests.sh
RUN /build/build.sh
#ENTRYPOINT [ "/bin/bash" ]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ or
ini_set('stackdriver_debugger.max_time', '50');
```

### Whitelisting Function Calls in Conditions and Evaluated Expressions
### Allowing Function Calls in Conditions and Evaluated Expressions

Setting a snapshot or logpoint should not affect the state of any application.
By default, we disallow any unknown function calls that could potentially
modify the state of your application.

You can add additional function calls to this list by setting the ini config
`stackdriver_debugger.function_whitelist`:
`stackdriver_debugger.functions_allowed`:

```
# in php.ini
stackdriver_debugger.function_whitelist="foo,bar,MyClass::function"
stackdriver_debugger.functions_allowed="foo,bar,MyClass::function"
```

```php
ini_set('stackdriver_debugger.function_whitelist', 'foo,bar,MyClass::function');
ini_set('stackdriver_debugger.functions_allowed', 'foo,bar,MyClass::function');
```

Note that all function names specified here must be declared with their full
Expand Down
19 changes: 19 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -ex

if [ -z "${BUILD_DIR}" ]; then
BUILD_DIR='/build'
fi

export BUILD_DIR
export BUILD_LOG_DIR='/build/log'
mkdir -p ${BUILD_DIR} ${BUILD_LOG_DIR}

phpize && \
./configure --enable-stackdriver-debugger && \
make clean && \
make && \
make test || ((find . -name '*.diff' | xargs cat) && false) && \
make install && \
(composer -V || scripts/install_composer.sh) && \
scripts/run_functional_tests.sh
19 changes: 0 additions & 19 deletions circle.yml

This file was deleted.

193 changes: 156 additions & 37 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,157 @@
# This cloudbuild.yaml is used to test the php extension against multiple versions of php
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.1', '.']
id: php71-nts
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.1-zts', '.']
id: php71-zts
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.0', '.']
id: php70-nts
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.0-zts', '.']
id: php70-zts
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.2', '.']
id: php72-nts
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=php:7.2-zts', '.']
id: php72-zts
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/google-appengine/php72', '.']
id: php72-gae
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/google-appengine/php71', '.']
id: php71-gae
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/google-appengine/php70', '.']
id: php70-gae
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-stackdriver/php71-debug', '.']
id: php71-debug
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-stackdriver/php71-32bit', '.']
id: php71-32bit
- name: gcr.io/cloud-builders/docker
args: ['build', '--build-arg', 'BASE_IMAGE=gcr.io/php-stackdriver/php70-32bit', '.']
id: php70-32bit
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=gcr.io/${_APPENGINE_PROJECT_ID}/php80'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php80-gae
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=gcr.io/${_APPENGINE_PROJECT_ID}/php74'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php74-gae
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=gcr.io/${_APPENGINE_PROJECT_ID}/php73'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php73-gae
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=php:8.0'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php80-nts
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=php:8.0-zts'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php80-zts
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=php:7.4'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php74-nts
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=php:7.4-zts'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php74-zts
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=php:7.3'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php73-nts
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=php:7.3-zts'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php73-zts
- name: gcr.io/cloud-builders/docker
args:
- 'build'
- '--build-arg'
- 'BASE_IMAGE=gcr.io/php-stackdriver/php71-debug'
- '--build-arg'
- 'GOOGLE_CREDENTIALS_BASE64=${_GOOGLE_CREDENTIALS_BASE64}'
- '--build-arg'
- 'CLOUDSDK_ACTIVE_CONFIG_NAME=${_CLOUDSDK_ACTIVE_CONFIG_NAME}'
- '--build-arg'
- 'GOOGLE_PROJECT_ID=${_GOOGLE_PROJECT_ID}'
- '--build-arg'
- 'PHP_DOCKER_GOOGLE_CREDENTIALS=${_PHP_DOCKER_GOOGLE_CREDENTIALS}'
- '.'
id: php71-debug
timeout: 2100s
substitutions:
_PHP_DOCKER_GOOGLE_CREDENTIALS: /build/gcp-creds.json
_APPENGINE_PROJECT_ID: google-appengine
_CLOUDSDK_ACTIVE_CONFIG_NAME: default
_GOOGLE_PROJECT_ID: $PROJECT_ID
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Validation will happen in 2 places.
#### Disallowing Function Calls in Conditions and Expressions

We will disallow all function calls except those that are explicitly marked as
safe. We maintain a list of build-in functions that are whitelisted. We also
safe. We maintain a list of build-in functions that are allowed. We also
provide a `php.ini` setting that allows you to specify your own list of allowed
function calls.

Expand Down
6 changes: 3 additions & 3 deletions php_stackdriver_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include "php.h"
#include "stackdriver_debugger.h"

#define PHP_STACKDRIVER_DEBUGGER_VERSION "0.2.0"
#define PHP_STACKDRIVER_DEBUGGER_VERSION "0.3.0"
#define PHP_STACKDRIVER_DEBUGGER_EXTNAME "stackdriver_debugger"
#define PHP_STACKDRIVER_DEBUGGER_INI_WHITELISTED_FUNCTIONS "stackdriver_debugger.function_whitelist"
#define PHP_STACKDRIVER_DEBUGGER_INI_ALLOWED_FUNCTIONS "stackdriver_debugger.functions_allowed"
#define PHP_STACKDRIVER_DEBUGGER_INI_MAX_TIME "stackdriver_debugger.max_time"
#define PHP_STACKDRIVER_DEBUGGER_INI_MAX_TIME_PERCENTAGE "stackdriver_debugger.max_time_percentage"
#define PHP_STACKDRIVER_DEBUGGER_INI_MAX_MEMORY "stackdriver_debugger.max_memory"
Expand All @@ -43,7 +43,7 @@ PHP_RSHUTDOWN_FUNCTION(stackdriver_debugger);

ZEND_BEGIN_MODULE_GLOBALS(stackdriver_debugger)
/* map of function name -> empty null zval */
HashTable *user_whitelisted_functions;
HashTable *user_allowed_functions;

/* map of filename -> stackdriver_debugger_snapshot[] */
HashTable *snapshots_by_file;
Expand Down
Loading

0 comments on commit f855707

Please sign in to comment.