Skip to content

Commit

Permalink
[fabric] Update ansible playbooks for create a channel
Browse files Browse the repository at this point in the history
**Primary Changes**

1.Deploy fabric 2.5.4 with channel using ansible.
2.Deploy fabric 2.2.2 with channel using ansible.

fixes #2576

Signed-off-by: mgCepeda <[email protected]>
  • Loading branch information
mgCepeda authored and suvajit-sarkar committed Jun 28, 2024
1 parent 80199da commit 6f02471
Show file tree
Hide file tree
Showing 45 changed files with 455 additions and 541 deletions.
67 changes: 47 additions & 20 deletions docs/source/guides/fabric/add-new-channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This guide explains how to add a new channel in a Hyperledger Fabric network usi

1. Using the `add-new-channel.yaml` playbook: This method involves running an Ansible playbook that automates the process of adding a new channel to the network.

1. Using `helm install`: This method involves using the `helm install` commands to directly add a new channel to the network.
2. Using `helm install`: This method involves using the `helm install` commands to directly add a new channel to the network.

## Prerequisites
- A fully configured Fabric network with Orderers, Peers, Peer Organization.
Expand All @@ -22,36 +22,63 @@ This guide explains how to add a new channel in a Hyperledger Fabric network usi

## Method 1: Using the `add-new-channel.yaml` playbook

1. **Update Configuration File**
1. **Add a defined channel with genesis or channeltx generated in basic deployment**

- Edit the `network.yaml` file to include a new channel with the following details:
- `channel_status: new`
- `org_status: existing`
- Organization details (name, CA address, MSP ID, etc.)
- Orderer information
- Remove existing channels or use `channel_status: existing`
- Refer to the [networkyaml-fabric.md](../networkyaml-fabric.md) guide for details on editing the configuration file.
**Update Configuration File**

Snippet from `network.channels` section below:
- Edit the `network.yaml` file to include a channel with the following details:
- Organization details (name, CA address, MSP ID, etc.)
- Orderer information
- Refer to the [networkyaml-fabric.md](../networkyaml-fabric.md) guide for details on editing the configuration file.

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabric-add-new-channel.yaml:66:193"
```
Snippet from `network.channels` section below:

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:63:165"
```

**Run Playbook**

Execute the following command to run the `add-new-channel.yaml` playbook:

```
ansible-playbook platforms/hyperledger-fabric/configuration/add-new-channel.yaml --extra-vars "@path-to-network.yaml"
```
Replace `path-to-network.yaml` with the actual path to your updated `network.yaml` file.

This will add a channel to the existing Fabric network.

2. **Add a new channel by generating a new genesis or channeltx in an existing network**

**Update Configuration File**

- Edit the `network.yaml` file to include a new channel with the following details:
- `channel_status: new`
- Organization details (name, CA address, MSP ID, etc.)
- Orderer information
- Remove existing channels or use `channel_status: existing`
- Refer to the [networkyaml-fabric.md](../networkyaml-fabric.md) guide for details on editing the configuration file.

Snippet from `network.channels` section below:

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabric-add-new-channel.yaml:63:227"
```

!!! tip

For reference, see sample [network-fabric-add-channel.yaml](https://github.com/hyperledger/bevel/tree/main/platforms/hyperledger-fabric/configuration/samples/network-fabric-add-new-channel.yaml) file.

1. **Run Playbook**
**Run Playbook**

Execute the following command to run the `add-new-channel.yaml` playbook:
Execute the following command to run the `add-new-channel.yaml` playbook:

```
ansible-playbook platforms/hyperledger-fabric/configuration/add-new-channel.yaml --extra-vars "@path-to-network.yaml"
```
Replace `path-to-network.yaml` with the actual path to your updated `network.yaml` file.
```
ansible-playbook platforms/hyperledger-fabric/configuration/add-new-channel.yaml --extra-vars "@path-to-network.yaml" -e genererate_configtx=true
```
Replace `path-to-network.yaml` with the actual path to your updated `network.yaml` file.

This will add a new channel to the existing Fabric network.
This will add a new channel to the existing Fabric network.

## Method 2: Using `helm install`

Expand Down
25 changes: 16 additions & 9 deletions docs/source/guides/networkyaml-fabric.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ channels
The snapshot of channels section with its fields and sample values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:63:158"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:63:165"
```

The fields under the `channel` are
Expand Down Expand Up @@ -188,7 +188,7 @@ In the sample configuration example, we have five organization under the `organi
The snapshot of an organization field with sample values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:160:176"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:167:185"
```

Each `organization` under the `organizations` section has the following fields.
Expand All @@ -214,7 +214,7 @@ Each `organization` under the `organizations` section has the following fields.
For the aws and k8s field the snapshot with sample values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:178:188"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:186:202"
```

The `aws` field under each organization contains: (This will be ignored if cloud_provider is not 'aws')
Expand All @@ -232,10 +232,17 @@ The `k8s` field under each organization contains
| context | Context/Name of the cluster where the organization entities should be deployed |
| config_file | Path to the kubernetes cluster configuration file |

The `vault` field under each organization contains

| Field | Description |
|-------------|----------------------------------------------------------|
| url | The URL for Hashicorp Vault server with port (Do not use 127.0.0.1 or localhost) |
| root_token | The root token for accessing the Vault server |

For gitops fields the snapshot from the sample configuration file with the example values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:190:208"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:203:215"
```

The gitops field under each organization contains
Expand All @@ -256,7 +263,7 @@ The gitops field under each organization contains
For Hyperledger Fabric, you can also generate different user certificates and pass the names and attributes in the specific section for `users`. This is only applicable if using Fabric CA. An example is below:

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:331:337"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:338:344"
```

The fields under `user` are
Expand All @@ -272,7 +279,7 @@ The services field for each organization under `organizations` section of Fabric
Each organization will have a CA service under the service field. The snapshot of CA service with example values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:212:218"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:217:225"
```

The fields under `ca` service are
Expand All @@ -288,7 +295,7 @@ The fields under `ca` service are
Example of peer service. Below is a snapshot of the peer service with example values.

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:347:380"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:354:387"
```

The fields under `peer` service are
Expand Down Expand Up @@ -335,7 +342,7 @@ The chaincodes section contains the list of chaincode for the peer, the fields u
The organization with orderer type will have concensus service. The snapshot of consensus service with example values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:220:221"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:227:228"
```

The fields under `consensus` service are
Expand All @@ -350,7 +357,7 @@ The fields under `consensus` service are
Example of ordering service. The snapshot of orderers service with example values is below

```yaml
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:222:246"
--8<-- "platforms/hyperledger-fabric/configuration/samples/network-fabricv2.yaml:229:253"
```

The fields under `orderer` service are
Expand Down
2 changes: 1 addition & 1 deletion platforms/hyperledger-fabric/charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ helm upgrade --install orderer3 ./fabric-orderernode --namespace supplychain-net
cp /home/bevel/build/peer0-core.yaml ./fabric-peernode/conf/default_core.yaml
# Install the peers
helm upgrade --install peer0 ./fabric-peernode --namespace supplychain-net --values ./values/proxy-and-vault/peer.yaml
helm upgrade --install peer1 ./fabric-peernode --namespace supplychain-net --values ./values/proxy-and-vault/peer.yaml --set peer.gossipPeerAddress=peer0.supplychain-net.test.yourdomain.com:443 --set peer.cliEnabled=true
helm upgrade --install peer1 ./fabric-peernode --namespace supplychain-net --values ./values/proxy-and-vault/peer.yaml --set peer.gossipPeerAddress=peer0.supplychain-net.hlf.blockchaincloudpoc-develop.com:443 --set peer.cliEnabled=true
```

#### Setup Peers in another organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ metadata:
name: createchannel-{{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: createchannel-{{ .Release.Name }}
app.kubernetes.io/component: fabric-channel-create-job
app.kubernetes.io/part-of: {{ include "fabric-channel-create.fullname" . }}
Expand All @@ -21,6 +22,7 @@ spec:
template:
metadata:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: createchannel-{{ .Release.Name }}
app.kubernetes.io/component: fabric-channel-create-job
app.kubernetes.io/part-of: {{ include "fabric-channel-create.fullname" . }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ metadata:
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": "before-hook-creation"
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: channel-join-{{ .Release.Name }}
app.kubernetes.io/component: fabric-channel-join-job
app.kubernetes.io/part-of: {{ include "fabric-channel-join.fullname" . }}
Expand All @@ -25,6 +26,7 @@ spec:
template:
metadata:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: channel-join-{{ .Release.Name }}
app.kubernetes.io/component: fabric-channel-join-job
app.kubernetes.io/part-of: {{ include "fabric-channel-join.fullname" . }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ metadata:
name: channel-create-{{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: osn-createchannel-{{ .Release.Name }}
app.kubernetes.io/component: fabric-osnadmin-channel-create-job
app.kubernetes.io/part-of: {{ include "fabric-osnadmin-channel-create.fullname" . }}
Expand All @@ -21,6 +22,7 @@ spec:
template:
metadata:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: osn-createchannel-{{ .Release.Name }}
app.kubernetes.io/component: fabric-osnadmin-channel-create-job
app.kubernetes.io/part-of: {{ include "fabric-osnadmin-channel-create.fullname" . }}
Expand Down
61 changes: 11 additions & 50 deletions platforms/hyperledger-fabric/configuration/add-new-channel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,16 @@
file:
path: "./build"
state: absent

# Create generate_crypto script for each organization
- include_role:
name: "create/crypto_script"
vars:
component_type: "{{ item.type | lower}}"
orderers: "{{ item.services.orderers }}"
loop: "{{ network['organizations'] }}"

# Creating channel artifacts
# This role creates configtx.yaml file as the requirements mentioned in network.yaml
# which is then consumed by configtxgen tool
- include_role:
name: "create/configtx"
vars:
config_file: "./build/configtx.yaml"

# This role generate channeltx
- include_role:
name: "create/channel_artifacts"
vars:
build_path: "./build"
genesis: "{{ item.genesis }}"
channel_name: "{{ item.channel_name | lower}}"
profile_name: "{{ item.channel_name }}"
add_new_org: 'false'
fetch_certs: "true"
loop: "{{ network['channels'] }}"
when: item.channel_status == 'new'


- name: "Create genesis block"
include_role:
name: "create/genesis"
vars:
build_path: "./build"
genesis: "{{ item.genesis }}"
channel_name: "{{ item.channel_name | lower }}"
loop: "{{ network['channels'] }}"
when: item.channel_status == 'new' and '2.5.' in network.version
org: "{{ network['organizations'] | first }}"
docker_url: "{{ network.docker.url }}"
kubernetes: "{{ org.k8s }}"
generateGenisis: false
when: genererate_configtx is defined and genererate_configtx == 'true'

# This role creates the value file for creating channel from creator organization
# to the vault.
Expand All @@ -72,6 +43,7 @@
build_path: "./build"
participants: "{{ item.participants }}"
docker_url: "{{ network.docker.url }}"
channel_name: "{{ item.channel_name | lower }}"
loop: "{{ network['channels'] }}"
when: item.channel_status == 'new' and ('2.2.' in network.version or '1.4.' in network.version)

Expand All @@ -97,20 +69,9 @@
loop: "{{ network['channels'] }}"
when: item.channel_status == 'new'

# This role creates the value file for anchor peer update over channel for
# each organization which is the part of the channel.
- include_role:
name: "create/anchorpeer"
vars:
build_path: "./build"
participants: "{{ item.participants }}"
docker_url: "{{ network.docker.url }}"
loop: "{{ network['channels'] }}"
when: item.channel_status == 'new'

vars: #These variables can be overriden from the command line
privilege_escalate: false #Default to NOT escalate to root privledges
install_os: "linux" #Default to linux OS
install_arch: "amd64" #Default to amd64 architecture
bin_install_dir: "~/bin" #Default to /bin install directory for binaries
privilege_escalate: false # Default to NOT escalate to root privledges
install_os: "linux" # Default to linux OS
install_arch: "amd64" # Default to amd64 architecture
bin_install_dir: "~/bin" # Default to /bin install directory for binaries
add_new_org: 'false' # Default to false as this is for main network creation
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@
include_role:
name: "create/genesis"
vars:
org: "{{ network['organizations'] | first }}"
docker_url: "{{ network.docker.url }}"
loop: "{{ network['organizations'] }}"
loop_control:
loop_var: org
kubernetes: "{{ org.k8s }}"
generateGenisis: true

vars: #These variables can be overriden from the command line
privilege_escalate: false #Default to NOT escalate to root privledges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
git_url: "{{ gitops.git_url }}"
git_branch: "{{ gitops.branch }}"
charts_dir: "{{ gitops.chart_source }}"
subject: "{{ ca.subject }}"
subject: "{{ ca.subject | quote }}"
external_url_suffix: "{{ org.external_url_suffix }}"
kubernetes_url: "{{ kubernetes_server_url.stdout }}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# SPDX-License-Identifier: Apache-2.0
##############################################################################################

# Set Variable charts_dir
- name: "Set Variable charts_dir"
set_fact:
charts_dir: "{{ org.gitops.chart_source }}"

# Waiting for the creation of peer pod
- name: "Waiting for peer pod {{ peer_name }} in {{ org.name | lower }}-net"
include_role:
Expand Down
Loading

0 comments on commit 6f02471

Please sign in to comment.