Skip to content

Commit

Permalink
Upgrade yq from v3.x to v4.x (#721)
Browse files Browse the repository at this point in the history
Upgrade yq from v3.x to v4.x

Signed-off-by: Deepjyoti-Sarmah <[email protected]>
Signed-off-by: Marcus Brandenburger <[email protected]>
Co-authored-by: Marcus Brandenburger <[email protected]>
  • Loading branch information
Deepjyoti-Sarmah and mbrandenburger authored Oct 24, 2023
1 parent aa932b7 commit 78c6117
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Make sure that you have the following required dependencies installed:
* yq v3.x (newer versions, v4.x and higher, are currently *not* supported!)
You can install `yq` v3 via `go get`.
```bash
GO111MODULE=on go get github.com/mikefarah/yq/v3
GO111MODULE=on go get github.com/mikefarah/yq/v4
```

* Protocol Buffers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ if [[ ! -f "$GATEWAY_CONFIG" ]]; then
exit 1
fi

MSP_ID=$(yq r $GATEWAY_CONFIG organizations.${ORG^}.mspid)
PEER_ID=$(yq r $GATEWAY_CONFIG organizations.${ORG^}.peers[0])
ADDR=$(yq r $GATEWAY_CONFIG peers.\"${PEER_ID}\".url | sed 's/grpcs:\/\///')
MSP_ID=$(yq ".organizations.${ORG^}.mspid" "$GATEWAY_CONFIG")
PEER_ID=$(yq ".organizations.${ORG^}.peers[0]" "$GATEWAY_CONFIG")
ADDR=$(yq ".peers.\"${PEER_ID}\".url" "$GATEWAY_CONFIG" | sed 's/grpcs:\/\///')

echo "export CONF_PATH=$FPC_PATH/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto" > ${ORG}.env
echo "export GATEWAY_CONFIG=\$CONF_PATH/peerOrganizations/${ORG,,}.example.com/connections.yaml" >> ${ORG}.env
Expand Down
6 changes: 3 additions & 3 deletions samples/deployment/test-network/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fi
echo "Adding FPC external builder to core.yaml"
# Create a backup copy of `core.yaml` first and always work from there.
backup ${CORE_PATH}
yq m -i -a=append ${CORE_PATH} core_ext.yaml
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i ${CORE_PATH} core_ext.yaml


###############################################
Expand Down Expand Up @@ -80,8 +80,8 @@ sed -i "s+\.\./+${FABRIC_SAMPLES_HOST}/test-network/+g" "${DOCKER_COMPOSE_CA}"
echo "${DOCKER_COMPOSE_TEST_NET}"
peers=("peer0.org1.example.com" "peer0.org2.example.com")
for p in "${peers[@]}"; do
yq w -i ${DOCKER_COMPOSE_TEST_NET} "services.\"$p\".volumes[+]" "${FPC_PATH_HOST}:/opt/gopath/src/github.com/hyperledger/fabric-private-chaincode"
yq w -i ${DOCKER_COMPOSE_TEST_NET} "services.\"$p\".volumes[+]" "${FABRIC_SAMPLES_HOST}/config/core.yaml:/etc/hyperledger/fabric/core.yaml"
yq ".services.\"$p\".volumes += [\"${FPC_PATH_HOST}:/opt/gopath/src/github.com/hyperledger/fabric-private-chaincode\"]" -i "${DOCKER_COMPOSE_TEST_NET}"
yq ".services.\"$p\".volumes += [\"${FABRIC_SAMPLES_HOST}/config/core.yaml:/etc/hyperledger/fabric/core.yaml\"]" -i "${DOCKER_COMPOSE_TEST_NET}"
done

###############################################
Expand Down
21 changes: 11 additions & 10 deletions samples/deployment/test-network/update-connection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ for org in "${orgs[@]}"; do
KEYS=("${ORG_PATH}/users/${user}@${org}.example.com/msp/keystore"/*)

# add cryptopath and admin cert / key
yq w -i ${CONNECTIONS_PATH} organizations.${org^}.cryptoPath ${ORG_PATH}/msp
yq w -i ${CONNECTIONS_PATH} organizations.${org^}.users.${user}.cert.path "${CERTS[0]}"
yq w -i ${CONNECTIONS_PATH} organizations.${org^}.users.${user}.key.path "${KEYS[0]}"
yq ".organizations.${org^}.cryptoPath = \"${ORG_PATH}/msp\"" -i "${CONNECTIONS_PATH}"
yq ".organizations.${org^}.users.${user}.cert.path = \"${CERTS[0]}\"" -i "${CONNECTIONS_PATH}"
yq ".organizations.${org^}.users.${user}.key.path = \"${KEYS[0]}\"" -i "${CONNECTIONS_PATH}"

# add channels and entity matcher
yq m -i ${CONNECTIONS_PATH} - <<EOF
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i ${CONNECTIONS_PATH} <<EOF
channels:
_default:
peers:
Expand All @@ -75,19 +76,19 @@ entityMatchers:
EOF

# fetch all peers from connections
yq r --printMode pv "${CONNECTIONS_PATH}" peers >> "${tmp_dir}/peers-${org}.yaml"
yq ".peers" "${CONNECTIONS_PATH}" >> "${tmp_dir}/peers-${org}.yaml"
done

# consolidate all collected peers in a single peers.yaml
yq m "${tmp_dir}"/peers-*.yaml >> "${tmp_dir}/peers.yaml"
yq v "${tmp_dir}/peers.yaml"
yq eval-all '. as $item ireduce ({}; . * $item )' ${tmp_dir}/peers-*.yaml >> "${tmp_dir}/peers.yaml"
yq 'true' "${tmp_dir}/peers.yaml" > /dev/null

# merge peers.yaml into all connection files
for org in "${orgs[@]}"; do
ORG_PATH="${FPC_PATH}/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/${org}.example.com"
CONNECTIONS_PATH="${ORG_PATH}/connection-${org}.yaml"
yq m -i "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml"
yq v "${CONNECTIONS_PATH}"
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml"
yq 'true' "${CONNECTIONS_PATH}" > /dev/null
done

echo "Updated!"
echo "Updated!"
2 changes: 1 addition & 1 deletion utils/docker/base-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ RUN go install golang.org/x/tools/cmd/goimports@latest \
&& go install github.com/maxbrunsfeld/counterfeiter/v6@latest \
&& go install honnef.co/go/tools/cmd/[email protected] \
&& go install github.com/client9/misspell/cmd/misspell@latest \
&& go install github.com/mikefarah/yq/v3@latest
&& go install github.com/mikefarah/yq/v4@latest

# Install SGX SSL
ENV SGX_SSL /opt/intel/sgxssl
Expand Down
2 changes: 1 addition & 1 deletion utils/docker/dev_peer_cc-builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@ RUN apt-get install -y -q \
${APT_ADD_PKGS}

RUN GO111MODULE=on \
go get github.com/mikefarah/yq/v3
go get github.com/mikefarah/yq/v4

WORKDIR ${FPC_PATH}

0 comments on commit 78c6117

Please sign in to comment.