Skip to content

Commit 07ecd7f

Browse files
committed
Initial commit
0 parents  commit 07ecd7f

13 files changed

+8649
-0
lines changed

.eslintrc.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2017
4+
},
5+
"env": {
6+
"node": true,
7+
"es6": true
8+
},
9+
"extends": "eslint:recommended",
10+
"rules": {
11+
"indent": [
12+
"warn",
13+
2
14+
],
15+
"linebreak-style": [
16+
"warn",
17+
"unix"
18+
],
19+
"quotes": [
20+
"warn",
21+
"single"
22+
],
23+
"semi": [
24+
"warn",
25+
"always"
26+
],
27+
"prefer-const": [
28+
"warn",
29+
{
30+
"destructuring": "any",
31+
"ignoreReadBeforeAssign": false
32+
}
33+
],
34+
"strict": [
35+
"error",
36+
"global"
37+
]
38+
}
39+
}

.gitignore

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# lambda-bin-perf folders
2+
bin
3+
.serverless
4+
.bin-minify
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
65+
# next.js build output
66+
.next

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 BotBits (SM)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# lambda-bin-perf
2+
3+
## Running the Example
4+
5+
Follow these steps to run this example:
6+
7+
1. Install all dependencies with:
8+
9+
`npm install`
10+
11+
2. Prepare the bin folder with:
12+
13+
`gulp`
14+
15+
3. Deploy it all to AWS with (make sure to [setup AWS credentials](https://serverless.com/framework/docs/providers/aws/guide/credentials/) first):
16+
17+
`npm run serverless`
18+
19+
4. Edit `script.yml` and replace `My_StackOutputs_ServiceEndpoint` with the `serverless` `Stack Outputs` for your `ServiceEndpoint`.
20+
21+
5. Run tests
22+
23+
`npm run perf-original`
24+
25+
`npm run perf-lambdaBin`
26+
27+
6. Compare results.
28+
29+
30+
## Customize for Your Needs
31+
32+
Follow these steps to customize this example:
33+
34+
1. Replace dependencies in `package.json` to include your own dependencies.
35+
36+
2. Change `gulpfile.js` to prepare your `bin` folder.
37+
38+
3. Change `test-original.js` to invoke your own code (added to `package.json` on step 1).
39+
40+
4. Change `index.js` to invoke your code using `lambda-bin` instead or your current binary deployment approach.
41+
42+
5. Follow the steps under section `Running the Example`.
43+
44+
## Cleanup AWS Account
45+
46+
Once you are done testing clean up your AWS account by running:
47+
48+
`npm run cleanup`

config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-env node */
2+
'use strict';
3+
4+
const path = require('path');
5+
exports.GIT_BIN_PATH = path.resolve(__dirname, path.join('bin', 'git'));
6+
exports.MIN_PACK_PATH = '.bin-minify';
7+
exports.MIN_PACK_FILENAME = 'git.json';

gulpfile.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-env node */
2+
'use strict';
3+
4+
const fs = require('fs');
5+
const fse = require('fs-extra');
6+
const gulp = require('gulp');
7+
const file = require('gulp-file');
8+
const path = require('path');
9+
const tar = require('tar-fs');
10+
const stagingWorkflow = require('bin-minify').StagingWorkflow;
11+
12+
const {
13+
GIT_BIN_PATH,
14+
MIN_PACK_PATH,
15+
MIN_PACK_FILENAME,
16+
} = require('./config');
17+
18+
const GIT_FILENAME = path.join('node_modules', 'lambda-git', 'git-2.4.3.tar');
19+
20+
gulp.task('default', async (done) => {
21+
fse.ensureDirSync(GIT_BIN_PATH);
22+
23+
await fs.createReadStream(path.resolve(__dirname, GIT_FILENAME))
24+
.pipe(tar.extract(GIT_BIN_PATH))
25+
.on('finish', () => {
26+
const options = {
27+
sendToTrash: false,
28+
dryRun: false,
29+
strict: false,
30+
};
31+
stagingWorkflow(GIT_BIN_PATH, options).then(minPack => {
32+
file(MIN_PACK_FILENAME, JSON.stringify(minPack, null, ' '), {src: true})
33+
.pipe(gulp.dest(MIN_PACK_PATH));
34+
done();
35+
}, error => {
36+
console.error(`Could not create minPack: ${error}`); // eslint-disable-line no-console
37+
done();
38+
});
39+
});
40+
});

index.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* eslint-env node */
2+
'use strict';
3+
4+
const path = require('path');
5+
const RuntimeBin = require('lambda-bin');
6+
7+
const {
8+
GIT_BIN_PATH,
9+
MIN_PACK_PATH,
10+
MIN_PACK_FILENAME,
11+
} = require('./config');
12+
const MIN_PACK = require(path.resolve(MIN_PACK_PATH, MIN_PACK_FILENAME));
13+
14+
exports.installGit = function (options) {
15+
return new Promise((resolve, reject) => {
16+
options = options || {};
17+
18+
var targetDirectory = options.targetDirectory || '/tmp/git';
19+
var updateEnv = (options.updateEnv !== undefined) ? options.updateEnv : true;
20+
21+
var GIT_TEMPLATE_DIR = path.join(targetDirectory, 'usr/share/git-core/templates');
22+
var GIT_EXEC_PATH = path.join(targetDirectory, 'usr/libexec/git-core');
23+
var LD_LIBRARY_PATH = path.join(targetDirectory, 'usr/lib64');
24+
var binPath = path.join(targetDirectory, 'usr/bin');
25+
26+
var lambdaBinRuntime = new RuntimeBin({
27+
useSymlinks: true,
28+
targetPath: GIT_BIN_PATH,
29+
minPack: MIN_PACK,
30+
});
31+
lambdaBinRuntime.applyMinPack(targetDirectory).then(() => {
32+
if (updateEnv) {
33+
process.env.PATH = process.env.PATH + ':' + binPath;
34+
process.env.GIT_TEMPLATE_DIR = GIT_TEMPLATE_DIR;
35+
process.env.GIT_EXEC_PATH = GIT_EXEC_PATH;
36+
process.env.LD_LIBRARY_PATH = process.env.LD_LIBRARY_PATH
37+
? process.env.LD_LIBRARY_PATH + ':' + LD_LIBRARY_PATH
38+
: LD_LIBRARY_PATH;
39+
resolve();
40+
} else {
41+
resolve({
42+
binPath: binPath,
43+
env: {
44+
GIT_TEMPLATE_DIR: GIT_TEMPLATE_DIR,
45+
GIT_EXEC_PATH: GIT_EXEC_PATH,
46+
LD_LIBRARY_PATH: LD_LIBRARY_PATH
47+
}
48+
});
49+
}
50+
}, error => {
51+
reject(new Error(`lambda-git failed to load: ${error}`));
52+
});
53+
54+
});
55+
};

0 commit comments

Comments
 (0)