Merge branch 'master' into fix-average-functions-duration

This commit is contained in:
Vlad Golubev 2017-02-07 23:41:50 +02:00
commit e8bf95997e
9 changed files with 71 additions and 14 deletions

3
.gitignore vendored
View File

@ -40,3 +40,6 @@ admin.env
tmp
.coveralls.yml
tmpdirs-serverless
# ESLint cache
.eslintcache

View File

@ -1,7 +1,7 @@
<!--
title: Hello World Python Example
menuText: Hello World Python Example
description: Create a simple Python powered Lambda function
description: Create a Python Hello World Lambda function
layout: Doc
-->
@ -13,13 +13,14 @@ layout: Doc
Make sure `serverless` is installed. [See installation guide](../../../guide/installation.md).
## 1. Deploy
## 1. Create a service
`serverless create --template aws-python --path myService` or `sls create --template aws-python --path myService`, where 'myService' is a new folder to be created with template service files. Change directories into this new folder.
## 2. Deploy
`serverless deploy` or `sls deploy`. `sls` is shorthand for the serverless CLI command
## 2. Invoke deployed function
`serverless invoke --function helloWorld` or `serverless invoke -f helloWorld`
## 3. Invoke deployed function
`serverless invoke --function hello` or `serverless invoke -f hello`
`-f` is shorthand for `--function`
@ -27,7 +28,8 @@ In your terminal window you should see the response from AWS Lambda
```bash
{
"message": "Hello World"
"statusCode": 200,
"body": "{\"message\":\"Go Serverless v1.0! Your function executed successfully!\",\"input\":{}}"
}
```

View File

@ -296,6 +296,16 @@ class Utils {
hasCustomVariableSyntaxDefined = true;
}
// wrap in try catch to make sure that missing permissions won't break anything
let isDockerContainer = false;
try {
const cgroupFilePath = path.join('/', 'proc', '1', 'cgroup');
const cgroupFileContent = fs.readFileSync(cgroupFilePath).toString();
isDockerContainer = !!cgroupFileContent.match(/docker/);
} catch (exception) {
// do nothing
}
const data = {
userId,
event: 'framework_stat',
@ -336,6 +346,7 @@ class Utils {
userAgent: (process.env.SERVERLESS_DASHBOARD) ? 'dashboard' : 'cli',
serverlessVersion: serverless.version,
nodeJsVersion: process.version,
isDockerContainer,
isCISystem: !!((process.env.CI || process.env.JENKINS_URL) || false),
},
},

View File

@ -371,6 +371,25 @@ describe('Utils', () => {
});
});
it('should be able to detect Docker containers', () => {
const cgroupFileContent = '6:devices:/docker/3601745b3bd54d9780436faa5f0e4f72';
const cgroupFilePath = path.join('/', 'proc', '1', 'cgroup');
const cgroupFileContentStub = sinon.stub(fs, 'readFileSync')
.withArgs(cgroupFilePath)
.returns(cgroupFileContent);
utils.logStat(serverless).then(() => {
expect(cgroupFileContentStub.calledOnce).to.equal(true);
const parsedBody = JSON.parse(fetchStub.args[0][1].body);
expect(parsedBody.properties.general.isDockerContainer)
.to.equal(true);
fs.readFileSync.restore();
});
});
it('should send the gathered information', () => {
serverless.service = {
service: 'new-service',

View File

@ -3,6 +3,7 @@
const BbPromise = require('bluebird');
const path = require('path');
const fse = require('fs-extra');
const _ = require('lodash');
// class wide constants
const validTemplates = [
@ -66,9 +67,8 @@ class Create {
}
// store the custom options for the service if given
const boilerplatePath = this.options
.path && this.options.path.length ? this.options.path : null;
const serviceName = this.options.name && this.options.name.length ? this.options.name : null;
const boilerplatePath = _.toString(this.options.path);
const serviceName = _.toString(this.options.name);
// create (if not yet present) and chdir into the directory for the service
if (boilerplatePath) {

View File

@ -311,6 +311,30 @@ describe('Create', () => {
});
});
it('should create a service in the directory if using the "path" option with digits', () => {
const cwd = process.cwd();
fse.mkdirsSync(tmpDir);
process.chdir(tmpDir);
create.options.path = 123;
create.options.name = null;
// using the nodejs template (this test is completely be independent from the template)
create.options.template = 'aws-nodejs';
return create.create().then(() => {
const serviceDir = path.join(tmpDir, String(create.options.path));
// check if files are created in the correct directory
expect(create.serverless.utils.fileExistsSync(
path.join(serviceDir, 'serverless.yml'))).to.be.equal(true);
expect(create.serverless.utils.fileExistsSync(
path.join(serviceDir, 'handler.js'))).to.be.equal(true);
process.chdir(cwd);
});
});
it('should create a custom renamed service in the directory if using ' +
'the "path" and "name" option', () => {
const cwd = process.cwd();

View File

@ -50,7 +50,7 @@
},
"scripts": {
"test": "istanbul cover -x '**/*.test.js' node_modules/mocha/bin/_mocha '!(node_modules)/**/*.test.js' -- -R spec --recursive",
"lint": "eslint .",
"lint": "eslint . --cache",
"docs": "node scripts/generate-readme.js",
"simple-integration-test": "jest --maxWorkers=5 simple-suite",
"complex-integration-test": "jest --maxWorkers=5 integration",

View File

@ -1,10 +1,9 @@
const BbPromise = require('bluebird');
const Serverless = require('../lib/Serverless');
const serverless = new Serverless();
(() => {
serverless.init().then(() => {
serverless.utils.logStat(serverless, 'install').catch(() => BbPromise.resolve());
serverless.utils.logStat(serverless, 'install').catch(() => Promise.resolve());
});
})();

View File

@ -1,10 +1,9 @@
const BbPromise = require('bluebird');
const Serverless = require('../lib/Serverless');
const serverless = new Serverless();
(() => {
serverless.init().then(() => {
serverless.utils.logStat(serverless, 'uninstall').catch(() => BbPromise.resolve());
serverless.utils.logStat(serverless, 'uninstall').catch(() => Promise.resolve());
});
})();