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

Use lambda-git #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file removed opt/git-2.4.3.tar
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"aws-sdk": "^2.72.0",
"debug": "^2.6.3",
"github": "^9.2.0",
"lambda-git": "^0.1.2",
"nconf": "^0.8.4",
"q": "^1.5.0",
"serverless-prune-plugin": "^1.0.4",
Expand Down
4 changes: 1 addition & 3 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ package:
# only the following paths will be included in the resulting artifact which will be uploaded. Without specific include everything in the current folder will be included
include:
- src
- functions
- opt
# The following paths will be excluded from the resulting artifact. If both include and exclude are defined we first apply the include, then the exclude so files are guaranteed to be excluded
exclude:
- tmp
Expand Down Expand Up @@ -125,4 +123,4 @@ resources:

plugins:
- serverless-prune-plugin
- serverless-offline
- serverless-offline
27 changes: 15 additions & 12 deletions src/common/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ var q = require("q"); // npm install q
var fs = require('fs')
var path = require('path');

var targetDirectory = path.resolve(__dirname, "../../opt/")
var GIT_TEMPLATE_DIR = path.resolve(targetDirectory, 'usr/share/git-core/templates');
var GIT_EXEC_PATH = path.resolve(targetDirectory, 'usr/libexec/git-core');

process.env.PATH = path.resolve(targetDirectory, 'usr/bin') + ":" + process.env.PATH ;
process.env.GIT_TEMPLATE_DIR = GIT_TEMPLATE_DIR;
process.env.GIT_EXEC_PATH = GIT_EXEC_PATH;


module.exports.cloneRepo = function(gitRemote, destination){
return execGitCmd(`git clone --depth 1 ${gitRemote} ${destination}`)
}
Expand Down Expand Up @@ -58,9 +49,21 @@ module.exports.pushRepo = function(repoPath, branchName){
return execGitCmd(`git push origin ${branchName}`, repoPath)
}


var GitPath = '/tmp/git.gitmask';
var gitExpand = false;

function execGitCmd(cmd, cwd, env){
if (gitExpand && fs.existsSync(GitPath)) {
// Use the existing one as it takes much time to expand git everytime.
return execGitCmdImpl(cmd, cwd, env);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

process.js often fails for timeouts ( > 40s) without this.

return require('lambda-git')({targetDirectory: GitPath}).then(function(){
gitExpand = true;
return execGitCmdImpl(cmd, cwd, env);
});
}

function execGitCmdImpl(cmd, cwd, env){
var opts = {}
if(cwd){
opts.cwd = cwd;
Expand All @@ -78,5 +81,5 @@ function execGitCmd(cmd, cwd, env){
if (err) return deferred.reject(err);
return deferred.resolve(stdout)
});
return deferred.promise
}
return deferred.promise;
}