Skip to content

Commit

Permalink
Modify chaincode packaging to comply
Browse files Browse the repository at this point in the history
FAB-2494
- only include files, no directories
- all file permissions are set to -rw-r-r

Change-Id: I0c0498b23ff917d01ffb149ef9b263da948f164c
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Feb 27, 2017
1 parent 64c7bb1 commit bc36ef5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
36 changes: 26 additions & 10 deletions fabric-client/lib/packager/Golang.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var tar = require('tar-fs');
var path = require('path');
var zlib = require('zlib');
var utils = require('../utils.js');
var dir = require('node-dir');

var logger = utils.getLogger('packager/Golang.js');

Expand Down Expand Up @@ -49,16 +50,30 @@ module.exports.package = function(chaincodePath) {
fs.copy(projDir, dest, (err) => {
if (err) return reject(new Error('Failed to copy chaincode source to temp folder. ' + err));

let targzFilePath = path.join(folder, 'deployment-package.tar.gz');
return generateTarGz(folder, targzFilePath)
.then(function() {
logger.debug('Successfully generated chaincode archive %s ', targzFilePath);
return utils.readFile(targzFilePath)
.then((data) => {
logger.debug('Successful readFile to data in bytes');
return resolve(data);
});
// first set the mode of all files to -rw-r--r--
dir.files(dest, (err, files) => {
if (err) return reject(new Error('Failed to iterate over files and subdirectories of the destination folder. ' + err));

let entries = [];
files.forEach((file) => {
fs.chmodSync(file, '644');

let entry = path.relative(folder, file);
logger.info('Chaincode package entry: ' + entry);
entries.push(entry);
});

let targzFilePath = path.join(folder, 'deployment-package.tar.gz');
return generateTarGz(folder, targzFilePath, entries)
.then(function() {
logger.debug('Successfully generated chaincode archive %s ', targzFilePath);
return utils.readFile(targzFilePath)
.then((data) => {
logger.debug('Successful readFile to data in bytes');
return resolve(data);
});
});
});
});
});
});
Expand All @@ -68,7 +83,7 @@ module.exports.package = function(chaincodePath) {
// generateTarGz creates a .tar.gz file from contents in the src directory and
// saves them in a dest file.
//
function generateTarGz(src, dest) {
function generateTarGz(src, dest, entries) {
// A list of file extensions that should be packaged into the .tar.gz.
// Files with all other file extenstions will be excluded to minimize the size
// of the install payload.
Expand All @@ -83,6 +98,7 @@ function generateTarGz(src, dest) {
return new Promise(function(resolve, reject) {
// Create the pack stream specifying the ignore/filtering function
var pack = tar.pack(src, {
entries: entries,
ignore: function(name) {
// Check whether the entry is a file or a directory
if (fs.statSync(name).isDirectory()) {
Expand Down
1 change: 1 addition & 0 deletions fabric-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"jssha": "^2.1.0",
"lodash": "^4.15.0",
"nconf": "^0.8.4",
"node-dir": "^0.1.16",
"node.extend": "^1.1.5",
"path": "^0.12.7",
"pkcs11js": "^1.0.6",
Expand Down

0 comments on commit bc36ef5

Please sign in to comment.