Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge samples for Flex and Std #590

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 28 additions & 3 deletions appengine/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Google App Engine Node.js Samples

These are samples for using [Node.js][nodejs] on
[Google App Engine Flexible Environment][appengine]. Many of these samples
[Google App Engine][appengine]. Many of these samples
are referenced from the documentation on [cloud.google.com][appengine].

There are also samples [submitted by the community][community_samples].
Expand Down Expand Up @@ -57,17 +57,42 @@ The App Engine Node.js samples typically that you do the following:

## Deploying

Some samples in this repositories may have special deployment instructions.
Some samples may have special deployment instructions.
Refer to the `README.md` file in the sample folder.

Many samples in this folder can be deployed to both App Engine Node.js Standard
Environment and Flexible Environment. Those samples come with two different
App Engine configuration files: `app.flexible.yaml` for Flexible Environment,
and `app.standard.yaml` for Standard Environment.

Samples with one single configuration file, `app.yaml`, can only be deployed
to one of the two environments. See the `README.md` files for these samples
for more information.

Generally speaking, to deploy a sample application:

1. Use the [Google Cloud Console][console] to create a Google Cloud Platform
project.
1. [Enable billing][billing] for your project.

1. Use the Cloud SDK to deploy your app.

For samples with two configuration files (`app.flexible.yaml` and
`app.standard.yaml`), if you plan to use App Engine Node.js Standard
Environment, run

gcloud app deploy app.standard.yaml

To deploy to App Engine Node.js Flexible Environment, run

gcloud app deploy app.flexible.yaml

For samples with one configuration file (`app.yaml`), run

gcloud app deploy

to deploy the app to its compatible environment.

Note: If there is a `yarn.lock` file then `yarn install` will be used during
deployment. Delete the `yarn.lock` file to fall back to `npm install`.

Expand All @@ -82,7 +107,7 @@ View the [Official App Engine Node.js samples][official_samples].
View the [Community-contributed App Engine Node.js samples][community_samples].

[nodejs]: https://nodejs.org/
[appengine]: https://cloud.google.com/appengine/docs/flexible/nodejs/
[appengine]: https://cloud.google.com/appengine/
[nodejs_dev]: https://cloud.google.com/community/tutorials/how-to-prepare-a-nodejs-dev-environment
[sdk]: https://cloud.google.com/sdk/
[console]: https://console.cloud.google.com
Expand Down
24 changes: 14 additions & 10 deletions appengine/analytics/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Integrating with Google Analytics

This is the sample application for the
[Integrating with Google Analytics tutorial][tutorial] tutorial found in the
[Google App Engine Node.js Flexible Environment][appengine] documentation.
This sample application shows how to integrate your Node.js application with
Google Analytics on Google App Engine.

App Engine Node.js Standard Environment users: See tutorial [Integrating with Google Analytics][std-tutorial] for more information on running and deploying this app.

App Engine Node.js Flexible Environment users: See tutorial [Integrating with Google Analytics][flex-tutorial] for more information on running and deploying this app.

* [Setup](#setup)
* [Running locally](#running-locally)
Expand Down Expand Up @@ -37,22 +40,23 @@ or with `yarn`:

GA_TRACKING_ID=YOUR_TRACKING_ID yarn start

## Deploying to App Engine
## Deploying to App Engine Standard Environment

With `npm`:
gcloud app deploy app.standard.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - these indentations are different.


npm run deploy
## Deploying to App Engine Flexible Environment

or with `yarn`:
gcloud app deploy app.flexible.yaml

yarn run deploy

## Running the tests

See [Contributing][contributing].

[appengine]: https://cloud.google.com/appengine/docs/flexible/nodejs
[tutorial]: https://cloud.google.com/appengine/docs/flexible/nodejs/integrating-with-analytics
[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/integrating-with-analytics
[std-tutorial]: https://cloud.google.com/appengine/docs/standard/nodejs/integrating-with-analytics
[readme]: ../README.md
[tracking]: https://support.google.com/analytics/answer/1042508
[contributing]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/CONTRIBUTING.md
File renamed without changes.
21 changes: 21 additions & 0 deletions appengine/analytics/app.standard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.

# [START app_yaml]
runtime: nodejs8

# [START env]
env_variables:
GA_TRACKING_ID: YOUR_TRACKING_ID
# [END env]
# [END app_yaml]
8 changes: 3 additions & 5 deletions appengine/analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appengine-analytics",
"description": "Sample for Google Analytics Measurement Protocol on Google App Engine Flexible Environment.",
"description": "Sample for Google Analytics Measurement Protocol on Google App Engine.",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
Expand All @@ -10,16 +10,14 @@
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": ">=4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmdobry @lukesneeringer Which versions of Node do we support? AFAIK, this is too restrictive (at least for Flex).

@michaelawyu if you make any changes as a result of this comment, please apply those changes to any other package.json files that have this issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 4+, until April 30 when Node 4 reaches end of life and we can switch our samples to support Node 6+

"node": "8.x.x"
},
"scripts": {
"deploy": "gcloud app deploy",
"start": "node app.js",
"lint": "repo-tools lint",
"pretest": "npm run lint",
"system-test": "repo-tools test app",
"test": "npm run system-test",
"e2e-test": "repo-tools test deploy"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed? (Perhaps because npm run deploy no longer works?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's removed because npm run deploy no longer works.

"test": "npm run system-test"
},
"dependencies": {
"express": "4.16.2",
Expand Down
38 changes: 38 additions & 0 deletions appengine/building-an-app/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Writing Your Web Service Sample for Node.js in the App Engine Standard Environment

This is the sample application for the
[Writing Your Web Service with Node.js][tutorial]
tutorial found in the [Google App Engine Node.js Standard Environment][appengine]
documentation.

* [Setup](#setup)
* [Running locally](#running-locally)
* [Deploying to App Engine](#deploying-to-app-engine)
* [Running the tests](#running-the-tests)

## Setup

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

1. Refer to the [appengine/README.md][readme] file for instructions on
running and deploying.
1. Install dependencies:

npm install

## Running locally

npm start

## Deploying to App Engine

npm run deploy

## Running the tests

See [Contributing][contributing].

[appengine]: https://cloud.google.com/appengine/docs/standard/nodejs
[tutorial]: https://cloud.google.com/appengine/docs/standard/nodejs/building-app/writing-web-service
[readme]: ../../README.md
[contributing]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/CONTRIBUTING.md
16 changes: 16 additions & 0 deletions appengine/building-an-app/build/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2018, 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.

# [START app_yaml]
runtime: nodejs8
# [END app_yaml]
29 changes: 29 additions & 0 deletions appengine/building-an-app/build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "appengine-standard-getting-started-build-apps",
"version": "0.0.1",
"description": "Node.js getting started sample for building an app on App Engine standard environment.",
"private": true,
"main": "server.js",
"scripts": {
"lint": "samples lint",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In README.md, you specify start and deploy scripts. Make sure to add those (and their respective commands) here, or remove them from your README.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

"pretest": "npm run lint",
"test": "ava --verbose test/*.test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": "8.x.x"
},
"author": "Google Inc.",
"license": "Apache-2.0",
"dependencies": {
"express": "^4.16.3"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.22.0",
"semistandard": "^12.0.1"
}
}
33 changes: 33 additions & 0 deletions appengine/building-an-app/build/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2018, 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.
*/

'use strict';

// [START app]
const express = require('express');
const app = express();

app.get('/', (req, res) => {
res.send('Hello from App Engine!');
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
// [END app]

module.exports = app;
36 changes: 36 additions & 0 deletions appengine/building-an-app/build/test/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2018, 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.

'use strict';

const path = require(`path`);
const test = require(`ava`);
const utils = require(`@google-cloud/nodejs-repo-tools`);

const cwd = path.join(__dirname, `../`);
const requestObj = utils.getRequest({
cwd: cwd,
cmd: `server` });

test.beforeEach(utils.stubConsole);
test.afterEach.always(utils.restoreConsole);

test.cb.serial(`should send greetings`, (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmdobry what are your thoughts on using repo-tools instead of this test file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can still do the same tests while deleting code, let's do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for building-an-app/build/ are now done by repo-tools.

requestObj
.get(`/`)
.expect(200)
.expect((response) => {
t.is(response.text, `Hello from App Engine!`);
})
.end(t.end);
});
38 changes: 38 additions & 0 deletions appengine/building-an-app/update/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Updating Your Web Service Sample for Node.js in the App Engine Standard Environment

This is the sample application for the
[Updating Your Web Service][tutorial]
tutorial found in the [Google App Engine Node.js Standard Environment][appengine]
documentation.

* [Setup](#setup)
* [Running locally](#running-locally)
* [Deploying to App Engine](#deploying-to-app-engine)
* [Running the tests](#running-the-tests)

## Setup

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

1. Refer to the [appengine/README.md][readme] file for instructions on
running and deploying.
1. Install dependencies:

npm install

## Running locally

npm start

## Deploying to App Engine

npm run deploy

## Running the tests

See [Contributing][contributing].

[appengine]: https://cloud.google.com/appengine/docs/standard/nodejs
[tutorial]: https://cloud.google.com/appengine/docs/standard/nodejs/building-app/updating-web-service
[readme]: ../../README.md
[contributing]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/CONTRIBUTING.md
16 changes: 16 additions & 0 deletions appengine/building-an-app/update/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2018, 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.

# [START app_yaml]
runtime: nodejs8
# [END app_yaml]
Loading