Skip to content

Commit

Permalink
Merge pull request #157 from softwaremill/issue-100/init-chaincode
Browse files Browse the repository at this point in the history
Init network with simple chaincode

Signed-off-by: Jakub Dzikowski <[email protected]>
  • Loading branch information
Jakub Dzikowski authored and Jakub Dzikowski committed Mar 17, 2021
1 parent 2140c08 commit 31d9f43
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ e2e-network
fabrica-target
node_modules
Jenkinsfile
samples/chaincodes
samples/chaincodes/chaincode-java-simple
samples/chaincodes/chaincode-kv-node/node_modules
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Validation of `fabrica-config.json` based on JSON schema and other rules
* Allow to upgrade chaincode ([#45](https://github.com/softwaremill/fabrica/issues/36))
* Network recreation in one step ([#105](https://github.com/softwaremill/fabrica/issues/105))
* Init command to provide simple config ([#90](https://github.com/softwaremill/fabrica/issues/90))
* Init command to provide simple config ([#90](https://github.com/softwaremill/fabrica/issues/90)) with chaincode ([#100](https://github.com/softwaremill/fabrica/issues/100))
* Proper exposing Orderer and Peers ports for service discovery ([#116](https://github.com/softwaremill/fabrica/issues/116))

### Fixes
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ FROM node:12.18.0-alpine3.12
RUN apk add --no-cache sudo shfmt
RUN npm install --global --silent yo

# copy fabrica files
COPY generators /fabrica/generators
COPY package.json /fabrica/package.json
COPY package-lock.json /fabrica/package-lock.json

# copy files for init network
COPY samples/fabricaConfig-1org-1channel-1chaincode.json /fabrica/generators/init/templates/fabrica-config.json
COPY samples/chaincodes/chaincode-kv-node /fabrica/generators/init/templates/chaincodes/chaincode-kv-node

WORKDIR /fabrica
RUN npm install --silent
RUN npm link
Expand Down
5 changes: 1 addition & 4 deletions e2e-network/test-01-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd
TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))"
FABRICA_HOME="$TEST_TMP/../.."

# testing relative path
CONFIG="../../samples/fabricaConfig-1org-1channel-1chaincode.json"

networkUpAsync() {
"$FABRICA_HOME/fabrica-build.sh" &&
(cd "$TEST_TMP" && "$FABRICA_HOME/fabrica.sh" generate "$CONFIG") &&
(cd "$TEST_TMP" && "$FABRICA_HOME/fabrica.sh" init) &&
(cd "$TEST_TMP" && "$FABRICA_HOME/fabrica.sh" up &)
}

Expand Down
11 changes: 7 additions & 4 deletions e2e/fabricaCommands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ describe('init', () => {
// Then
expect(commandResult).toEqual(TestCommands.success());
expect(commandResult.output).toContain('Sample config file created! :)');
expect(commandResult.output).toContain('Chaincode directory is \'./chaincodes/chaincode-kv-node\'.');
expect(commandResult.output).toContain('If it\'s empty your network won\'t run entirely.');
expect(commands.getFiles()).toEqual(['./e2e/__tmp__/commands-tests/fabrica-config.json']);
expect(commands.getFiles()).toEqual([
'./e2e/__tmp__/commands-tests/chaincodes/chaincode-kv-node/index.js',
'./e2e/__tmp__/commands-tests/chaincodes/chaincode-kv-node/package-lock.json',
'./e2e/__tmp__/commands-tests/chaincodes/chaincode-kv-node/package.json',
'./e2e/__tmp__/commands-tests/fabrica-config.json',
]);
expect(commands.getFileContent('fabrica-config.json')).toMatchSnapshot();
});
});
Expand Down Expand Up @@ -49,7 +52,7 @@ describe('validate', () => {
expect(commandResult).toEqual(TestCommands.success());
expect(commandResult.output).toContain('Validation errors count: 0');
expect(commandResult.output).toContain('Validation warnings count: 0');
expect(commands.getFiles()).toEqual(['./e2e/__tmp__/commands-tests/fabrica-config.json']);
expect(commands.getFiles()).toContain('./e2e/__tmp__/commands-tests/fabrica-config.json');
});

it('should validate custom config', () => {
Expand Down
2 changes: 1 addition & 1 deletion fabrica.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ useVersion() {

initConfig() {
executeOnFabricaDocker init
cp -R "$FABRICA_TEMP_DIR/." "$COMMAND_CALL_ROOT/"
cp -R -i "$FABRICA_TEMP_DIR/." "$COMMAND_CALL_ROOT/"
}

validateConfig() {
Expand Down
10 changes: 2 additions & 8 deletions generators/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
*/
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const simpleFabricaConfigJson = require('../../samples/fabricaConfig-1org-1channel-1chaincode');

module.exports = class extends Generator {
async copySampleConfig() {
this.fs.writeJSON(
'fabrica-config.json',
simpleFabricaConfigJson,
);
this.fs.copy(this.templatePath(), this.destinationPath());

this.on('end', () => {
this.log('===========================================================');
this.log(chalk.bold('Sample config file created! :)'));
this.log('');
this.log(`Chaincode directory is '${simpleFabricaConfigJson.chaincodes[0].directory}'.`);
this.log('If it\'s empty your network won\'t run entirely.');
this.log('You can start your network with \'fabrica up\' command');
this.log('===========================================================');
});
}
Expand Down

0 comments on commit 31d9f43

Please sign in to comment.