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

Decouple fabric tools image from fabric sample #1186

Merged
merged 2 commits into from
Apr 6, 2024

Conversation

SamYuan1990
Copy link
Contributor

@SamYuan1990 SamYuan1990 commented Mar 20, 2024

Decouple fabric tools image from fabric sample.
change list for running on github action:

  • network for orderer.
  • file path for add org3.
  • core.yaml missing?

The current PR seems has many code smells... but it seems works.

@SamYuan1990
Copy link
Contributor Author

Creating config transaction to add org3 to network
Using organization 1
++ peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /home/runner/work/fabric-samples/fabric-samples/test-network/addOrg3/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
Fetching the most recent configuration block for the channel
2024-03-20 15:09:14.997 UTC 0001 ERRO [main] InitCmd -> Fatal error when initializing core config : error when reading core config file: Config File "core" Not Found in "[/home/runner/work/fabric-samples/fabric-samples/test-network/addOrg3]"

@denyeart , I am got confused a little, could you please help with which core config is missing here? when we try to add org3?

@SamYuan1990 SamYuan1990 marked this pull request as ready for review March 20, 2024 15:53
@SamYuan1990 SamYuan1990 requested a review from a team as a code owner March 20, 2024 15:53
@SamYuan1990
Copy link
Contributor Author

@denyeart , please help retry failed test case and review this PR. :-)

Copy link
Contributor

@satota2 satota2 left a comment

Choose a reason for hiding this comment

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

@SamYuan1990 Thank you for submitting the PR.
I have some review comments:

  • I noticed the use of symbolic links for scripts and organizations folders, which might be confusing for beginners looking at the code. I believe it would be better to use relative paths instead of symbolic links. Would it be difficult to make this change?
  • Many of the modified files contain comments stating like "This script is designed to be run in the cli container," which should also be updated.
  • For org3, I think it's preferable to refer to core.yaml in fabric-samples/config, similar to org1 and 2, by setting the FABRIC_CFG_PATH instead of adding a new core file.
  • Additionally, the intermediate artifacts related to configtx that were previously generated within cli container, such as *.json, *.tx, and *.pb files, remain in the root of the test-network or addOrg3 directories. It might be better to generate these in a dedicated directory, like channel-artifacts, to keep things organized. Would this approach be feasible?
  • The Test Network SBE GitHub test seems to be failing due to a different issue unrelated to this PR, so it might be okay to ignore it for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

For org3, I think it's preferable to refer to core.yaml in fabric-samples/config, similar to org1 and 2, by setting the FABRIC_CFG_PATH instead of adding a new core file. Specifically, adjusting FABRIC_CFG_PATH in here to FABRIC_CFG_PATH=$PWD/../../config/ and appending this setting in here could potentially ensure it works as intended without the core.yaml.

@SamYuan1990
Copy link
Contributor Author

@SamYuan1990 Thank you for submitting the PR. I have some review comments:

  • I noticed the use of symbolic links for scripts and organizations folders, which might be confusing for beginners looking at the code. I believe it would be better to use relative paths instead of symbolic links. Would it be difficult to make this change?
  • Many of the modified files contain comments stating like "This script is designed to be run in the cli container," which should also be updated.
  • For org3, I think it's preferable to refer to core.yaml in fabric-samples/config, similar to org1 and 2, by setting the FABRIC_CFG_PATH instead of adding a new core file.
  • Additionally, the intermediate artifacts related to configtx that were previously generated within cli container, such as *.json, *.tx, and *.pb files, remain in the root of the test-network or addOrg3 directories. It might be better to generate these in a dedicated directory, like channel-artifacts, to keep things organized. Would this approach be feasible?
  • The Test Network SBE GitHub test seems to be failing due to a different issue unrelated to this PR, so it might be okay to ignore it for now.

@satota2, with my hands on, the most challenging for this PR is the loop of relative paths.
for example/to be details:
as https://github.com/hyperledger/fabric-samples/blob/main/test-network/compose/compose-test-net.yaml#L155
the docker compose provides a good beginning as the /scripts folder.

which makes https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/joinChannel.sh#L26 org3 related script starts from this absolute directory.

the symbolic links... provides the same folder structure, specific for the loop case.
for example a loop like:
https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/updateChannelConfig.sh#L27
https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/configUpdate.sh#L9

as those scripts also reused by org1 and org2, if we just change the scripts for org3, which will break the relative paths for org1 and org2.
hence, can we adjust org3's folder structure make it parallel with org1 and org2 to make all the orgs share the same behavior for every org, such as relative paths for shell, FABRIC_CFG_PATH and generate files?

@satota2
Copy link
Contributor

satota2 commented Mar 28, 2024

@satota2, with my hands on, the most challenging for this PR is the loop of relative paths. for example/to be details: as https://github.com/hyperledger/fabric-samples/blob/main/test-network/compose/compose-test-net.yaml#L155 the docker compose provides a good beginning as the /scripts folder.

which makes https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/joinChannel.sh#L26 org3 related script starts from this absolute directory.

the symbolic links... provides the same folder structure, specific for the loop case. for example a loop like: https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/updateChannelConfig.sh#L27 https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/configUpdate.sh#L9

as those scripts also reused by org1 and org2, if we just change the scripts for org3, which will break the relative paths for org1 and org2. hence, can we adjust org3's folder structure make it parallel with org1 and org2 to make all the orgs share the same behavior for every org, such as relative paths for shell, FABRIC_CFG_PATH and generate files?

@SamYuan1990
Thank you for your response.
I understand that this solution is challenging due to scripts being called from structurally different folders.
However, I believe we should avoid using symbolic links as it may lead to confusion.

As an alternative, what about using absolute paths in each script instead of relative ones?
For example, we could use dirname $0 in each script to dynamically obtain the absolute path of the script itself and use that as a starting point. What are your thoughts on this approach?

@SamYuan1990
Copy link
Contributor Author

@satota2, with my hands on, the most challenging for this PR is the loop of relative paths. for example/to be details: as https://github.com/hyperledger/fabric-samples/blob/main/test-network/compose/compose-test-net.yaml#L155 the docker compose provides a good beginning as the /scripts folder.
which makes https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/joinChannel.sh#L26 org3 related script starts from this absolute directory.
the symbolic links... provides the same folder structure, specific for the loop case. for example a loop like: https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/updateChannelConfig.sh#L27 https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/configUpdate.sh#L9
as those scripts also reused by org1 and org2, if we just change the scripts for org3, which will break the relative paths for org1 and org2. hence, can we adjust org3's folder structure make it parallel with org1 and org2 to make all the orgs share the same behavior for every org, such as relative paths for shell, FABRIC_CFG_PATH and generate files?

@SamYuan1990 Thank you for your response. I understand that this solution is challenging due to scripts being called from structurally different folders. However, I believe we should avoid using symbolic links as it may lead to confusion.

As an alternative, what about using absolute paths in each script instead of relative ones? For example, we could use dirname $0 in each script to dynamically obtain the absolute path of the script itself and use that as a starting point. What are your thoughts on this approach?

I see, let's try.

@SamYuan1990 SamYuan1990 marked this pull request as draft March 30, 2024 07:37
@SamYuan1990
Copy link
Contributor Author

2024-03-30 08:37:06.594 UTC 0001 ERRO [main] InitCmd -> Cannot run peer because cannot init crypto, specified path "/home/runner/work/fabric-samples/fabric-samples/test-network/addOrg3/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" does not exist or cannot be accessed: stat /home/runner/work/fabric-samples/fabric-samples/test-network/addOrg3/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp: no such file or directory

we can't simply using FABRIC_CFG_PATH=$PWD/../../config/ ... otherwise the msp folder will be wrong.

@SamYuan1990 SamYuan1990 force-pushed the decoupleFabricTools branch 2 times, most recently from 396f557 to 0e1e578 Compare March 30, 2024 09:23
@SamYuan1990 SamYuan1990 marked this pull request as ready for review March 30, 2024 09:33
@SamYuan1990
Copy link
Contributor Author

SamYuan1990 commented Mar 30, 2024

@satota2, with my hands on, the most challenging for this PR is the loop of relative paths. for example/to be details: as https://github.com/hyperledger/fabric-samples/blob/main/test-network/compose/compose-test-net.yaml#L155 the docker compose provides a good beginning as the /scripts folder.
which makes https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/joinChannel.sh#L26 org3 related script starts from this absolute directory.
the symbolic links... provides the same folder structure, specific for the loop case. for example a loop like: https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/org3-scripts/updateChannelConfig.sh#L27 https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/configUpdate.sh#L9
as those scripts also reused by org1 and org2, if we just change the scripts for org3, which will break the relative paths for org1 and org2. hence, can we adjust org3's folder structure make it parallel with org1 and org2 to make all the orgs share the same behavior for every org, such as relative paths for shell, FABRIC_CFG_PATH and generate files?

@SamYuan1990 Thank you for your response. I understand that this solution is challenging due to scripts being called from structurally different folders. However, I believe we should avoid using symbolic links as it may lead to confusion.
As an alternative, what about using absolute paths in each script instead of relative ones? For example, we could use dirname $0 in each script to dynamically obtain the absolute path of the script itself and use that as a starting point. What are your thoughts on this approach?

I see, let's try.

@satota2 , I suppose I found a way to make it by a env named as test_network_home please help review this PR. @denyeart , once this PR been merged, which means we decoupled fabric tools from fabric sample, then we can deprecated fabric tools image.

Signed-off-by: Sam Yuan <yy19902439@126.com>
Copy link
Contributor

@satota2 satota2 left a comment

Choose a reason for hiding this comment

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

@SamYuan1990

@satota2 , I suppose I found a way to make it by a env named as test_network_home please help review this PR. @denyeart , once this PR been merged, which means we decoupled fabric tools from fabric sample, then we can deprecated fabric tools image.

Thank you for your work. I believe this way of using an environment variable named test_network_home simplifies the process compared to the previous way that involved symbolic links, making it more understandable for the readers. Could you please refine the implementation following this direction?
I also think that using uppercase for the test_network_home environment variable would be preferable since it is a convention for environment variables.
Furthermore, I would appreciate it if you could reconsider the following comments:

  • For org3, it seems better to refer to core.yaml in fabric-samples/config, similar to org1 and 2, by setting the FABRIC_CFG_PATH instead of adding a new core file.
  • Additionally, the intermediate artifacts related to configtx that were previously generated within the cli container, such as *.json, *.tx, and *.pb files, remain in the root of the test-network or addOrg3 directories. It might be more organized to generate these in a dedicated directory, like channel-artifacts, to keep things tidy. Would this approach be workable?

@@ -34,7 +33,7 @@ fetchChannelConfig 1 ${CHANNEL_NAME} config.json

# Modify the configuration to append the new org
set -x
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ../organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ../organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ${test_network_home}/organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json

@SamYuan1990 SamYuan1990 marked this pull request as draft April 2, 2024 12:56
Signed-off-by: Sam Yuan <yy19902439@126.com>
@SamYuan1990 SamYuan1990 marked this pull request as ready for review April 2, 2024 13:40
@SamYuan1990 SamYuan1990 requested a review from satota2 April 2, 2024 13:41
Copy link
Contributor

@satota2 satota2 left a comment

Choose a reason for hiding this comment

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

@SamYuan1990, Cc: @denyeart

Thank you for the update. The code has been refined, and I was able to verify that Org3 can now be added in the local environment as well.
However, it appears that the following improvements I previously suggested have not yet been incorporated. Would it be possible for you to address these areas? We might consider merging this PR as it stands and then either you, I, or someone else could quickly create a new PR to tackle these areas for further code cleanup. How does that sound?

Comments for improvements I previously suggested:

  • I think that using uppercase for the test_network_home environment variable would be preferable since it is a convention for environment variables.
  • For org3, it seems better to refer to core.yaml in fabric-samples/config, similar to org1 and 2, by setting the FABRIC_CFG_PATH instead of adding a new core file.
  • The intermediate artifacts related to configtx that were previously generated within the cli container, such as *.json, *.tx, and *.pb files, remain in the root of the test-network or addOrg3 directories. It might be more organized to generate these in a dedicated directory, like channel-artifacts, to keep things tidy.

@SamYuan1990
Copy link
Contributor Author

@SamYuan1990, Cc: @denyeart

Thank you for the update. The code has been refined, and I was able to verify that Org3 can now be added in the local environment as well. However, it appears that the following improvements I previously suggested have not yet been incorporated. Would it be possible for you to address these areas? We might consider merging this PR as it stands and then either you, I, or someone else could quickly create a new PR to tackle these areas for further code cleanup. How does that sound?

Comments for improvements I previously suggested:

  • I think that using uppercase for the test_network_home environment variable would be preferable since it is a convention for environment variables.
  • For org3, it seems better to refer to core.yaml in fabric-samples/config, similar to org1 and 2, by setting the FABRIC_CFG_PATH instead of adding a new core file.
  • The intermediate artifacts related to configtx that were previously generated within the cli container, such as *.json, *.tx, and *.pb files, remain in the root of the test-network or addOrg3 directories. It might be more organized to generate these in a dedicated directory, like channel-artifacts, to keep things tidy.

hi @satota2 , my goal to have this PR is to proof we can deprecated fabric tools image but not make a perfect change for multiple org solution. Hence the enhancement or totally refactor can be in other PRs.

Copy link
Contributor

@satota2 satota2 left a comment

Choose a reason for hiding this comment

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

@SamYuan1990 Cc: @denyeart

hi @satota2 , my goal to have this PR is to proof we can deprecated fabric tools image but not make a perfect change for multiple org solution. Hence the enhancement or totally refactor can be in other PRs.

Thank you for your response. We'll mark the tasks up to this point as completed within this PR and do the refactoring and improvements in a new PR. Thanks for all your hard work so far.

Would you be interested in handling the refactoring? Your involvement would be welcome. However, if you prefer not to, that's perfectly fine. Either I or someone else can take it from there.

@SamYuan1990
Copy link
Contributor Author

SamYuan1990 commented Apr 4, 2024

@SamYuan1990 Cc: @denyeart

hi @satota2 , my goal to have this PR is to proof we can deprecated fabric tools image but not make a perfect change for multiple org solution. Hence the enhancement or totally refactor can be in other PRs.

Thank you for your response. We'll mark the tasks up to this point as completed within this PR and do the refactoring and improvements in a new PR. Thanks for all your hard work so far.

Would you be interested in handling the refactoring? Your involvement would be welcome. However, if you prefer not to, that's perfectly fine. Either I or someone else can take it from there.

Hi @satota2 , you can try with refactor and I would like to learn from it.

@satota2
Copy link
Contributor

satota2 commented Apr 4, 2024

Hi @SamYuan1990,

Hi @satota2 , you can try with refactor and I would like to learn from it.
OK! I will attempt the refactoring once we have merged this PR. Thank you once again for the hard work!

@satota2 satota2 merged commit ebbc419 into hyperledger:main Apr 6, 2024
38 of 40 checks passed
@satota2
Copy link
Contributor

satota2 commented Apr 6, 2024

Hi @SamYuan1990,

Hi @satota2 , you can try with refactor and I would like to learn from it.

OK! I will attempt the refactoring once we have merged this PR. Thank you once again for the hard work!

I've merged the PR and have now submitted a new PR (#1193) for the refactoring as discussed. Please take a look when you have a moment.

Hi @denyeart
Once the new PR (#1193) is merged, I think that the tasks related to removing fabric-tools on the fabric-samples side will be completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants