Skip to content

Commit b903bfd

Browse files
authored
Upgrades everything to env flex! (GoogleCloudPlatform#231)
* Upgrade endpoints to env flex (GoogleCloudPlatform#230) * WIP for endpoints on env:flex * updates tests for endpoints app - requires 'gcloud beta app deploy' * updates google/cloud-tools version for semantic versioning * upgrade pubsub sample to env:flex (GoogleCloudPlatform#228) * upgrades symfony sample to env:flex (GoogleCloudPlatform#227) * upgrades symfony sample to env:flex * updates google/cloud-tools version for semantic versioning * upgrade sendgrid sample to env flex (GoogleCloudPlatform#226) * upgrades staticcontent sample to env:flex (GoogleCloudPlatform#225) * upgradces twilio sample to env:flex (GoogleCloudPlatform#224) * update analytics sample for env:flex (GoogleCloudPlatform#222) * updates datastore sample to env:flex (GoogleCloudPlatform#221) * updates Mailgun sample for env:flex (GoogleCloudPlatform#220) * upgrades Mailjet sample for env:flex (GoogleCloudPlatform#219) * updates cloudsql sample to env:flex (GoogleCloudPlatform#218) * updates drupal sample for env:flex (GoogleCloudPlatform#217) * adds proper cs
2 parents 2b0e03b + 9593ac4 commit b903bfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+11266
-1411
lines changed

appengine/flexible/analytics/app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
runtime: php
2-
vm: true
2+
env: flex
33

44
runtime_config:
5-
document_root: web
5+
document_root: web
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/**
3+
* Copyright 2016 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+
namespace Google\Cloud\Samples\AppEngine\Analytics;
18+
19+
use Google\Cloud\TestUtils\AppEngineDeploymentTrait;
20+
21+
class DeployTest extends \PHPUnit_Framework_TestCase
22+
{
23+
use AppEngineDeploymentTrait;
24+
25+
public function testIndex()
26+
{
27+
// Access the modules app top page.
28+
$resp = $this->client->get('/');
29+
$this->assertEquals('200', $resp->getStatusCode(),
30+
'top page status code');
31+
$this->assertContains('returned 200', (string) $resp->getBody(),
32+
'top page content');
33+
}
34+
}

appengine/flexible/analytics/tests/LocalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
namespace Google\Cloud\Test;
17+
namespace Google\Cloud\Samples\AppEngine\Analytics;
1818

1919
use Silex\WebTestCase;
2020

appengine/flexible/cloudsql/README.md

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,23 @@ composer install
1919

2020
Before you can run or deploy the sample, you will need to do the following:
2121

22-
1. Create a [First Generation Cloud SQL](https://cloud.google.com/sql/docs/create-instance) instance. You can do this from the [Cloud Console](https://console.developers.google.com) or via the [Cloud SDK](https://cloud.google.com/sdk). To create it via the SDK use the following command:
22+
1. Create a [Second Generation Cloud SQL](https://cloud.google.com/sql/docs/create-instance) instance. You can do this from the [Cloud Console](https://console.developers.google.com) or via the [Cloud SDK](https://cloud.google.com/sdk). To create it via the SDK use the following command:
2323

24-
$ gcloud sql instances create YOUR_INSTANCE_NAME
24+
$ gcloud beta sql instances create YOUR_INSTANCE_NAME --tier=db-f1-micro --activation-policy=ALWAYS
2525

26-
1. Set the root password on your Cloud SQL instance:
26+
> Note: the `--tier` option is required to create a `Second Generation` instance. See the
27+
full list of available tiers by running `gcloud sql tiers list`
2728

28-
$ gcloud sql instances set-root-password YOUR_INSTANCE_NAME --password YOUR_INSTANCE_ROOT_PASSWORD
29-
30-
1. Update the connection string in `app.yaml` with your configuration values. These values are used when the application is deployed.
31-
32-
## Run locally
33-
34-
To run locally, you can either run your own MySQL server locally and set the connection string in `app.yaml`, or you can [connect to your CloudSQL instance externally](https://cloud.google.com/sql/docs/external#appaccess).
29+
2. Set the root password on your Cloud SQL instance:
3530

36-
```sh
37-
cd php-docs-samples/appengine/standard/cloudsql
31+
$ gcloud sql instances set-root-password YOUR_INSTANCE_NAME --password YOUR_INSTANCE_ROOT_PASSWORD
3832

39-
# set local mysql connection parameters
40-
export MYSQL_DSN="mysql:host=127.0.0.1;port=3306;dbname=guestbook"
41-
export MYSQL_USERNAME=root
42-
export MYSQL_PASSWORD=
33+
3. Install and run the [CloudSQL Proxy](https://cloud.google.com/sql/docs/mysql-connect-proxy)
4334

44-
php -S localhost:8080
45-
```
35+
4. Create a database for this example
4636

47-
> be sure the `MYSQL_` environment variables are appropriate for your mysql instance
37+
$ mysql -h 127.0.0.1 -u root -p -e "CREATE DATABASE ;"
4838

49-
Now you can view the app running at [http://localhost:8080](http://localhost:8080)
50-
in your browser.
5139

5240
## Deploy to App Engine
5341

@@ -57,6 +45,16 @@ in your browser.
5745

5846
**Deploy with gcloud**
5947

48+
1. Update `app.yaml` with the configuration values for `USER`, `PASSWORD`, and
49+
`DATABASE` with the values you used during setup.
50+
51+
1. Get the CloudSQL connection name
52+
53+
$ gcloud beta sql instances describe YOUR_INSTANCE_NAME | grep connectionName
54+
55+
1. Update `app.yaml` with the configuration value for `CONNECTION_NAME` you retrieved
56+
at the end up setup.
57+
6058
```
6159
gcloud config set project YOUR_PROJECT_ID
6260
gcloud app deploy
@@ -65,3 +63,28 @@ gcloud app browse
6563

6664
The last command will open `https://{YOUR_PROJECT_ID}.appspot.com/`
6765
in your browser.
66+
67+
## Run locally
68+
69+
1. Ensure the [CloudSQL Proxy](https://cloud.google.com/sql/docs/external#proxy) is
70+
installed and running.
71+
72+
1. Set the following environment variables with the configuration values for
73+
`USER`, `PASSWORD`, and `DATABASE` you used during setup:
74+
75+
```sh
76+
# set local mysql connection parameters
77+
export MYSQL_DSN="mysql:host=127.0.0.1;port=3306;dbname=DATABASE"
78+
export MYSQL_USERNAME=USER
79+
export MYSQL_PASSWORD=PASSWORD
80+
```
81+
82+
1. Run the application
83+
84+
```sh
85+
cd php-docs-samples/appengine/standard/cloudsql
86+
php -S localhost:8080
87+
```
88+
89+
Now you can view the app running at [http://localhost:8080](http://localhost:8080)
90+
in your browser.

appengine/flexible/cloudsql/app.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
runtime: php
2-
vm: true
2+
env: flex
33

4-
runtime_config:
5-
document_root: web
4+
#[START env]
5+
env_variables:
6+
# Replace USER, PASSWORD, DATABASE, and CONNECTION_NAME with the
7+
# values obtained when configuring your Cloud SQL instance.
8+
MYSQL_DSN: mysql:dbname=DATABASE;unix_socket=/cloudsql/CONNECTION_NAME
9+
MYSQL_USER: USER
10+
MYSQL_PASSWORD: PASSWORD
11+
#[END env]
12+
13+
#[START cloudsql_settings]
14+
# Use the connection name obtained when configuring your Cloud SQL instance.
15+
beta_settings:
16+
cloud_sql_instances: "CONNECTION_NAME"
17+
#[END cloudsql_settings]

appengine/flexible/cloudsql/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"require-dev": {
77
"google/cloud-tools": "<=1.0",
8+
"paragonie/random_compat": "^2.0",
89
"phpunit/phpunit": "~4"
910
}
1011
}

0 commit comments

Comments
 (0)