Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql"
value: "appengine/cloudsql/flexible"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql"
value: "appengine/cloudsql/standard/basic"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node10/cloudsql-standard-cnx-pooling.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql/standard/connection-pooling"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node10/cloudsql_postgresql-flex.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/flexible"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node10/cloudsql_postgresql-standard-basic.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/standard/basic"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/standard/connection-pooling"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql"
value: "appengine/cloudsql/flexible"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node6/cloudsql_postgresql-flex.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/flexible"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql"
value: "appengine/cloudsql/flexible"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql"
value: "appengine/cloudsql/standard/basic"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node8/cloudsql-standard-cnx-pooling.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql/standard/connection-pooling"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node8/cloudsql_postgresql-flex.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/flexible"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
13 changes: 13 additions & 0 deletions .kokoro/appengine/node8/cloudsql_postgresql-standard-basic.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/standard/basic"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Set the folder in which the tests are run
env_vars: {
key: "PROJECT"
value: "appengine/cloudsql_postgresql/standard/connection-pooling"
}

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
13 changes: 0 additions & 13 deletions .kokoro/appengine/node8/cloudsql_postgresql.cfg

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
This sample application shows how to use [Google Cloud SQL][sql] for [MySQL][mysql]
on Google App Engine.

[App Engine standard environment][appengine-std] users: See tutorial [Using Cloud SQL for MySQL (App Engine Standard Environment)][std-tutorial] for more information on running and deploying this app.

[App Engine flexible environment][appengine-flex] users: See tutorial [Using Cloud SQL for MySQL (App Engine Flexible Environment)][flex-tutorial] for more information on running and deploying this app.

[sql]: https://cloud.google.com/sql/
[mysql]: https://www.mysql.com/downloads/
[appengine-flex]: https://cloud.google.com/appengine/docs/flexible/nodejs
[appengine-std]: https://cloud.google.com/appengine/docs/standard/nodejs
[flex-tutorial]: https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql
[std-tutorial]: https://cloud.google.com/appengine/docs/standard/nodejs/using-cloud-sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appengine-cloudsql-mysql",
"description": "Node.js MySQL sample for Cloud SQL on App Engine.",
"name": "appengine-cloudsql-mysql-flexible",
"description": "Node.js MySQL sample for Cloud SQL on App Engine flexible.",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions appengine/cloudsql/standard/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Cloud SQL for MySQL Node.js sample on App Engine standard environment

This sample application shows how to use [Google Cloud SQL][sql] for [MySQL][mysql]
on Google App Engine.

See [Using Cloud SQL for MySQL (App Engine Standard Environment)][std-tutorial] for more information.

[sql]: https://cloud.google.com/sql/
[mysql]: https://www.mysql.com/downloads/
[appengine-std]: https://cloud.google.com/appengine/docs/standard/nodejs
[std-tutorial]: https://cloud.google.com/appengine/docs/standard/nodejs/using-cloud-sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

runtime: nodejs8
runtime: nodejs10

# [START gae_mysql_env]
# The following env variables may contain sensitive information that grants
Expand All @@ -23,9 +23,3 @@ env_variables:
# e.g. my-awesome-project:us-central1:my-cloud-sql-instance
INSTANCE_CONNECTION_NAME: YOUR_INSTANCE_CONNECTION_NAME
# [END gae_mysql_env]

beta_settings:
# The connection name of your instance, available by using
# 'gcloud beta sql instances describe [INSTANCE_NAME]' or from
# the Instance details page in the Google Cloud Platform Console.
cloud_sql_instances: YOUR_INSTANCE_CONNECTION_NAME
62 changes: 62 additions & 0 deletions appengine/cloudsql/standard/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "appengine-cloudsql-mysql-standard",
"description": "Node.js MySQL sample for Cloud SQL on App Engine standard.",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": ">=8"
},
"scripts": {
"lint": "repo-tools lint",
"pretest": "npm run lint",
"unit-test": "ava --verbose test/*.test.js",
"start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &",
"system-test": "repo-tools test app -- server.js",
"system-test-proxy": "npm run start-proxy; npm run system-test",
"all-test": "npm run unit-test && npm run system-test",
"test": "repo-tools test run --cmd npm -- run all-test"
},
"dependencies": {
"express": "4.16.3",
"mysql": "2.15.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.3.0",
"ava": "0.25.0",
"semistandard": "^12.0.1"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
"requiresProjectId": true,
"test": {
"app": {
"requiredEnvVars": [
"SQL_USER",
"SQL_PASSWORD",
"SQL_DATABASE",
"SQL_PORT",
"INSTANCE_CONNECTION_NAME"
],
"msg": "Current time:",
"args": [
"server.js"
]
},
"build": {
"requiredEnvVars": [
"SQL_USER",
"SQL_PASSWORD",
"SQL_DATABASE",
"SQL_PORT",
"INSTANCE_CONNECTION_NAME"
]
}
}
}
}
63 changes: 63 additions & 0 deletions appengine/cloudsql/standard/basic/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2018, Google, LLC.
* 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.
*/

'use strict';

const express = require('express');
const mysql = require('mysql');

const app = express();

const dbConfig = {
user: process.env.SQL_USER,
password: process.env.SQL_PASSWORD,
database: process.env.SQL_DATABASE
};

// When deployed to App Engine, the `NODE_ENV` environment variable will be
// set to `production`.
if (process.env.INSTANCE_CONNECTION_NAME &&
process.env.NODE_ENV === 'production') {
// If deployed, use the local socket interface for accessing Cloud SQL.
// If running locally, use the the TCP connection instead.
// mysql package by default connects to localhost:3306.
// Set up Cloud SQL Proxy (cloud.google.com/sql/docs/mysql/sql-proxy)
// so that your application can use localhost:3306 to connect to your
// Cloud SQL instance.
dbConfig.socketPath = `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`;
}

app.get(`/`, (req, res, next) => {
var connection = mysql.createConnection(dbConfig);
connection.query(
`SELECT NOW() as now`,
function (error, results, fields) {
if (error) throw error;
var now = results[0].now;
res
.status(200)
.send(`Current time: ${now}`)
.end();
}
);
});

const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`App listening on port ${port}`);
console.log('Press Ctrl+C to quit.');
});

module.exports = app;
Loading