diff --git a/.gitignore b/.gitignore index b7952abc4..266ff9083 100755 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ admin.env tmp .coveralls.yml tmpdirs-serverless + +# ESLint cache +.eslintcache diff --git a/docs/providers/aws/examples/hello-world/python/README.md b/docs/providers/aws/examples/hello-world/python/README.md index 011ee4d61..d1e432b60 100644 --- a/docs/providers/aws/examples/hello-world/python/README.md +++ b/docs/providers/aws/examples/hello-world/python/README.md @@ -1,7 +1,7 @@ @@ -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\":{}}" } ``` diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js index 01dbc1566..ec57f161c 100644 --- a/lib/classes/Utils.js +++ b/lib/classes/Utils.js @@ -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), }, }, diff --git a/lib/classes/Utils.test.js b/lib/classes/Utils.test.js index b45f139a1..03f438d1b 100644 --- a/lib/classes/Utils.test.js +++ b/lib/classes/Utils.test.js @@ -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', diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index 8da0f8a30..1bc0991e6 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -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) { diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index d35e8f4c5..5597ec357 100644 --- a/lib/plugins/create/create.test.js +++ b/lib/plugins/create/create.test.js @@ -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(); diff --git a/package.json b/package.json index e35fcc094..4ca9249b6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/postinstall.js b/scripts/postinstall.js index fde4a3cbc..24c69ecd2 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -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()); }); })(); diff --git a/scripts/preuninstall.js b/scripts/preuninstall.js index 085d6c2b4..7f372539a 100644 --- a/scripts/preuninstall.js +++ b/scripts/preuninstall.js @@ -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()); }); })();