Skip to content

Commit

Permalink
Adds Kokoro pre-submit (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed May 7, 2018
1 parent bd6341a commit f44c03f
Show file tree
Hide file tree
Showing 72 changed files with 1,744 additions and 684 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ credentials.*
**/build/
.php_cs.cache
.vscode/
export-secrets.sh
iap/composer.lock
.kokoro/secrets.sh
29 changes: 27 additions & 2 deletions .kokoro/php72/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
FROM gcr.io/google_appengine/php72

RUN composer global require phpunit/phpunit:4.8
RUN apt-get update && apt-get install -y \
python-ipaddr \
autoconf \
build-essential \
zlib1g-dev \
jq

RUN export PATH="$PATH:/opt/composer/vendor/bin"
RUN git clone https://github.com/GoogleCloudPlatform/php-tools.git ${HOME}/php-tools \
&& ${HOME}/php-tools/scripts/install_test_deps.sh

# install / enable PHP extensions
RUN pecl install grpc \
&& echo "extension=grpc.so" >> /opt/php72/lib/conf.d/ext-grpc.ini \
&& echo "extension=bcmath.so" >> /opt/php72/lib/conf.d/ext-bcmath.ini

# Install composer globally
RUN composer global require phpunit/phpunit:^5.0

# Install Google Cloud SDK
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz \
-o ${HOME}/google-cloud-sdk.tar.gz \
&& tar xzf ${HOME}/google-cloud-sdk.tar.gz -C $HOME \
&& ${HOME}/google-cloud-sdk/install.sh \
--usage-reporting false \
--path-update false \
--command-completion false

ENV PATH="$PATH:/opt/composer/vendor/bin:/root/google-cloud-sdk/bin"

ENTRYPOINT /bin/bash
92 changes: 92 additions & 0 deletions .kokoro/secrets-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

################################################################################
# Run the following gcloud command to decrypt secrets.sh.enc as follows: #
# #
# gcloud kms decrypt -location=global --keyring=ci --key=ci \ #
# --ciphertext-file=.kokoro/secrets.sh.enc \ #
# --plaintext-file=.kokoro/secrets.sh #
# #
# Then run `source .kokoro/secrets.sh` #
################################################################################

# General
export GOOGLE_PROJECT_ID=
export GOOGLE_API_KEY=
export GOOGLE_STORAGE_BUCKET=$GOOGLE_PROJECT_ID
export GOOGLE_CLIENT_ID=
export GOOGLE_CLIENT_SECRET=
export GCLOUD_PROJECT=$GOOGLE_PROJECT_ID

# AppEngine
export MAILJET_APIKEY=
export MAILJET_SECRET=
export MAILGUN_APIKEY=
export MAILGUN_DOMAIN=
export MAILGUN_RECIPIENT=
export SENDGRID_APIKEY=
export SENDGRID_SENDER=
export TWILIO_ACCOUNT_SID=
export TWILIO_AUTH_TOKEN=
export TWILIO_FROM_NUMBER=
export TWILIO_TO_NUMBER=

# BigQuery
export GOOGLE_BIGQUERY_DATASET=test_dataset
export GOOGLE_BIGQUERY_TABLE=test_table

# CloudSQL
export CLOUDSQL_CONNECTION_NAME_MYSQL=
export CLOUDSQL_CONNECTION_NAME_POSTGRES=
export MYSQL_DSN=
export MYSQL_DATABASE=
export MYSQL_USER=
export MYSQL_PASSWORD=
export POSTGRES_DSN=
export POSTGRES_DATABASE=
export POSTGRES_USER=
export POSTGRES_PASSWORD=

# Datastore
export CLOUD_DATASTORE_NAMESPACE=
export DATASTORE_EVENTUALLY_CONSISTENT_RETRY_COUNT=

# DLP
export DLP_TOPIC=dlp-tests
export DLP_SUBSCRIPTION=dlp-tests
export DLP_DEID_WRAPPED_KEY=
export DLP_DEID_KEY_NAME=projects/$GOOGLE_PROJECT_ID/locations/global/keyRings/ci/cryptoKeys/ci

# Firestore
export FIRESTORE_PROJECT_ID=

# IAP
export IAP_CLIENT_ID=
export IAP_PROJECT_ID=
export IAP_PROJECT_NUMBER=
export IAP_URL=

# IAM
export GOOGLE_IAM_USER=

# IOT
export GOOGLE_IOT_DEVICE_CERTIFICATE_B64=

# KMS
export GOOGLE_KMS_KEYRING=
export GOOGLE_KMS_CRYPTOKEY=
export GOOGLE_KMS_CRYPTOKEY_ALTERNATE=
export GOOGLE_KMS_SERVICEACCOUNTEMAIL=

# PubSub
export GOOGLE_PUBSUB_SUBSCRIPTION=php-example-subscription
export GOOGLE_PUBSUB_TOPIC=php-example-topic

# Spanner
export GOOGLE_SPANNER_INSTANCE_ID=
export GOOGLE_SPANNER_DATABASE_ID=test-database

# Tasks
export CLOUD_TASKS_APPENGINE_QUEUE=
export CLOUD_TASKS_LOCATION=
export CLOUD_TASKS_PULL_QUEUE=
Binary file added .kokoro/secrets.sh.enc
Binary file not shown.
43 changes: 42 additions & 1 deletion .kokoro/system_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
#!/bin/bash

# Copyright 2017 Google Inc.
#
# Licensed 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.

set -ex

echo "hello world"
# Kokoro directory for running these samples
cd github/php-docs-samples

export GOOGLE_APPLICATION_CREDENTIALS=$KOKORO_GFILE_DIR/service-account.json

# export the secrets
if [ -f ${GOOGLE_APPLICATION_CREDENTIALS} ]; then
gcloud auth activate-service-account \
--key-file "${GOOGLE_APPLICATION_CREDENTIALS}" \
--project $(cat "${GOOGLE_APPLICATION_CREDENTIALS}" | jq -r .project_id)
gcloud kms decrypt \
--location=global \
--keyring=ci \
--key=ci \
--ciphertext-file=.kokoro/secrets.sh.enc \
--plaintext-file=.kokoro/secrets.sh
fi

# Unencrypt and extract secrets
source .kokoro/secrets.sh

mkdir -p build/logs

export IS_PULL_REQUEST=$KOKORO_GITHUB_PULL_REQUEST_COMMIT

# Run tests
bash testing/run_test_suite.sh
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ env:
- PATH="${HOME}/google-cloud-sdk/bin:${PATH}"
- PHP_CGI_PATH=/home/travis/.phpenv/shims/php-cgi
- TEST_BUILD_DIR=$TRAVIS_BUILD_DIR
# We use the envvar "IS_PULL_REQUEST" for both kokoro and travis
- IS_PULL_REQUEST=$TRAVIS_PULL_REQUEST_BRANCH

before_install:
- git clone https://github.com/GoogleCloudPlatform/php-tools.git ${HOME}/php-tools
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Please fill out either the individual or corporate Contributor License Agreement
own the intellectual property, then you'll need to sign an
[individual CLA](https://developers.google.com/open-source/cla/individual).
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a
then you'll need to sign a
[corporate CLA](https://developers.google.com/open-source/cla/corporate).

Follow either of the two links above to access the appropriate CLA and
Expand All @@ -31,14 +31,14 @@ accept your pull requests.
credentials](https://cloud.google.com/docs/authentication/getting-started)
by setting the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the
path to a service account key JSON file.

Then set any environment variables needed by the test. Check the
`$SAMPLES_DIRECTORY/test` directory to see what specific variables are needed.
```
export GOOGLE_PROJECT_ID=YOUR_PROJECT_ID
export GOOGLE_BUCKET_NAME=YOUR_BUCKET
export GOOGLE_STORAGE_BUCKET=YOUR_BUCKET
```

To run the tests in a samples directory,
```
cd $SAMPLES_DIRECTORY
Expand Down
6 changes: 3 additions & 3 deletions appengine/flexible/cloudsql-mysql/test/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function setUp()

public function createApplication()
{
if (getenv('MYSQL_DSN') === false ||
getenv('MYSQL_USER') === false ||
getenv('MYSQL_PASSWORD') === false) {
if (!getenv('MYSQL_DSN') ||
!getenv('MYSQL_USER') ||
!getenv('MYSQL_PASSWORD')) {
$this->markTestSkipped('set the MYSQL_DSN, MYSQL_USER and MYSQL_PASSWORD environment variables');
return;
}
Expand Down
6 changes: 3 additions & 3 deletions appengine/flexible/cloudsql-postgres/test/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function setUp()

public function createApplication()
{
if (getenv('POSTGRES_DSN') === false ||
getenv('POSTGRES_USER') === false ||
getenv('POSTGRES_PASSWORD') === false) {
if (!getenv('POSTGRES_DSN') ||
!getenv('POSTGRES_USER') ||
!getenv('POSTGRES_PASSWORD')) {
$this->markTestSkipped('set the POSTGRES_DSN, POSTGRES_USER and POSTGRES_PASSWORD environment variables');
return;
}
Expand Down
4 changes: 2 additions & 2 deletions appengine/flexible/logging/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

// create the Silex application
$app = new Application();
$app['project_id'] = getenv('GOOGLE_CLOUD_PROJECT');
$app['project_id'] = getenv('GOOGLE_PROJECT_ID');
// register twig
$app->register(new TwigServiceProvider(), [
'twig.path' => __DIR__
]);

$app->get('/', function () use ($app) {
if (empty($app['project_id'])) {
return 'Set the GOOGLE_CLOUD_PROJECT environment variable to run locally';
return 'Set the GOOGLE_PROJECT_ID environment variable to run locally';
}
$projectId = $app['project_id'];
# [START list_entries]
Expand Down
6 changes: 3 additions & 3 deletions appengine/flexible/logging/test/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class LocalTest extends WebTestCase
{
public function setUp()
{
if (!getenv('GOOGLE_CLOUD_PROJECT')) {
$this->markTestSkipped('Must set GOOGLE_CLOUD_PROJECT');
if (!getenv('GOOGLE_PROJECT_ID')) {
$this->markTestSkipped('Must set GOOGLE_PROJECT_ID');
}
if (!getenv('TRAVIS_SECURE_ENV_VARS')) {
$this->markTestSkipped('No secret available');
Expand All @@ -36,7 +36,7 @@ public function setUp()
public function createApplication()
{
$app = require __DIR__ . '/../app.php';
$app['project_id'] = getenv('GOOGLE_CLOUD_PROJECT');
$app['project_id'] = getenv('GOOGLE_PROJECT_ID');
return $app;
}

Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/sendgrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ composer install

**Run Locally**
```sh
export SENDGRID_API_KEY=your-sendgrid-api-key
export SENDGRID_APIKEY=your-sendgrid-api-key
export SENDGRID_SENDER=somebody@yourdomain.com
php -S localhost:8000 -t .
```
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/sendgrid/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
$sendgridApiKey = $app['sendgrid.api_key'];
$sendgridRecipient = $request->get('recipient');
# [START send_mail]
// $sendgridApiKey = 'YOUR_SENDGRID_API_KEY';
// $sendgridApiKey = 'YOUR_SENDGRID_APIKEY';
// $sendgridSender = 'an-email-to-send-from@example.com';
// $sendgridRecipient = 'some-recipient@example.com';
$sender = new SendGrid\Email(null, $sendgridSender);
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/sendgrid/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ runtime_config:

# [START env_variables]
env_variables:
SENDGRID_API_KEY: your-sendgrid-api-key
SENDGRID_APIKEY: your-sendgrid-api-key
SENDGRID_SENDER: your-sendgrid-sender
# [END env_variables]
2 changes: 1 addition & 1 deletion appengine/flexible/sendgrid/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$app = require __DIR__ . '/app.php';

$app['sendgrid.sender'] = getenv('SENDGRID_SENDER');
$app['sendgrid.api_key'] = getenv('SENDGRID_API_KEY');
$app['sendgrid.api_key'] = getenv('SENDGRID_APIKEY');

// Run the app!
// use "gcloud app deploy" or run "php -S localhost:8000"
Expand Down
4 changes: 2 additions & 2 deletions appengine/flexible/sendgrid/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function beforeDeploy()
chdir($tmpDir);

$appYaml = Yaml::parse(file_get_contents('app.yaml'));
$appYaml['env_variables']['SENDGRID_API_KEY'] =
getenv('SENDGRID_API_KEY');
$appYaml['env_variables']['SENDGRID_APIKEY'] =
getenv('SENDGRID_APIKEY');
$appYaml['env_variables']['SENDGRID_SENDER'] =
getenv('SENDGRID_SENDER');
file_put_contents('app.yaml', Yaml::dump($appYaml));
Expand Down
4 changes: 2 additions & 2 deletions appengine/flexible/sendgrid/test/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function createApplication()
$app['debug'] = true;

$app['sendgrid.sender'] = getenv('SENDGRID_SENDER');
$app['sendgrid.api_key'] = getenv('SENDGRID_API_KEY');
$app['sendgrid.api_key'] = getenv('SENDGRID_APIKEY');

if (empty($app['sendgrid.sender']) || empty($app['sendgrid.api_key'])) {
$this->markTestSkipped(
'set the SENDGRID_SENDER and SENDGRID_API_KEY' .
'set the SENDGRID_SENDER and SENDGRID_APIKEY ' .
'environment variables'
);
}
Expand Down
4 changes: 2 additions & 2 deletions appengine/flexible/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Before running this sample:

## Run Locally

Set the environment variables `GOOGLE_BUCKET_NAME` and `GCLOUD_PROJECT` to the name of your storage bucket and project ID respectively.
Set the environment variables `GOOGLE_STORAGE_BUCKET` and `GCLOUD_PROJECT` to the name of your storage bucket and project ID respectively.

```
export GOOGLE_BUCKET_NAME=your-bucket-name
export GOOGLE_STORAGE_BUCKET=your-bucket-name
export GCLOUD_PROJECT=your-project-id
```
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/storage/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ runtime_config:

# [START env_variables]
env_variables:
GOOGLE_BUCKET_NAME: "your-bucket-name"
GOOGLE_STORAGE_BUCKET: "your-bucket-name"
# [END env_variables]

2 changes: 1 addition & 1 deletion appengine/flexible/storage/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$app = require __DIR__ . '/app.php';

// change this to your bucket name!
$app['bucket_name'] = getenv('GOOGLE_BUCKET_NAME') ?: 'your-bucket-name';
$app['bucket_name'] = getenv('GOOGLE_STORAGE_BUCKET') ?: 'your-bucket-name';
$app['project_id'] = getenv('GCLOUD_PROJECT');
$app['object_name'] = 'hello.txt';

Expand Down
8 changes: 4 additions & 4 deletions appengine/flexible/storage/test/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function setUp()
if (!getenv('GOOGLE_PROJECT_ID')) {
$this->markTestSkipped('Must set GOOGLE_PROJECT_ID');
}
if (!getenv('GOOGLE_BUCKET_NAME')) {
$this->markTestSkipped('Must set GOOGLE_BUCKET_NAME');
if (!getenv('GOOGLE_STORAGE_BUCKET')) {
$this->markTestSkipped('Must set GOOGLE_STORAGE_BUCKET');
}
parent::setUp();
$this->client = $this->createClient();
Expand All @@ -43,8 +43,8 @@ public function createApplication()

// the bucket name doesn't matter because we mock the stream wrapper
$app['project_id'] = getenv('GOOGLE_PROJECT_ID');
$app['bucket_name'] = getenv('GOOGLE_BUCKET_NAME');
$app['object_name'] = 'hello_flex.txt';
$app['bucket_name'] = getenv('GOOGLE_STORAGE_BUCKET');
$app['object_name'] = 'appengine/hello_flex.txt';

return $app;
}
Expand Down
Loading

0 comments on commit f44c03f

Please sign in to comment.